@@ -14,17 +14,26 @@ module.exports = (env, argv) => {
1414 argv . mode = "development" ;
1515 }
1616
17+ const development = { } ;
18+ if ( argv . mode !== "production" ) {
19+ // This makes the sourcemaps human readable for developers. We use eval-source-map
20+ // because the plain source-map devtool ruins the alignment.
21+ development [ 'devtool' ] = 'eval-source-map' ;
22+ }
23+
1724 return {
25+ ...development ,
26+
1827 entry : {
1928 "bundle" : "./src/vector/index.js" ,
20- "indexeddb-worker" : "./src/vector/indexeddb-worker.js" ,
21- "mobileguide" : "./src/vector/mobile_guide/index.js" ,
22-
23- // CSS themes
24- "theme-light" : "./node_modules/matrix-react-sdk/res/themes/light/css/light.scss" ,
25- "theme-dark" : "./node_modules/matrix-react-sdk/res/themes/dark/css/dark.scss" ,
26- "theme-light-custom" : "./node_modules/matrix-react-sdk/res/themes/light-custom/css/light-custom.scss" ,
27- "theme-dark-custom" : "./node_modules/matrix-react-sdk/res/themes/dark-custom/css/dark-custom.scss" ,
29+ "indexeddb-worker" : "./src/vector/indexeddb-worker.js" ,
30+ "mobileguide" : "./src/vector/mobile_guide/index.js" ,
31+
32+ // CSS themes
33+ "theme-light" : "./node_modules/matrix-react-sdk/res/themes/light/css/light.scss" ,
34+ "theme-dark" : "./node_modules/matrix-react-sdk/res/themes/dark/css/dark.scss" ,
35+ "theme-light-custom" : "./node_modules/matrix-react-sdk/res/themes/light-custom/css/light-custom.scss" ,
36+ "theme-dark-custom" : "./node_modules/matrix-react-sdk/res/themes/dark-custom/css/dark-custom.scss" ,
2837 } ,
2938
3039 optimization : {
@@ -35,17 +44,21 @@ module.exports = (env, argv) => {
3544 cacheGroups : {
3645 styles : {
3746 name : 'styles' ,
38- test : / \. c s s $ / ,
39- enforce : true ,
47+ test : / \. c s s $ / ,
48+ enforce : true ,
4049 // Do not add `chunks: 'all'` here because you'll break the app entry point.
4150 } ,
4251 } ,
4352 } ,
4453
54+ // This fixes duplicate files showing up in chrome with sourcemaps enabled.
55+ // See https://github.com/webpack/webpack/issues/7128 for more info.
56+ namedModules : false ,
57+
4558 // Minification is normally enabled by default for webpack in production mode, but
4659 // we use a CSS optimizer too and need to manage it ourselves.
4760 minimize : argv . mode === 'production' ,
48- minimizer : argv . mode === 'production' ? [ new TerserPlugin ( { } ) , new OptimizeCSSAssetsPlugin ( { } ) ] : [ ] ,
61+ minimizer : argv . mode === 'production' ? [ new TerserPlugin ( { } ) , new OptimizeCSSAssetsPlugin ( { } ) ] : [ ] ,
4962 } ,
5063
5164 resolve : {
@@ -59,22 +72,22 @@ module.exports = (env, argv) => {
5972 // layer to have our custom alternate fields to load things in the right order. These are
6073 // the defaults of webpack prepended with `matrix_src_`.
6174 mainFields : [ 'matrix_src_browser' , 'matrix_src_main' , 'browser' , 'main' ] ,
62- aliasFields : [ 'matrix_src_browser' , 'browser' ] ,
75+ aliasFields : [ 'matrix_src_browser' , 'browser' ] ,
6376
64- // We need to specify that TS can be resolved without an extension
65- extensions : [ '.js' , '.json' , '.ts' ] ,
66- alias : {
77+ // We need to specify that TS can be resolved without an extension
78+ extensions : [ '.js' , '.json' , '.ts' ] ,
79+ alias : {
6780 // alias any requires to the react module to the one in our path,
6881 // otherwise we tend to get the react source included twice when
6982 // using `npm link` / `yarn link`.
7083 "react" : path . resolve ( __dirname , 'node_modules/react' ) ,
71- "react-dom" : path . resolve ( __dirname , 'node_modules/react-dom' ) ,
84+ "react-dom" : path . resolve ( __dirname , 'node_modules/react-dom' ) ,
7285
73- // same goes for js-sdk - we don't need two copies.
74- "matrix-js-sdk" : path . resolve ( __dirname , 'node_modules/matrix-js-sdk' ) ,
86+ // same goes for js-sdk - we don't need two copies.
87+ "matrix-js-sdk" : path . resolve ( __dirname , 'node_modules/matrix-js-sdk' ) ,
7588
76- // Define a variable so the i18n stuff can load
77- "$webapp" : path . resolve ( __dirname , 'webapp' ) ,
89+ // Define a variable so the i18n stuff can load
90+ "$webapp" : path . resolve ( __dirname , 'webapp' ) ,
7891 } ,
7992 } ,
8093
@@ -99,7 +112,7 @@ module.exports = (env, argv) => {
99112 exclude : / n o d e _ m o d u l e s / ,
100113 loader : 'babel-loader' ,
101114 options : {
102- cacheDirectory : true ,
115+ cacheDirectory : true
103116 }
104117 } ,
105118 {
@@ -283,8 +296,8 @@ module.exports = (env, argv) => {
283296 } ) ,
284297 ] ,
285298
286- output : {
287- path : path . join ( __dirname , "webapp" ) ,
299+ output : {
300+ path : path . join ( __dirname , "webapp" ) ,
288301
289302 // The generated JS (and CSS, from the extraction plugin) are put in a
290303 // unique subdirectory for the build. There will only be one such
@@ -295,19 +308,14 @@ module.exports = (env, argv) => {
295308 // chunks even after the app is redeployed.
296309 filename : "bundles/[hash]/[name].js" ,
297310 chunkFilename : "bundles/[hash]/[name].js" ,
298- } ,
299-
300- // DO NOT enable this option. It makes the source maps all wonky. Instead,
301- // we end up including the sourcemaps through the loaders which makes them
302- // more accurate.
303- //devtool: "source-map",
311+ } ,
304312
305313 // configuration for the webpack-dev-server
306314 devServer : {
307315 // serve unwebpacked assets from webapp.
308316 contentBase : './webapp' ,
309317
310- stats : {
318+ stats : {
311319 // don't fill the console up with a mahoosive list of modules
312320 chunks : false ,
313321 } ,
@@ -316,7 +324,7 @@ module.exports = (env, argv) => {
316324 // so webpack-dev-server reloads the page on every update which is quite
317325 // tedious in Riot since that can take a while.
318326 hot : false ,
319- inline : false ,
327+ inline : false ,
320328 } ,
321329 } ;
322330} ;
0 commit comments