Webpack热中间件拆分块



我正在尝试利用webpack代码分裂。一切看起来都很好,webpack拆分代码正确,依赖项,几乎和预期的一样。

除了我不能让它工作与热模块更换。

我成功加载127.0.0.1:8009/main.js

但是main.js正在加载127.0.0.1:8001/资产/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']
        }
    },
};

Simple Hot Server

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设置为hot-middleware client,是吗

output: {
  path: PATHS.public,
  filename: '[name].js',
  chunkFilename: '[chunkhash].js',
  publicPath: http://127.0.0.1:8009
}

相关内容

  • 没有找到相关文章

最新更新