使用react-hot时拆分供应商和应用程序

时间:2015-10-28 00:56:35

标签: reactjs webpack

我正在使用带有webpack的react-hot插件,并且在我遵循指示后它可以工作:

module.exports = {
    entry: [
        'webpack-dev-server/client?http://localhost:8090',
        'webpack/hot/only-dev-server',
        './src/index'
    ],
    output: {
        path: path.join(__dirname, 'dist'),
        filename: 'bundle.js',
        publicPath: '/static/'
    },
    plugins: [
        new webpack.HotModuleReplacementPlugin()
    ],
    module: {
        loaders: [{
            test: /\.js$/,
            loaders: ['react-hot', 'babel'],
            include: path.join(__dirname, 'src')
        }]
    }
};

生成的/static/bundle.js包含所有库。

虽然我想从我的应用程序中拆分供应商,但我尝试添加多个入口点:

module.exports = {
    entry: {
        app: ['./src/index'],
        vendor: [
            'webpack-dev-server/client?http://localhost:8090',
            'webpack/hot/only-dev-server'
        ]
    },
    output: {
        path: path.join(__dirname, 'dist'),
        filename: '[name].bundle.js',
        publicPath: '/static/'
    },
    plugins: [
        new webpack.HotModuleReplacementPlugin()
    ],
    module: {
        loaders: [{
            test: /\.js$/,
            loaders: ['react-hot', 'babel'],
            include: path.join(__dirname, 'src')
        }]
    }
};

然而/static/app.bundle.js仍然包含jquery,react...

这可能吗?

更新这是配置,在@zerkms提到供应商必须明确声明后,可以按预期工作:

module.exports = {
    entry: {
        app: ['./src/index'],
        vendor: [
            'webpack-dev-server/client?http://localhost:8090',
            'webpack/hot/only-dev-server', 'react', 'jquery'
        ]
    },
    output: {
        path: path.join(__dirname, 'dist'),
        filename: 'app.bundle.js',
        publicPath: '/static/'
    },
    plugins: [
        new webpack.HotModuleReplacementPlugin(),
        new webpack.optimize.CommonsChunkPlugin('vendor', 'vendor.bundle.js')
    ],
    module: {
        loaders: [{
            test: /\.js$/,
            loaders: ['react-hot', 'babel'],
            include: path.join(__dirname, 'src')
        }]
    }
};

0 个答案:

没有答案