@@ -5,7 +5,7 @@ const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
55const TerserPlugin = require ( 'terser-webpack-plugin' ) ;
66const webpack = require ( 'webpack' ) ;
77
8- module . exports = ( { mode = 'development' , hot = false , cache = false } = { } ) => {
8+ module . exports = ( { mode = 'development' , hot = false , cache = false , transpile = false } = { } ) => {
99 const production = mode === 'production' ;
1010
1111 // Have to pass this option to prevent complaints about empty exports:
@@ -34,6 +34,51 @@ module.exports = ({ mode = 'development', hot = false, cache = false } = {}) =>
3434 // for scss blocks
3535 const sassLoaders = [ cssInsertionLoader , cssLoader , postCSSLoader , 'sass-loader' ] ;
3636
37+ const rules = [
38+ // Transpilation and code loading rules
39+ {
40+ test : / \. v u e $ / ,
41+ loader : 'vue-loader' ,
42+ options : {
43+ compilerOptions : {
44+ preserveWhitespace : false ,
45+ } ,
46+ } ,
47+ } ,
48+ {
49+ test : / \. c s s $ / ,
50+ use : [ cssInsertionLoader , cssLoader , postCSSLoader ] ,
51+ } ,
52+ {
53+ test : / \. s [ a | c ] s s $ / ,
54+ use : sassLoaders ,
55+ } ,
56+ {
57+ test : / \. ( p n g | j p e ? g | g i f | s v g | e o t | w o f f | t t f | w o f f 2 ) $ / ,
58+ type : 'asset' ,
59+ generator : {
60+ filename : '[name]-[contenthash][ext]' ,
61+ } ,
62+ parser : {
63+ dataUrlCondition : {
64+ maxSize : 10000 ,
65+ } ,
66+ } ,
67+ } ,
68+ ] ;
69+
70+ if ( transpile ) {
71+ rules . push ( {
72+ test : / \. j s $ / ,
73+ loader : 'babel-loader' ,
74+ exclude : { and : [ / ( n o d e _ m o d u l e s \/ v u e | d i s t | c o r e - j s ) / , { not : [ / \. ( e s m \. j s | m j s ) $ / ] } ] } ,
75+ options : {
76+ cacheDirectory : cache ,
77+ cacheCompression : false ,
78+ } ,
79+ } ) ;
80+ }
81+
3782 return {
3883 target : 'browserslist' ,
3984 mode,
@@ -45,47 +90,7 @@ module.exports = ({ mode = 'development', hot = false, cache = false } = {}) =>
4590 } ,
4691 } ,
4792 module : {
48- rules : [
49- // Transpilation and code loading rules
50- {
51- test : / \. v u e $ / ,
52- loader : 'vue-loader' ,
53- options : {
54- compilerOptions : {
55- preserveWhitespace : false ,
56- } ,
57- } ,
58- } ,
59- {
60- test : / \. j s $ / ,
61- loader : 'babel-loader' ,
62- exclude : { and : [ / ( n o d e _ m o d u l e s \/ v u e | d i s t | c o r e - j s ) / , { not : [ / \. ( e s m \. j s | m j s ) $ / ] } ] } ,
63- options : {
64- cacheDirectory : cache ,
65- cacheCompression : false ,
66- } ,
67- } ,
68- {
69- test : / \. c s s $ / ,
70- use : [ cssInsertionLoader , cssLoader , postCSSLoader ] ,
71- } ,
72- {
73- test : / \. s [ a | c ] s s $ / ,
74- use : sassLoaders ,
75- } ,
76- {
77- test : / \. ( p n g | j p e ? g | g i f | s v g | e o t | w o f f | t t f | w o f f 2 ) $ / ,
78- type : 'asset' ,
79- generator : {
80- filename : '[name]-[contenthash][ext]' ,
81- } ,
82- parser : {
83- dataUrlCondition : {
84- maxSize : 10000 ,
85- } ,
86- } ,
87- } ,
88- ] ,
93+ rules,
8994 } ,
9095 node : {
9196 __filename : true ,
0 commit comments