How to simultaneously create both 'web' and 'node' versions of a bundle with Webpack?

我只是一个虾纸丫 提交于 2019-12-24 00:37:28

问题


Is there a way to create both 'web' and 'node' versions of a bundle with one go by using Webpack or Browserify? The 'web' version of the bundle will be used on a client, and 'node' version of the same bundle will be used on the server for pre-rendering ("isomorphic" web application).


回答1:


I think the easiest way is probably just to create two configs, one with target: "node" and the other target: "web" in the configuration, and run them both like $ webpack && webpack --config webpack.config.web.js




回答2:


You can create multiple config objects in webpack.config.js file:

const config1 = {
  target: 'web',
  ...
}
const config2 = {
  target: 'node',
  ...
}

export default [config1, config2]


来源:https://stackoverflow.com/questions/26063480/how-to-simultaneously-create-both-web-and-node-versions-of-a-bundle-with-web

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