Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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).

like image 432
Grief Coder Avatar asked Nov 16 '25 05:11

Grief Coder


2 Answers

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

like image 136
trekforever Avatar answered Nov 17 '25 20:11

trekforever


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

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

export default [config1, config2]
like image 25
Tyler Liu Avatar answered Nov 17 '25 19:11

Tyler Liu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!