Webpack not excluding node_modules

前端 未结 5 680
轮回少年
轮回少年 2020-11-30 22:02

I\'m using webpack for a Node framework that I\'m building (though I should probably use gulp, admittedly). When I include the EJS module, webpack includes it in the compile

相关标签:
5条回答
  • 2020-11-30 22:39

    From your config file, it seems like you're only excluding node_modules from being parsed with babel-loader, but not from being bundled.

    In order to exclude node_modules and native node libraries from bundling, you need to:

    1. Add target: 'node' to your webpack.config.js. This will exclude native node modules (path, fs, etc.) from being bundled.
    2. Use webpack-node-externals in order to exclude other node_modules.

    So your result config file should look like:

    var nodeExternals = require('webpack-node-externals');
    ...
    module.exports = {
        ...
        target: 'node', // in order to ignore built-in modules like path, fs, etc. 
        externals: [nodeExternals()], // in order to ignore all modules in node_modules folder 
        ...
    };
    
    0 讨论(0)
  • 2020-11-30 22:40

    This worked for me:

    exclude: [/bower_components/, /node_modules/]

    module.loaders

    A array of automatically applied loaders.

    Each item can have these properties:

    test: A condition that must be met

    exclude: A condition that must not be met

    include: A condition that must be met

    loader: A string of "!" separated loaders

    loaders: A array of loaders as string

    A condition can be a RegExp, an absolute path start, or an array of one of these combined with "and".

    See http://webpack.github.io/docs/configuration.html#module-loaders

    0 讨论(0)
  • 2020-11-30 22:41

    If you ran into this issue when using TypeScript, you may need to add skipLibCheck: true in your tsconfig.json file.

    0 讨论(0)
  • 2020-11-30 22:41

    Try use absolute path:

    exclude:path.resolve(__dirname, "node_modules")
    
    0 讨论(0)
  • 2020-11-30 22:47

    try this below solution:

    exclude:path.resolve(__dirname, "node_modules")
    
    0 讨论(0)
提交回复
热议问题