【发布时间】:2015-08-10 06:00:29
【问题描述】:
我根据this article写了一个reactjs app,但是里面提到了webpack's externals的配置项,这些第三方lib不应该打包在我们的bundle.js中。
您在文章中看到的reactjs 包含在index.html。
我可以在开发环境中做到这一点,但是如何在生产环境中将其编译为单独的文件?(可能还有其他依赖项)
【问题讨论】:
我根据this article写了一个reactjs app,但是里面提到了webpack's externals的配置项,这些第三方lib不应该打包在我们的bundle.js中。
您在文章中看到的reactjs 包含在index.html。
我可以在开发环境中做到这一点,但是如何在生产环境中将其编译为单独的文件?(可能还有其他依赖项)
【问题讨论】:
这是一个 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的类似例子
【讨论】: