1- var webpack = require ( 'webpack' ) ;
2- var ExtractTextPlugin = require ( 'extract-text-webpack-plugin' ) ;
1+ const webpack = require ( 'webpack' ) ;
2+ const MiniCssExtractPlugin = require ( 'mini-css-extract-plugin' ) ;
3+ const ESLintPlugin = require ( 'eslint-webpack-plugin' ) ;
34const pkg = require ( '../package.json' ) ;
45
56//包版本(ES6或者ES5)
6- let moduleVersion = process . env . moduleVersion || " es5" ;
7+ let moduleVersion = process . env . moduleVersion || ' es5' ;
78
89//打包公共配置
910module . exports = {
10-
1111 moduleVersion : moduleVersion ,
1212
13- mode : " production" ,
13+ mode : ' production' ,
1414 //页面入口文件配置
1515 entry : { } ,
1616
@@ -19,12 +19,13 @@ module.exports = {
1919 return {
2020 path : `${ __dirname } /../dist/${ libName } /` ,
2121 filename : `${ fileName } .js`
22- }
22+ } ;
2323 } ,
2424
2525 //是否启用压缩
2626 optimization : {
27- minimize : false
27+ minimize : false ,
28+ emitOnErrors : false
2829 } ,
2930 //不显示打包文件大小相关警告
3031 performance : {
@@ -37,46 +38,32 @@ module.exports = {
3738 } ,
3839
3940 externals : {
40- ' echarts' : 'function(){try{return echarts}catch(e){return {}}}()' ,
41- ' mapv' : " function(){try{return mapv}catch(e){return {}}}()" ,
42- ' elasticsearch' : 'function(){try{return elasticsearch}catch(e){return {}}}()'
41+ echarts : 'function(){try{return echarts}catch(e){return {}}}()' ,
42+ mapv : ' function(){try{return mapv}catch(e){return {}}}()' ,
43+ elasticsearch : 'function(){try{return elasticsearch}catch(e){return {}}}()'
4344 } ,
4445
4546 module : {
4647 rules : {
4748 img : {
4849 //图片小于80k采用base64编码
4950 test : / \. ( p n g | j p g | j p e g | g i f | w o f f | w o f f 2 | s v g | e o t | t t f ) $ / ,
50- use : [ {
51- loader : 'url-loader' ,
52- options : {
53- limit : 150000
51+ use : [
52+ {
53+ loader : 'url-loader' ,
54+ options : {
55+ limit : 150000
56+ }
5457 }
55- } ]
56- } ,
57-
58- eslint : {
59- test : [ / \. j s $ / ] ,
60- exclude : / n o d e _ m o d u l e s / ,
61- enforce : 'pre' ,
62- loader : 'eslint-loader' ,
63- options : {
64- failOnError : true
65- }
58+ ]
6659 } ,
67-
6860 css : {
6961 test : / \. c s s $ / ,
70- use : ExtractTextPlugin . extract ( {
71- use : {
72- loader : 'css-loader'
73- }
74- } )
62+ use : [ MiniCssExtractPlugin . loader , 'css-loader' ]
7563 }
7664 }
7765 } ,
7866
79-
8067 bannerInfo : function ( libName ) {
8168 return `
8269 ${ libName } .(${ pkg . homepage } )
@@ -89,8 +76,8 @@ module.exports = {
8976 plugins : function ( libName , productName ) {
9077 return [
9178 new webpack . BannerPlugin ( this . bannerInfo ( productName ) ) ,
92- new ExtractTextPlugin ( `./${ productName } .css` ) ,
93- new webpack . NoEmitOnErrorsPlugin ( )
94- ]
79+ new MiniCssExtractPlugin ( { filename : `./${ productName } .css` } ) ,
80+ new ESLintPlugin ( { failOnError : true , files : 'src' } )
81+ ] ;
9582 }
96- } ;
83+ } ;
0 commit comments