我遇到了一个非常令人沮丧的问题,我的 webpack-hot-middleware 不是“热重载”。它正在构建项目,并在我对任何有问题的文件进行任何编辑时重新构建项目,但它似乎从未显示任何更改,并且总是在对它们进行编辑之前显示我的文件(几乎就像它正在缓存它们或某物)。
我也在使用 Express 服务器,对这一切都很陌生。实际上,我正在尝试使用从雇主那里交给我的文件来设置开发环境,并且很难弄清楚如何解决这个问题。
我的 package.json 运行这些脚本:
"scripts": {
"postinstall": "npm run prod",
"prod": "webpack --config ./webpack.prod.config.js",
"start": "node ./app_build.js"
}
在“npm install”之后,它似乎运行了这个文件“webpack.prod.config.js”:
const path = require('path');
const webpack = require('webpack');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
module.exports = {
devtool: 'source-map',
entry: './main.js',
output: {
path: path.join(__dirname,'prod'),
filename: 'bundle.js',
publicPath: '/'
},
plugins:[
new webpack.DefinePlugin({
'process.env':{
NODE_ENV: JSON.stringify('production'),
}
}),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.UglifyJsPlugin({
minimize: true,
compress:{
warnings:false
}
}),
new ExtractTextPlugin('bundle.css'),
new webpack.IgnorePlugin(/^(buffertools)$/) //Remove deeper dependancy for react-jsonschema-forms error
],
module: {
loaders: [
{ test: /\.js$/,
loader: 'babel',
exclude: /node_modules/,
query: {
presets: ['es2015', 'react'] }},
{ test: /\.css?$/,
loader: ExtractTextPlugin.extract('style', 'css')},
{ test: /\.less$/,
loader: 'style!css!less' },
{ test: /\.(png|jpg|gif)$/,
loader: 'url-loader?limit=100000' },
{
test: /\.woff(\?v=\d+\.\d+\.\d+)?$/,
loader: "url?limit=10000&mimetype=application/font-woff"
}, {
test: /\.woff2(\?v=\d+\.\d+\.\d+)?$/,
loader: "url?limit=10000&mimetype=application/font-woff"
}, {
test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/,
loader: "url?limit=10000&mimetype=application/octet-stream"
}, {
test: /\.eot(\?v=\d+\.\d+\.\d+)?$/,
loader: "file"
}, {
test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
loader: "url?limit=10000&mimetype=image/svg+xml"
}
]
}
};
“npm start”运行“app_build.js”,如下所示:
const Server = require('./server.js');
const port = (process.env.PORT || 3333);
const app = Server.app();
const stormpath = require('express-stormpath');
const path = require('path');
var helpers = require('express-stormpath/lib/helpers');
var uuid = require('node-uuid');
var requestProxy = require('express-request-proxy');
var btoa = require('btoa');
var session = require('express-session');
var request = require('request');
var bodyParser = require('body-parser');
var Mailgun = require('mailgun-js');
request = request.defaults({jar:true});
const CONSTANTS = require('./src/constants/Constants');
//console.log('version: '+ process.env.NODE_ENV);
if (process.env.NODE_ENV !== 'production') {
const webpack = require('webpack');
const webpackDevMiddleware = require('webpack-dev-middleware');
const webpackHotMiddleware = require('webpack-hot-middleware');
const config = require('./webpack.dev.config.js');
const compiler = webpack(config);
app.use(webpackHotMiddleware(compiler));
app.use(webpackDevMiddleware(compiler, {
noInfo: true,
publicPath: config.output.publicPath
}))
console.log(`Listening at http://localhost:${port}`);
}
这个文件还有更多内容,但我相信我的问题与我的 publicPath 或其他东西有关,我不完全确定。就像我说的,我从以前的开发人员那里得到了这个配置,我对这一切都是全新的。