1- const path = require ( ' path' ) ;
2- const HtmlWebpackPlugin = require ( ' html-webpack-plugin' ) ;
3- const CompressionPlugin = require ( ' compression-webpack-plugin' ) ;
4- const { CleanWebpackPlugin } = require ( ' clean-webpack-plugin' ) ;
5- const CopyWebpackPlugin = require ( ' copy-webpack-plugin' ) ;
1+ const path = require ( " path" ) ;
2+ const HtmlWebpackPlugin = require ( " html-webpack-plugin" ) ;
3+ const CompressionPlugin = require ( " compression-webpack-plugin" ) ;
4+ const { CleanWebpackPlugin } = require ( " clean-webpack-plugin" ) ;
5+ const CopyWebpackPlugin = require ( " copy-webpack-plugin" ) ;
66
77const copyPaths = [
8- { from : path . resolve ( __dirname , "src/assets" ) , to : ' assets' } ,
8+ { from : path . resolve ( __dirname , "src/assets" ) , to : " assets" } ,
99] ;
1010
1111module . exports = function webpacking ( envVariables ) {
@@ -14,36 +14,43 @@ module.exports = function webpacking(envVariables) {
1414 env = { } ;
1515 }
1616 if ( ! env . mode ) {
17- env . mode = ' production' ;
17+ env . mode = " production" ;
1818 }
1919
20-
21- console . log ( '####################' ) ;
22- console . log ( '####################' ) ;
23- console . log ( 'BUILD bundle with parameters:' ) ;
24- console . log ( env ) ;
25- console . log ( '####################' ) ;
26- console . log ( '####################' ) ;
20+ console . log ( "####################" ) ;
21+ console . log ( "####################" ) ;
22+ console . log ( "BUILD bundle with parameters:" ) ;
23+ console . log ( env ) ;
24+ console . log ( "####################" ) ;
25+ console . log ( "####################" ) ;
2726
2827 const { mode } = env ;
29- const devtool = env . mode === 'source-map' ;
30-
28+ const devtool = "source-map" ;
3129
3230 const output = {
33- path : path . resolve ( __dirname , 'dist' ) ,
34- filename : '[name].[contenthash].js'
31+ path : path . resolve ( __dirname , "dist" ) ,
32+ filename : "[name].[contenthash].js" ,
33+ publicPath : "/"
3534 } ;
3635
3736 const module = {
3837 rules : [
3938 {
4039 test : / \. ( j s | j s x ) $ / ,
4140 exclude : / n o d e _ m o d u l e s / ,
42- loader : ' babel-loader'
41+ loader : " babel-loader" ,
4342 } ,
4443 {
45- test : / \. t s | t s x ? $ / ,
46- loader : "awesome-typescript-loader"
44+ test : / \. t s ( x ? ) $ / ,
45+ include : path . resolve ( __dirname , 'src' ) ,
46+ use : [
47+ {
48+ loader : "ts-loader" ,
49+ options : {
50+ transpileOnly : true ,
51+ } ,
52+ }
53+ ]
4754 } ,
4855 {
4956 test : / \. ( c s s ) $ / ,
@@ -53,7 +60,8 @@ module.exports = function webpacking(envVariables) {
5360 } ,
5461 {
5562 loader : "css-loader" ,
56- } ] ,
63+ } ,
64+ ] ,
5765 } ,
5866 {
5967 test : / \. l e s s $ / ,
@@ -76,27 +84,33 @@ module.exports = function webpacking(envVariables) {
7684 } ,
7785 {
7886 test : / \. ( p n g | j p g | g i f | e o t | w o f f | w o f f 2 | s v g | t t f ) $ / ,
79- loader : 'file-loader'
87+ use : [
88+ "file-loader" ,
89+ {
90+ loader : "image-webpack-loader" ,
91+ options : {
92+ bypassOnDebug : true , // webpack@1.x
93+ disable : true , // webpack@2.x and newer
94+ } ,
95+ } ,
96+ ] ,
8097 } ,
81-
82- ]
98+ ] ,
8399 } ;
84100
85101 const resolve = {
86- extensions : [ '*' , ' .js' , ' .json' , ' .ts' , ' .tsx' , ' .jsx' ] ,
87- symlinks : false
102+ extensions : [ "*" , " .js" , " .json" , " .ts" , " .tsx" , " .jsx" ] ,
103+ symlinks : false ,
88104 } ;
89105
90-
91-
92106 const plugins = [
93107 new CleanWebpackPlugin ( ) ,
94108 new CopyWebpackPlugin ( { patterns : copyPaths } ) ,
95109 new CompressionPlugin ( ) ,
96110 new HtmlWebpackPlugin ( {
97- template : ' src/index.ejs' ,
98- favicon : path . join ( __dirname , ' src/assets/icon.png' )
99- } )
111+ template : " src/index.ejs" ,
112+ favicon : path . join ( __dirname , " src/assets/icon.png" ) ,
113+ } ) ,
100114 ] ;
101115
102116 return {
@@ -105,6 +119,6 @@ module.exports = function webpacking(envVariables) {
105119 output,
106120 module,
107121 resolve,
108- plugins
122+ plugins,
109123 } ;
110124} ;
0 commit comments