简体   繁体   English

我将依赖项与wepback捆绑在一起进行生产

[英]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.

相关问题 如何将Bower程序包依存关系排除在汇总包之外? - How do I keep bower package dependencies out of my rollup bundle? 如何在本地捆绑 JavaScript 和 CSS 依赖项以供离线使用? - How do I bundle JavaScript and CSS dependencies locally for offline use? 如何获得我的捆绑包? - How do I get access to my bundle? 在生产模式下将源与 webpack 捆绑在一起时,如何避免丢失类名? - How can I avoid losing my class name when I bundle source with webpack in production mode? 如果我只发布库的包,我应该将我的库依赖项放入 devDependencies 中吗? - Should i put my library dependencies into devDependencies if I only publish the bundle of the library? 如何才能异步要求依赖项,但将其保留在捆绑包之外? - How can I require dependencies asynchronously but keeping them outside my bundle? 如何修复群集束图中的缩放和平移? - How do I fix zooming and panning in my cluster bundle graph? 如何将特定的Webkit构建与我的Cocoa App捆绑在一起 - How do I bundle a specific webkit build with my Cocoa App 如何从我的Browserified包中排除“require('react')”? - How do I exclude the “require('react')” from my Browserified bundle? 如何修复Webpack避免在生产环境中破坏代码? - How do I fix Webpack from mangling my code in production?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM