我在Java(Spring启动)项目中使用reactJs和webpack。 我已经配置了webpack服务器来从本地文件夹提供bundle.js文件,所以我可以在我的tomcat服务器中使用它。 我使用了" WriteFilePlugin"将文件写入高清,但的问题是:当我运行" npm start"该文件只生成一次,并且在每次编辑Js文件后都没有更新。请告诉我如何解决此问题?
关注我的webpack dev服务器配置:
import webpack from 'webpack';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import autoprefixer from 'autoprefixer';
import WriteFilePlugin from 'write-file-webpack-plugin';
import DashboardPlugin from 'webpack-dashboard/plugin';
export default {
debug: true,
devtool: 'cheap-module-eval-source-map',
noInfo: true,
entry: [
'./src/webpack-public-path',
'webpack-hot-middleware/client?http://localhost:8080/',
'./src/index'
],
target: 'web',
output: {
path: `${__dirname}../../../../target/classes/public`,
publicPath: '/',
filename: 'bundle.js'
},
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('development'),
__DEV__: true
}),
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin(),
new DashboardPlugin({ port: 3333 }),
new HtmlWebpackPlugin({
template: 'src/index.ejs',
minify: {
removeComments: true,
collapseWhitespace: true
},
inject: true
}),
new webpack.ProvidePlugin({
"React": "react",
})
, new WriteFilePlugin({force:true})
],
module: {
loaders: [
{test: /\.js$/, exclude: /node_modules/, loaders: ['babel']},
{test: /\.eot(\?v=\d+.\d+.\d+)?$/, loader: 'file'},
{test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: "url?limit=10000&mimetype=application/font-woff"},
{test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/, loader: 'url?limit=10000&mimetype=application/octet-stream'},
{test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, loader: 'url?limit=10000&mimetype=image/svg+xml'},
{test: /\.(jpe?g|png|gif)$/i, loader: 'file?name=[name].[ext]'},
{test: /\.ico$/, loader: 'file?name=[name].[ext]'},
{test: /(\.css|\.scss)$/, loaders: ['style', 'css?sourceMap', 'postcss', 'sass?sourceMap']}
]
},
postcss: () => [autoprefixer]
};