webpack打包将配置文件单独抽离不压缩打包

webpack.config.js:

 plugins: [
         //提取公共模块
         new webpack.optimize.CommonsChunkPlugin({
             name: 'vendors',
             chunks: Object.keys(entries),
             minChunks: 3
         }),
         //提取文件内容的散列
        new ExtractTextPlugin({
             filename: 'css/[name].min.css',
             allChunks: true
         })
     ]

新建一个config.js  

在html中单独引入config.js  

config.js配置文件:

(function (window) {
  if (window.mapStyles) {
    return;
  }
 var mapStyles = [{
       "featureType": "water",
       "elementType": "all",
       "stylers": {
         "color": "#021019"
       }
     }
   ];
  window.mapStyles = mapStyles;
})(this);

 

在requireJS中需要配置相应路径才能不被压缩  require('!file-loader?name=/js/[name].[ext]!../common/config.js');

不能直接 require('config');

需要加上  !file-loader?name=/js/[name].[ext]!  后面再加路径名
最后可再 window 对象中访问配置的  mapStyles 对象
 
原文地址:https://www.cnblogs.com/gaoguowen/p/10108663.html