webpack 热中间件拆分块
webpack hot middleware split chunk
我正在尝试使用 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);
将 publicPath 设置为热中间件客户端就可以了
output: {
path: PATHS.public,
filename: '[name].js',
chunkFilename: '[chunkhash].js',
publicPath: http://127.0.0.1:8009
}
我正在尝试使用 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);
将 publicPath 设置为热中间件客户端就可以了
output: {
path: PATHS.public,
filename: '[name].js',
chunkFilename: '[chunkhash].js',
publicPath: http://127.0.0.1:8009
}