【问题标题】:How to compile webpack externals js lib to another file如何将webpack externals js lib编译到另一个文件
【发布时间】:2015-08-10 06:00:29
【问题描述】:

我根据this article写了一个reactjs app,但是里面提到了webpack's externals的配置项,这些第三方lib不应该打包在我们的bundle.js中。

您在文章中看到的reactjs 包含在index.html

我可以在开发环境中做到这一点,但是如何在生产环境中将其编译为单独的文件?(可能还有其他依赖项)

【问题讨论】:

    标签: reactjs webpack


    【解决方案1】:

    这是一个 sn-p,在你的 webpack.config.js 中:

    var webpack = require('webpack')
    
    module.exports = {
        entry: {
            app: 'index.js',
            vendors: ['react', 'flux']  //assuming you use react and flux, add as many npm packages here as you want
        },
    
        plugins: [
            new webpack.optimize.CommonsChunkPlugin('vendors', './js/vendors.js') //this line means put everything defined in vendors to a file named vendors.js
        ]
    };
    

    你可以找到这个at the bottom of the offical doc page的类似例子

    【讨论】:

      猜你喜欢
      • 2019-05-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-19
      • 2020-08-06
      • 2022-09-27
      • 2019-10-15
      • 2017-06-10
      相关资源
      最近更新 更多