How can I exclude code path when bundling with webpack/browserify?

后端 未结 4 779
再見小時候
再見小時候 2021-02-12 09:27

I have a library that can be used with both node.js and the browser. I am using CommonJS then publishing for the web version using webpack. My code looks like this:



        
4条回答
  •  天命终不由人
    2021-02-12 10:24

    You may use IgnorePlugin for Webpack. If you are using a webpack.config.js file, use it like this:

    var webpack = require('webpack')
    
    var ignore = new webpack.IgnorePlugin(/^(canvas|mongoose|react)$/)
    
    module.exports = {
      //other options goes here
      plugins: [ignore]
    }
    

    To push it further, you may use some flags like process.env.NODE_ENV to control the regex filter of IgnorePlugin

提交回复
热议问题