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 對象

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM