88const path = require ( 'path' ) ;
99const webpack = require ( 'webpack' ) ;
1010
11- /** @type webpack.Configuration */
12- const webview = {
13- name : 'webiew' ,
14- entry : {
15- index : './preview-src/index.ts'
16- } ,
17- module : {
18- rules : [
19- {
20- test : / \. t s x ? $ / ,
21- use : 'ts-loader' ,
22- exclude : / n o d e _ m o d u l e s /
23- } ,
24- {
25- test : / \. c s s / ,
26- use : [ 'style-loader' , 'css-loader' ]
27- }
28- ]
29- } ,
30- resolve : {
31- extensions : [ '.tsx' , '.ts' , '.js' ]
32- } ,
33- devtool : 'inline-source-map' ,
34- output : {
35- filename : '[name].js' ,
36- path : path . resolve ( __dirname , 'media' )
37- }
38- } ;
11+ function getWebviewConfig ( env ) {
12+ /** @type webpack.Configuration */
13+ let webview = {
14+ name : 'webiew' ,
15+ mode : env . production ? 'production' : 'development' ,
16+ entry : {
17+ index : './preview-src/index.ts'
18+ } ,
19+ module : {
20+ rules : [
21+ {
22+ test : / \. t s x ? $ / ,
23+ use : 'ts-loader' ,
24+ exclude : / n o d e _ m o d u l e s /
25+ } ,
26+ {
27+ test : / \. c s s / ,
28+ use : [ 'style-loader' , 'css-loader' ]
29+ }
30+ ]
31+ } ,
32+ resolve : {
33+ extensions : [ '.tsx' , '.ts' , '.js' ]
34+ } ,
35+ devtool : ! env . production ? 'inline-source-map' : undefined ,
36+ output : {
37+ filename : '[name].js' ,
38+ path : path . resolve ( __dirname , 'media' )
39+ }
40+ } ;
41+
42+ return webview ;
43+ }
3944
40- /** @type webpack.Configuration */
41- const extension = {
42- name : 'extension' ,
43- target : 'node' ,
44- entry : {
45- extension : './src/extension.ts'
46- } ,
47- module : {
48- rules : [
49- {
50- test : / \. t s x ? $ / ,
51- use : 'ts-loader' ,
52- exclude : / n o d e _ m o d u l e s /
45+ /**
46+ *
47+ * @param {* } env
48+ * @returns webpack.Configuration
49+ */
50+ function getExtensionConfig ( env ) {
51+ /** @type webpack.Configuration */
52+ let config = {
53+ name : 'extension' ,
54+ mode : env . production ? 'production' : 'development' ,
55+ target : 'node' ,
56+ entry : {
57+ extension : './src/extension.ts'
58+ } ,
59+ module : {
60+ rules : [
61+ {
62+ test : / \. t s x ? $ / ,
63+ use : 'ts-loader' ,
64+ exclude : / n o d e _ m o d u l e s /
65+ }
66+ ]
67+ } ,
68+ resolve : {
69+ extensions : [ '.tsx' , '.ts' , '.js' ] ,
70+ alias : {
71+ "node-fetch" : path . resolve ( __dirname , 'node_modules/node-fetch/lib/index.js' ) ,
5372 }
54- ]
55- } ,
56- resolve : {
57- extensions : [ '.tsx' , '.ts' , '.js' ] ,
58- alias : {
59- "node-fetch" : path . resolve ( __dirname , 'node_modules/node-fetch/lib/index.js' ) ,
60- }
61- } ,
62- devtool : 'source-map' ,
63- output : {
64- filename : '[name].js' ,
65- path : path . resolve ( __dirname , 'media' ) ,
66- libraryTarget : "commonjs" ,
67- devtoolModuleFilenameTemplate : 'file:///[absolute-resource-path]'
68- } ,
69- externals : {
70- 'vscode' : 'commonjs vscode' ,
71- 'utf-8-validate' : 'utf-8-validate' ,
72- 'bufferutil' : 'bufferutil' ,
73- 'encoding' : 'encoding'
74- } ,
75- } ;
73+ } ,
74+ devtool : ! env . production ? 'source-map' : undefined ,
75+ output : {
76+ filename : '[name].js' ,
77+ path : path . resolve ( __dirname , 'media' ) ,
78+ libraryTarget : "commonjs" ,
79+ devtoolModuleFilenameTemplate : 'file:///[absolute-resource-path]'
80+ } ,
81+ externals : {
82+ 'vscode' : 'commonjs vscode' ,
83+ 'utf-8-validate' : 'utf-8-validate' ,
84+ 'bufferutil' : 'bufferutil' ,
85+ 'encoding' : 'encoding'
86+ } ,
87+ } ;
88+
89+ return config ;
90+ }
7691
77- module . exports = [ webview , extension ] ;
92+ module . exports = function ( env ) {
93+ env = env || { } ;
94+ env . production = ! ! env . production ;
95+ return [ getExtensionConfig ( env ) , getWebviewConfig ( env ) ] ;
96+ } ;
0 commit comments