Why is webpack creating output js in form of string and using eval function to deploy it?

后端 未结 1 832
暖寄归人
暖寄归人 2021-01-07 19:16

My webpack.config.js file is as follows:

var path = require(\'path\');
var webpack = require(\'webpack\');
var CommonsChunkPlugin = webpack.optimize.CommonsC         


        
相关标签:
1条回答
  • 2021-01-07 19:51

    Your config uses this configuration as default:

    config.devtool = 'eval-source-map';
    

    The fine manual states:

    eval-source-map - Each module is executed with eval and a SourceMap is added as DataUrl to the eval.

    If you don't want that, use another devtool option.

    As for decreasing code size, you probably want to either disable the creation of a source map entirely (just don't set the devtool option) or have Webpack write the source map to a separate file (devtool : 'source-map' or devtool : 'cheap-source-map', AFAIK).

    Also set the NODE_ENV environment variable to production if you want less code:

    # if you're on a Unix-like OS:
    env NODE_ENV=production webpack -p
    
    0 讨论(0)
提交回复
热议问题