What does “The code generator has deoptimised the styling of [some file] as it exceeds the max of ”100KB“” mean?

前端 未结 9 1437
失恋的感觉
失恋的感觉 2020-11-30 19:18

I added a new npm package to my project and require it in one of my modules.

Now I get this message from webpack,

build modulesNote: The code generator

9条回答
  •  一整个雨季
    2020-11-30 19:26

    Either one of the below three options gets rid of the message (but for different reasons and with different side-effects I suppose):

    1. exclude the node_modules directory or explicitly include the directory where your app resides (which presumably does not contain files in excess of 100KB)
    2. set the Babel option compact to true (actually any value other than "auto")
    3. set the Babel option compact to false (see above)

    #1 in the above list can be achieved by either excluding the node_modules directory or be explicitly including the directory where your app resides.

    E.g. in webpack.config.js:

    let path = require('path');
    ....
    module: {
         loaders: [
              ...
              loader: 'babel',
              exclude: path.resolve(__dirname, 'node_modules/')
    

    ... or by using include: path.resolve(__dirname, 'app/') (again in webpack.config.js).

    #2 and #3 in the above list can be accomplished by the method suggested in this answer or (my preference) by editing the .babelrc file. E.g.:

    $ cat .babelrc 
    {
        "presets": ["es2015", "react"],
        "compact" : true
    }
    

    Tested with the following setup:

    $ npm ls --depth 0 | grep babel
    ├── babel-core@6.7.4
    ├── babel-loader@6.2.4
    ├── babel-preset-es2015@6.6.0
    ├── babel-preset-react@6.5.0
    

提交回复
热议问题