Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make option for exclude in js config #83

Open
nemchik opened this issue Jan 11, 2021 · 1 comment
Open

Make option for exclude in js config #83

nemchik opened this issue Jan 11, 2021 · 1 comment
Labels
enhancement New feature or request js-config js-config-webpack-plugin

Comments

@nemchik
Copy link
Contributor

nemchik commented Jan 11, 2021

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[x] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

https://github.com/namics/webpack-config-plugins/blob/6bf7421bf492dba2d1b62e1889c3970c2f48b4bf/packages/js-config-webpack-plugin/config/production.config.js#L13 and https://github.com/namics/webpack-config-plugins/blob/6bf7421bf492dba2d1b62e1889c3970c2f48b4bf/packages/js-config-webpack-plugin/config/development.config.js#L12 cause the node_modules folder NOT to be processed by the babel loader, and thus code from node packages is not transpiled per my babel configuration.

Expected behavior

It would be great if this could be setup as an option, along the lines of options.jsConfigExclude with a default value of [/[/\\\\]node_modules[/\\\\]/] that could be passed in as

new CommonConfigWebpackPlugin({ jsConfigExclude: "" }),

or

new JsConfigWebpackPlugin({ jsConfigExclude: "" }),

for those of us who want to intentionally include the node_modules folder to be transpiled by babel.

Minimal reproduction of the problem with instructions

What is the motivation / use case for changing the behavior?

Using https://www.npmjs.com/package/signature_pad in some of my projects with the common config ends up with class in my bundles, and IE 11 does not know what to do with this, which causes all kinds of problems (the rest of the code in the bundle stops functioning). When including my own override for this by doing:

  module: {
    rules: [
      {
        test: /\.(js|jsx|mjs)$/,
        //exclude: [/[/\\\\]node_modules[/\\\\]/], // exclude node_modules folder per default
        use: [
          // run process in multiple threads
          require.resolve("thread-loader"),
          {
            loader: require.resolve("babel-loader"),
            options: {
              extends: "./.babelrc.json",
              // cache builds, future builds attempt to read from cache to avoid needing to run expensive babel processings
              cacheDirectory: true,
              // do not include superfluous whitespace characters and line terminators
              // https://babeljs.io/docs/en/babel-core/#options
              compact: true,
            },
          },
        ],
      },
    ],
  },

everything is transpiled through babel and works as expected. On my system (which is 6+ years old, dell optiplex 3010, core i3) I did not notice any significant difference in runtime for building bundles. Others may have different experience with that (noting that excluding node_modules is recommended to decrease runtime), which is why I'm hoping this can be an option and the default can maintain the current value so it would not be a breaking change.

Environment


Plugin version: 2.0.1

 
- Node version: v15.5.0 
- Platform:  Windows

Others:

@ernscht ernscht added the enhancement New feature or request label Feb 27, 2021
@ernscht ernscht added the js-config js-config-webpack-plugin label Apr 21, 2021
@nemchik
Copy link
Contributor Author

nemchik commented Jun 10, 2021

On further investigation it actually looks like excluding node_modules is really not meant to be done when target is set to web (default). If target is set to something else (like node) then it may be desirable to exclude node_modules. Excluding node_modules seems like it would be better accomplished with webpack-node-externals and maybe not included in this project since the end user could add this themselves as needed. Further reference liady/webpack-node-externals#17 (comment)

However - when running in a web environment - all the dependencies must be bundled as well (there are no sync require calls in the browser) - so using this library will actually not make sense.

I would propose that since target is not set by default anywhere in this plugin (it would default to web) that node_modules should not be excluded at all, and users who set a target to an environment that should exclude node_modules should be handling the exclusion on their own, either by defining exclude or by using a plugin like webpack-node-externals

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request js-config js-config-webpack-plugin
Development

No branches or pull requests

2 participants