22 * License, v. 2.0. If a copy of the MPL was not distributed with this
33 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44
5- const LodashModuleReplacementPlugin = require ( 'lodash-webpack-plugin' ) ;
6- const TerserPlugin = require ( "terser-webpack-plugin" ) ;
7- const NodePolyfillPlugin = require ( "node-polyfill-webpack-plugin" )
8- const webpack = require ( 'webpack' ) ;
9- const path = require ( 'path' ) ;
10- const { CheckerPlugin } = require ( 'awesome-typescript-loader' ) ;
11-
12- const BUILD_DIR = path . resolve ( __dirname , 'src/client/public/app' ) ;
13- const APP_DIR = path . resolve ( __dirname , 'src/client/app' ) ;
14-
15- const config = {
16- // Enable sourcemaps for debugging webpack's output.
17- devtool : 'source-map' ,
18- entry : {
19- application : APP_DIR + "/index.tsx" ,
20- } ,
21- cache : {
22- type : "filesystem"
23- } ,
24- resolve : {
25- fallback : {
26- "buffer" : require . resolve ( 'buffer/' ) ,
27- "assert" : require . resolve ( 'assert/' ) ,
28- "stream" : require . resolve ( 'stream-browserify' ) ,
29- "fs" : false
30- } ,
31- // Add '.ts' and '.tsx' as resolvable extensions.
32- extensions : [ ".css" , ".ts" , ".tsx" , ".js" , ".jsx" , ".json" ]
33- } ,
34-
35- // Ignore warnings about bundle size
36- performance : {
37- hints : false
38- } ,
39- module : {
40- rules : [
41- // All TypeScript ('.ts' or '.tsx') will be handled by 'awesome-typescript-loader'.
42- // Also, for development, JavaScript is handled by 'awesome-typescript-loader' and passed to Babel.
43- { test : / \. [ j t ] s x ? $ / , exclude : / n o d e _ m o d u l e s / , use :[ { loader : "awesome-typescript-loader" } ] } ,
44- // Any remaining JavaScript ('.js' or '.jsx') will be transpiled by Babel, for production uglification.
45- { test : / \/ j s x ? $ / , exclude : / n o d e _ m o d u l e s / , use :[ { loader : "babel-loader" } ] } ,
46- // CSS stylesheet loader.
47- { test : / \. c s s $ / , use : [
48- { loader : "style-loader" } ,
49- { loader : "css-loader" }
50- ] , } ,
51- // Babel not able to resolve imports https://github.com/webpack/webpack/issues/11467#issuecomment-691873586
52- {
53- test : / \. m ? j s / ,
54- resolve : {
55- fullySpecified : false
56- }
57- } ,
58- // All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'.
59- { enforce : "pre" , test : / \. j s $ / , use :[ { loader : "source-map-loader" } ] }
60- ]
61- } ,
62- output : {
63- filename : "bundle.js" ,
64- path : BUILD_DIR
65- } ,
66- plugins : [
67- new LodashModuleReplacementPlugin ( ) ,
68- new NodePolyfillPlugin ( ) ,
69- new CheckerPlugin ( ) ,
70- ]
71- } ;
72-
73- if ( process . env . NODE_ENV === 'production' ) {
74- config . plugins . push (
75- new webpack . DefinePlugin ( {
76- 'process.env' : {
77- NODE_ENV : JSON . stringify ( 'production' )
78- }
79- } ) ,
80- new TerserPlugin ( { sourceMap : true } )
81- ) ;
82- }
83-
84- module . exports = config ;
5+ const LodashModuleReplacementPlugin = require ( 'lodash-webpack-plugin' ) ;
6+ const TerserPlugin = require ( "terser-webpack-plugin" ) ;
7+ const NodePolyfillPlugin = require ( "node-polyfill-webpack-plugin" )
8+ const webpack = require ( 'webpack' ) ;
9+ const path = require ( 'path' ) ;
10+ const { CheckerPlugin } = require ( 'awesome-typescript-loader' ) ;
11+
12+ const BUILD_DIR = path . resolve ( __dirname , 'src/client/public/app' ) ;
13+ const APP_DIR = path . resolve ( __dirname , 'src/client/app' ) ;
14+
15+ const config = {
16+ // Enable sourcemaps for debugging webpack's output.
17+ devtool : 'source-map' ,
18+ entry : {
19+ application : APP_DIR + "/index.tsx" ,
20+ } ,
21+ cache : {
22+ type : "filesystem"
23+ } ,
24+ resolve : {
25+ fallback : {
26+ "buffer" : require . resolve ( 'buffer/' ) ,
27+ "assert" : require . resolve ( 'assert/' ) ,
28+ "stream" : require . resolve ( 'stream-browserify' ) ,
29+ "fs" : false
30+ } ,
31+ // Add '.ts' and '.tsx' as resolvable extensions.
32+ extensions : [ ".css" , ".ts" , ".tsx" , ".js" , ".jsx" , ".json" ]
33+ } ,
34+
35+ // Ignore warnings about bundle size
36+ performance : {
37+ hints : false
38+ } ,
39+ module : {
40+ rules : [
41+ // All TypeScript ('.ts' or '.tsx') will be handled by 'awesome-typescript-loader'.
42+ // Also, for development, JavaScript is handled by 'awesome-typescript-loader' and passed to Babel.
43+ { test : / \. [ j t ] s x ? $ / , exclude : / n o d e _ m o d u l e s / , use :[ { loader : "awesome-typescript-loader" } ] } ,
44+ // Any remaining JavaScript ('.js' or '.jsx') will be transpiled by Babel, for production uglification.
45+ { test : / \/ j s x ? $ / , exclude : / n o d e _ m o d u l e s / , use :[ { loader : "babel-loader" } ] } ,
46+ // CSS stylesheet loader.
47+ { test : / \. c s s $ / , use : [
48+ { loader : "style-loader" } ,
49+ { loader : "css-loader" }
50+ ] , } ,
51+ // Babel not able to resolve imports https://github.com/webpack/webpack/issues/11467#issuecomment-691873586
52+ {
53+ test : / \. m ? j s / ,
54+ resolve : {
55+ fullySpecified : false
56+ }
57+ } ,
58+ // All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'.
59+ { enforce : "pre" , test : / \. j s $ / , use :[ { loader : "source-map-loader" } ] }
60+ ]
61+ } ,
62+ output : {
63+ filename : "bundle.js" ,
64+ path : BUILD_DIR
65+ } ,
66+ plugins : [
67+ new LodashModuleReplacementPlugin ( ) ,
68+ new NodePolyfillPlugin ( ) ,
69+ new CheckerPlugin ( ) ,
70+ ]
71+ } ;
72+
73+ if ( process . env . NODE_ENV === 'production' ) {
74+ config . plugins . push (
75+ new webpack . DefinePlugin ( {
76+ 'process.env' : {
77+ NODE_ENV : JSON . stringify ( 'production' )
78+ }
79+ } ) ,
80+ new TerserPlugin ( {
81+ terserOptions : {
82+ sourceMap : true
83+ } ,
84+ } )
85+ ) ;
86+ }
87+
88+ module . exports = config ;
89+
0 commit comments