Webpack TerserPlugin Excludes
Asked Answered
J

0

8

One of my Node Modules in my React project uses vm.runincontext and this code isn't being able to run while minified. My current solution has been to turn minification off and it works it just makes loading take a long time :(. I was thinking to try to not minify just this specific node module using excludes but no matter what I pass in there it doesn't seem like it's working. This solution looks like it could work and if I pass a regex that always matched true my production build works but I don't know if I'm expected to now make a regex expression which evaluates every file

This is quite confusing since I can put exclude:/(.*)/ and the program works but if I try to put anything related to the file such as exclude:/node_modules/ or /kekule/ (the name of the module) then this doesn't work. Even weirder than that I can pass the inverse andexclude:/^((?!node_modules).)*$/ or even exclude:/^((?!kekule).)*$/, and they both work

      optimization: {
        minimizer: [
          new TerserPlugin({
            exclude: /node_modules/,
          }),
        ],
      },
    }; 

Also tried using this it's also not quite working

optimization: {
      minimize:isEnvProduction,
      minimizer: [
        // This is only used in production mode
        new TerserPlugin({
          terserOptions: {
            module: {
              noParse: (content) => /kekule/.test(content)
            },
            parse: {...

And also tried placing the module:{noParse...} right under module.exports in the hierarchy but it didn't work either

Any tips? Thanks

Jordan answered 28/2, 2020 at 9:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.