1- const webpack = require ( 'webpack' ) ;
2-
31const isProduction = true ;
4- const useOptimize = isProduction ;
52const useSourceMap = ! isProduction ;
63
74module . exports = {
5+ mode : isProduction ? 'production' : 'development' ,
86 entry : './src/main.js' ,
97 output : { // ファイルの出力設定
108 path : `${ __dirname } /../html/js` , // 出力ファイルのディレクトリ名
11- filename : 'bundle.js' // 出力ファイル名
9+ filename : 'bundle.js' , // 出力ファイル名
1210 } ,
1311 module : {
1412 rules : [
@@ -22,13 +20,11 @@ module.exports = {
2220 // Babel のオプションを指定する
2321 options : {
2422 presets : [
25- // env を指定することで、ES2017 を ES5 に変換。
26- // {modules: false}にしないと import 文が Babel によって CommonJS に変換され、
27- // webpack の Tree Shaking 機能が使えない
28- [ 'env' , { 'modules' : false } ]
29- ]
30- }
31- }
23+ // プリセットを指定することで、ES2018 を ES5 に変換
24+ '@babel/preset-env' ,
25+ ] ,
26+ } ,
27+ } ,
3228 ] ,
3329 // node_modules は除外する
3430 exclude : / n o d e _ m o d u l e s / ,
@@ -46,7 +42,7 @@ module.exports = {
4642 url : true ,
4743 // ソースマップを有効にする
4844 sourceMap : useSourceMap ,
49- importLoaders : 2
45+ importLoaders : 2 ,
5046 } ,
5147 } ,
5248 {
@@ -62,27 +58,13 @@ module.exports = {
6258 // 画像関係
6359 {
6460 test : / \. ( p n g | j p e g | s v g ) $ / ,
65- use : 'url-loader'
61+ use : 'url-loader' ,
6662 } ,
6763 // フォント関係
6864 {
6965 test : / \. ( o t f | e o t | s v g | t t f | w o f f | w o f f 2 ) ( \? .+ ) ? $ / ,
70- use : 'url-loader'
71- }
66+ use : 'url-loader' ,
67+ } ,
7268 ] ,
7369 } ,
74- plugins : useOptimize === true ? [
75- // 【効果:中】Scope Hoistingをするためのプラグイン
76- new webpack . optimize . ModuleConcatenationPlugin ( ) ,
77-
78- // 【効果:大】JSファイルのminifyを実行する
79- new webpack . optimize . UglifyJsPlugin ( {
80- sourceMap : useSourceMap ,
81- compress : {
82- warnings : false ,
83- } ,
84- // マルチプロセスで高速化
85- parallel : true ,
86- } ) ,
87- ] : [ ]
8870} ;
0 commit comments