[英]do I bundle my dependencies with wepback for production
I am using webpack to create my production bundle for running an express application. 我正在使用webpack创建用于运行快速应用程序的生产包。 I thought the webpack externals field would bundle up the dependencies I required to deploy without having to do a yarn install or an npm install.
我认为webpack externals字段将捆绑我需要部署的依赖项,而不必执行yarn安装或npm安装。
My server webpack config looks like this: 我的服务器webpack配置看起来像这样:
const config = merge(common, {
name: 'server',
target: 'node',
externals: readdirSync(path.join(__dirname, '../../node_modules'))
.filter(x => !/\.bin|react-universal-component|require-universal-module|webpack-flush-chunks/.test(x))
.reduce((externals, mod) => {
externals[mod] = `commonjs ${mod}`;
return externals;
}, {});
I can see the following entry for express in the list of externals: 我可以在外部组件列表中看到以下用于express的条目:
express: 'commonjs express',
But when I try and execute the file with the script that requires the express dependency I get: 但是,当我尝试使用需要明确依赖性的脚本执行文件时,我得到了:
Cannot find module 'express'
找不到模块“表达”
I thought the whole point of externals was to specify what should be bundled. 我认为外部因素的全部目的是指定应捆绑的东西。
I thought the whole point of externals was to specify what should be bundled.
我认为外部因素的全部目的是指定应捆绑的东西。
Is the opposite, from the webpack documentation : 相反,来自webpack文档 :
The externals configuration option provides a way of excluding dependencies from the output bundles.
外部配置选项提供了一种从输出包中排除依赖项的方法。 Instead, the created bundle relies on that dependency to be present in the consumer's environment.
而是,创建的捆绑包依赖于出现在消费者环境中的依赖关系。
So you don't want express
in your externals, because it will actually be excluded from the bundle. 因此,您不希望在外部
express
您的想法,因为它实际上会从捆绑包中排除。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.