Conditional build based on environment using Webpack

前端 未结 9 672
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-30 21:40

I have some things for development - e.g mocks which I would like to not bloat my distributed build file with.

In RequireJS you can pass a config in a plugin file an

9条回答
  •  清歌不尽
    2020-11-30 22:13

    Not sure why the "webpack.DefinePlugin" answer is the top one everywhere for defining Environment based imports/requires.

    The problem with that approach is that you are still delivering all those modules to the client -> check with webpack-bundle-analyezer for instance. And not reducing your bundle.js's size at all :)

    So what really works well and much more logical is: NormalModuleReplacementPlugin

    So rather than do a on_client conditional require -> just not include not needed files to the bundle in the first place

    Hope that helps

提交回复
热议问题