How to whitelist all subdependencies with webpack-node-externals

半世苍凉 提交于 2020-01-14 12:32:34

问题


I'm using webpack to bundle server assets using the target property.

This results in a usable client bundle, and a usable server, which is working great. However it seems that even for the server code, webpack is bundling everything within node_modules. I am attempting to use webpack-node-externals to solve this problem, seen below:

module.exports = [
  {
    name: "server code, output to ./server",
    entry: "./servertest.js",
    output: {
      filename: "./server/index.js"
    },
    target: "node",
    externals: [
      nodeExternals({
        includeClientPackages: false
      })
    ]
  },
  {
    name: "client side, output to ./public",
    entry: "./app.js",
    output: {
      filename: "./dist/app.js"
    }
  }
]

This doesn't work however as its default behavior is to exclude all node_modules from bundling, thus rendering the server useless. There is a whitelist option, for which I have included express, the only dependency of my small test case. It doesn't fail on express, however it fails on a dependency of express, merge-descriptors. And of course if I add merge-descriptors to the whitelist, trying to start the server will fail on another dependency of express. I surely cannot add every dependency and sub-dependency (etc etc) to this whitelist array.

How can I ensure all dependencies of a given requirement are bundled by webpack during a target: 'node' build?

来源:https://stackoverflow.com/questions/45763620/how-to-whitelist-all-subdependencies-with-webpack-node-externals

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!