diff --git a/webpack.config.js b/webpack.config.js index 026ea956d21..79c3be801c4 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -157,6 +157,68 @@ function lorisModule(mname, entries, override=false) { }; } +let mode = 'production'; +try { + const configFile = fs.readFileSync('project/config.xml', 'latin1'); + const res = /<[\s]*?sandbox[\s]*?>(.*)<\/[\s]*?sandbox[\s]*?>/ + .exec(configFile); + if (res && parseInt(res[1]) == 1) mode = 'development'; +} catch (error) { + console.error( + 'Error - Can\'t read config.xml file. ' + + 'Webpack mode set to production.' + ); +} + +const plugins = [ + new CopyPlugin({ + patterns: [ + { + from: path.resolve(__dirname, 'node_modules/react/umd'), + to: path.resolve(__dirname, 'htdocs/vendor/js/react'), + flatten: true, + force: true, + globOptions: { + ignore: ['react.profiling.min.js'], + }, + filter: async (path) => { + const file = path.split('\\').pop().split('/').pop(); + const keep = [ + 'react.development.js', + 'react.production.min.js', + ]; + return keep.includes(file); + }, + }, + { + from: path.resolve(__dirname, 'node_modules/react-dom/umd'), + to: path.resolve(__dirname, 'htdocs/vendor/js/react'), + flatten: true, + force: true, + filter: async (path) => { + const file = path.split('\\').pop().split('/').pop(); + const keep = [ + 'react-dom.development.js', + 'react-dom.production.min.js', + ]; + return keep.includes(file); + }, + }, + ], + }), +]; + +mode == 'development' && plugins.push(new ESLintPlugin({ + files: [ + 'modules/', + 'jsx/', + 'jslib/', + 'htdocs/js/', + 'webpack.config.js', + ], + cache: true, +})); + let config = [ // Core components { @@ -227,6 +289,7 @@ let config = [ ], }), ], + plugins: plugins, optimization: optimization, resolve: resolve, module: mod,