@@ -5,123 +5,123 @@ const nodeModulesPath = path.resolve(__dirname, '../node_modules')
55const browserslistConfig = require ( '@wordpress/browserslist-config' )
66
77function isEditor ( loaderContext ) {
8- return loaderContext . resource . indexOf ( 'editor.scss' ) > - 1
8+ return loaderContext . resource . indexOf ( 'editor.scss' ) > - 1
99}
1010
1111module . exports = {
12- get : function ( mode ) {
13- const isProduction = mode === 'production'
12+ get : function ( mode ) {
13+ const isProduction = mode === 'production'
1414
15- return [
16- /* FontsLoader */ {
17- test : / \. ( w o f f | w o f f 2 ) $ / ,
18- type : 'asset/resource' ,
19- include : [ srcPath + '/fonts' , nodeModulesPath + '/@fontsource-variable' , nodeModulesPath + '/@fontsource' ] ,
20- generator : {
21- filename : 'fonts/[name][ext][query]' ,
22- } ,
23- } ,
24- /* ImagesLoader */ {
25- test : / \. ( p n g | j p e ? g | g i f | s v g | a v i f | w e b p ) $ / ,
26- type : 'asset/resource' ,
27- exclude : / i c o n s / ,
28- include : srcPath + '/img' ,
29- generator : {
30- filename : 'images/[name][ext][query]' ,
31- } ,
32- } ,
33- /* JSLoader */ {
34- test : / \. j s $ / i,
35- include : srcPath + '/js' ,
36- use : {
37- loader : 'esbuild-loader' ,
38- options : {
39- loader : 'js' ,
40- target : 'es2016' ,
41- legalComments : 'inline' ,
42- } ,
43- } ,
44- } ,
45- /* SCSSLoader */ {
46- test : / \. ( s c s s | c s s ) $ / ,
47- include : srcPath + '/scss' ,
48- use : [
49- MiniCssExtractPlugin . loader ,
50- {
51- loader : 'css-loader' ,
52- options : {
53- url : true ,
54- esModule : false ,
55- importLoaders : 1 ,
56- } ,
57- } ,
58- {
59- loader : 'postcss-loader' ,
60- options : {
61- postcssOptions : function ( loaderContext ) {
62- let obj = {
63- plugins : {
64- 'postcss-import' : { } ,
65- 'postcss-preset-env' : {
66- browsers : browserslistConfig ,
67- stage : 2 ,
68- features : {
69- // https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_logical_properties_and_values
70- // https://stackoverflow.com/questions/64565180/how-to-prevent-postcss-preset-env-from-removing-css-logical-properties#answer-66966232
71- // Use stage 2 features + disable logical properties and values rule
72- 'logical-properties-and-values' : false ,
73- } ,
74- } ,
75- 'postcss-pxtorem' : { propWhiteList : [ ] } ,
76- 'postcss-sort-media-queries' : { } ,
77- } ,
78- }
15+ return [
16+ /* FontsLoader */ {
17+ test : / \. ( w o f f | w o f f 2 ) $ / ,
18+ type : 'asset/resource' ,
19+ include : [ srcPath + '/fonts' , nodeModulesPath + '/@fontsource-variable' , nodeModulesPath + '/@fontsource' ] ,
20+ generator : {
21+ filename : 'fonts/[name][ext][query]' ,
22+ } ,
23+ } ,
24+ /* ImagesLoader */ {
25+ test : / \. ( p n g | j p e ? g | g i f | s v g | a v i f | w e b p ) $ / ,
26+ type : 'asset/resource' ,
27+ exclude : / i c o n s / ,
28+ include : srcPath + '/img' ,
29+ generator : {
30+ filename : 'images/[name][ext][query]' ,
31+ } ,
32+ } ,
33+ /* JSLoader */ {
34+ test : / \. j s $ / i,
35+ include : srcPath + '/js' ,
36+ use : {
37+ loader : 'esbuild-loader' ,
38+ options : {
39+ loader : 'js' ,
40+ target : 'es2016' ,
41+ legalComments : 'inline' ,
42+ } ,
43+ } ,
44+ } ,
45+ /* SCSSLoader */ {
46+ test : / \. ( s c s s | c s s ) $ / ,
47+ include : srcPath + '/scss' ,
48+ use : [
49+ MiniCssExtractPlugin . loader ,
50+ {
51+ loader : 'css-loader' ,
52+ options : {
53+ url : true ,
54+ esModule : false ,
55+ importLoaders : 1 ,
56+ } ,
57+ } ,
58+ {
59+ loader : 'postcss-loader' ,
60+ options : {
61+ postcssOptions : function ( loaderContext ) {
62+ let obj = {
63+ plugins : {
64+ 'postcss-import' : { } ,
65+ 'postcss-preset-env' : {
66+ browsers : browserslistConfig ,
67+ stage : 2 ,
68+ features : {
69+ // https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_logical_properties_and_values
70+ // https://stackoverflow.com/questions/64565180/how-to-prevent-postcss-preset-env-from-removing-css-logical-properties#answer-66966232
71+ // Use stage 2 features + disable logical properties and values rule
72+ 'logical-properties-and-values' : false ,
73+ } ,
74+ } ,
75+ 'postcss-pxtorem' : { propWhiteList : [ ] } ,
76+ 'postcss-sort-media-queries' : { } ,
77+ } ,
78+ }
7979
80- if ( isProduction && ! isEditor ( loaderContext ) ) {
81- obj . plugins . cssnano = { }
82- }
80+ if ( isProduction && ! isEditor ( loaderContext ) ) {
81+ obj . plugins . cssnano = { }
82+ }
8383
84- return obj
85- } ,
86- } ,
87- } ,
88- {
89- loader : 'sass-loader' ,
90- options : {
91- sassOptions : function ( loaderContext ) {
92- let obj = {
93- quietDeps : true ,
94- sourceMap : true ,
95- }
84+ return obj
85+ } ,
86+ } ,
87+ } ,
88+ {
89+ loader : 'sass-loader' ,
90+ options : {
91+ sassOptions : function ( loaderContext ) {
92+ let obj = {
93+ quietDeps : true ,
94+ sourceMap : true ,
95+ }
9696
97- if ( isProduction && isEditor ( loaderContext ) ) {
98- obj . outputStyle = 'expanded'
99- }
97+ if ( isProduction && isEditor ( loaderContext ) ) {
98+ obj . outputStyle = 'expanded'
99+ }
100100
101- return obj
102- } ,
103- } ,
104- } ,
105- ] ,
106- } ,
107- /* SVGLoader */ {
108- test : / \. s v g $ / ,
109- include : srcPath + '/img/icons' ,
110- use : [
111- {
112- loader : 'svg-sprite-loader' ,
113- options : {
114- extract : true ,
115- publicPath : 'icons/' ,
116- spriteFilename : ( svgPath ) => `${ / i c o n s ( [ \\ | / ] ) ( .* ?) \1/ gm. exec ( svgPath ) [ 2 ] } .svg` ,
117- symbolId : ( filePath ) => `icon-${ path . basename ( filePath ) . slice ( 0 , - 4 ) } ` ,
118- } ,
119- } ,
120- {
121- loader : 'svgo-loader' ,
122- } ,
123- ] ,
124- } ,
125- ]
126- } ,
101+ return obj
102+ } ,
103+ } ,
104+ } ,
105+ ] ,
106+ } ,
107+ /* SVGLoader */ {
108+ test : / \. s v g $ / ,
109+ include : srcPath + '/img/icons' ,
110+ use : [
111+ {
112+ loader : 'svg-sprite-loader' ,
113+ options : {
114+ extract : true ,
115+ publicPath : 'icons/' ,
116+ spriteFilename : ( svgPath ) => `${ / i c o n s ( [ \\ | / ] ) ( .* ?) \1/ gm. exec ( svgPath ) [ 2 ] } .svg` ,
117+ symbolId : ( filePath ) => `icon-${ path . basename ( filePath ) . slice ( 0 , - 4 ) } ` ,
118+ } ,
119+ } ,
120+ {
121+ loader : 'svgo-loader' ,
122+ } ,
123+ ] ,
124+ } ,
125+ ]
126+ } ,
127127}
0 commit comments