From 566f6284690b094891bad2b0a8b69e40a8802ca1 Mon Sep 17 00:00:00 2001 From: Laetitia Fesselier Date: Fri, 11 Nov 2022 13:33:00 -0500 Subject: [PATCH] [ESLint] Disable on prod instances --- webpack.config.js | 63 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) 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,