@@ -62,13 +62,77 @@ export default function (env, argv) {
6262 } ;
6363
6464 return [
65+ getCommonConfig ( mode , env ) ,
6566 getExtensionConfig ( 'node' , mode , env ) ,
6667 getExtensionConfig ( 'webworker' , mode , env ) ,
6768 getWebviewsCommonConfig ( mode , env ) ,
6869 ...getWebviewsConfigs ( mode , env ) ,
6970 ] ;
7071}
7172
73+ /** @type WebpackConfig['stats'] */
74+ const stats = {
75+ preset : 'errors-warnings' ,
76+ assets : true ,
77+ assetsSort : 'name' ,
78+ assetsSpace : 100 ,
79+ colors : true ,
80+ env : true ,
81+ errorsCount : true ,
82+ excludeAssets : [ / \. ( t t f | w e b p ) / ] ,
83+ warningsCount : true ,
84+ timings : true ,
85+ } ;
86+
87+ /**
88+ * @param { 'production' | 'development' | 'none' } mode
89+ * @param {{ analyzeBundle?: boolean; analyzeDeps?: boolean; esbuild?: boolean; skipLint?: boolean } } env
90+ * @returns { WebpackConfig }
91+ */
92+ function getCommonConfig ( mode , env ) {
93+ // Ensure that the dist folder exists otherwise the FantasticonPlugin will fail
94+ const dist = path . join ( __dirname , 'dist' ) ;
95+ if ( ! fs . existsSync ( dist ) ) {
96+ fs . mkdirSync ( dist ) ;
97+ }
98+
99+ /**
100+ * @type WebpackConfig['plugins'] | any
101+ */
102+ const plugins = [
103+ new DocsPlugin ( ) ,
104+ new LicensesPlugin ( ) ,
105+ new FantasticonPlugin ( {
106+ configPath : '.fantasticonrc.js' ,
107+ onBefore :
108+ mode !== 'production'
109+ ? undefined
110+ : ( ) =>
111+ spawnSync ( pkgMgr , [ 'run' , 'icons:svgo' ] , {
112+ cwd : __dirname ,
113+ encoding : 'utf8' ,
114+ shell : true ,
115+ } ) ,
116+ onComplete : ( ) =>
117+ spawnSync ( pkgMgr , [ 'run' , 'icons:apply' ] , {
118+ cwd : __dirname ,
119+ encoding : 'utf8' ,
120+ shell : true ,
121+ } ) ,
122+ } ) ,
123+ ] ;
124+
125+ return {
126+ name : 'common' ,
127+ context : __dirname ,
128+ entry : { } ,
129+ mode : mode ,
130+ plugins : plugins ,
131+ infrastructureLogging : mode === 'production' ? undefined : { level : 'log' } , // enables logging required for problem matchers
132+ stats : stats ,
133+ } ;
134+ }
135+
72136/**
73137 * @param { 'node' | 'webworker' } target
74138 * @param { 'production' | 'development' | 'none' } mode
@@ -112,36 +176,10 @@ function getExtensionConfig(target, mode, env) {
112176 if ( target === 'webworker' ) {
113177 plugins . push ( new optimize . LimitChunkCountPlugin ( { maxChunks : 1 } ) ) ;
114178 } else {
115- // Ensure that the dist folder exists otherwise the FantasticonPlugin will fail
116- const dist = path . join ( __dirname , 'dist' ) ;
117- if ( ! fs . existsSync ( dist ) ) {
118- fs . mkdirSync ( dist ) ;
119- }
120-
121179 plugins . push (
122180 new GenerateContributionsPlugin ( ) ,
123181 new ExtractContributionsPlugin ( ) ,
124182 new GenerateCommandTypesPlugin ( ) ,
125- new DocsPlugin ( ) ,
126- new LicensesPlugin ( ) ,
127- new FantasticonPlugin ( {
128- configPath : '.fantasticonrc.js' ,
129- onBefore :
130- mode !== 'production'
131- ? undefined
132- : ( ) =>
133- spawnSync ( pkgMgr , [ 'run' , 'icons:svgo' ] , {
134- cwd : __dirname ,
135- encoding : 'utf8' ,
136- shell : true ,
137- } ) ,
138- onComplete : ( ) =>
139- spawnSync ( pkgMgr , [ 'run' , 'icons:apply' ] , {
140- cwd : __dirname ,
141- encoding : 'utf8' ,
142- shell : true ,
143- } ) ,
144- } ) ,
145183 ) ;
146184 }
147185
@@ -278,23 +316,8 @@ function getExtensionConfig(target, mode, env) {
278316 extensions : [ '.ts' , '.tsx' , '.js' , '.jsx' , '.json' ] ,
279317 } ,
280318 plugins : plugins ,
281- infrastructureLogging :
282- mode === 'production'
283- ? undefined
284- : {
285- level : 'log' , // enables logging required for problem matchers
286- } ,
287- stats : {
288- preset : 'errors-warnings' ,
289- assets : true ,
290- assetsSort : 'name' ,
291- assetsSpace : 100 ,
292- colors : true ,
293- env : true ,
294- errorsCount : true ,
295- warningsCount : true ,
296- timings : true ,
297- } ,
319+ infrastructureLogging : mode === 'production' ? undefined : { level : 'log' } , // enables logging required for problem matchers
320+ stats : stats ,
298321 } ;
299322}
300323
@@ -411,24 +434,8 @@ function getWebviewsCommonConfig(mode, env) {
411434 : [ ] ,
412435 } ,
413436 plugins : plugins ,
414- infrastructureLogging :
415- mode === 'production'
416- ? undefined
417- : {
418- level : 'log' , // enables logging required for problem matchers
419- } ,
420- stats : {
421- preset : 'errors-warnings' ,
422- assets : true ,
423- assetsSort : 'name' ,
424- assetsSpace : 100 ,
425- colors : true ,
426- env : true ,
427- errorsCount : true ,
428- excludeAssets : [ / \. ( t t f | w e b p ) / ] ,
429- warningsCount : true ,
430- timings : true ,
431- } ,
437+ infrastructureLogging : mode === 'production' ? undefined : { level : 'log' } , // enables logging required for problem matchers
438+ stats : stats ,
432439 } ;
433440}
434441
@@ -638,24 +645,8 @@ function getWebviewConfig(webviews, overrides, mode, env) {
638645 modules : [ basePath , 'node_modules' ] ,
639646 } ,
640647 plugins : plugins ,
641- infrastructureLogging :
642- mode === 'production'
643- ? undefined
644- : {
645- level : 'log' , // enables logging required for problem matchers
646- } ,
647- stats : {
648- preset : 'errors-warnings' ,
649- assets : true ,
650- assetsSort : 'name' ,
651- assetsSpace : 100 ,
652- colors : true ,
653- env : true ,
654- errorsCount : true ,
655- excludeAssets : [ / \. ( t t f | w e b p ) / ] ,
656- warningsCount : true ,
657- timings : true ,
658- } ,
648+ infrastructureLogging : mode === 'production' ? undefined : { level : 'log' } , // enables logging required for problem matchers
649+ stats : stats ,
659650 } ;
660651}
661652
0 commit comments