我正在尝试利用webpack代码拆分。一切看起来都运行良好,webpack将代码分割正确,依赖性,非常符合预期。
除非我无法使用热模块更换。
我成功加载了127.0.0.1:8009/main.js
但是main.js正在尝试加载 127.0.0.1:8001/assets/1.chunk.js
有意义吗?我一定错过了什么。
我在127.0.0.1:8001运行节点服务器,热点中间件客户端在127.0.0.1:8009
** main.js **
require.ensure([], function (require) {
var admin = require('./admin');
}, 'admin');
我的Webpack配置
const PATHS = {
root: __dirname,
client: path.join(__dirname, '../', 'browser', 'scripts'),
public: path.join(__dirname, '../', '../', 'public')
};
var webpackConfig = {
hotPort: process.env.PORT_HOT,
devtool: 'eval',
name: 'browser',
resolve: {
root: PATHS.root,
extensions: ['', '.js', '.jsx', '.styl'],
modulesDirectories: [
'node_modules',
PATHS.client,
],
},
entry: {
main: ['main', hotMiddlewareScript]
},
output: {
path: PATHS.public,
filename: '[name].js',
publicPath: '/assets/'
},
module: {
noParse: [
/lodash/
],
loaders: [
{
test: /\.js$|\.jsx$/,
exclude: /node_modules/,
loaders: ['babel']
}
},
};
简单热门服务器
const app = express();
const compiler = webpack(webpackConfig);
app.use(webpackDev(compiler, {
noInfo: true,
publicPath: webpackConfig.output.publicPath
}));
app.use(webpackHot(compiler));
app.listen(webpackConfig.hotPort);
答案 0 :(得分:1)
将publicPath设置为热中间件客户端
output: {
path: PATHS.public,
filename: '[name].js',
chunkFilename: '[chunkhash].js',
publicPath: http://127.0.0.1:8009
}