11const ESLintPlugin = require ( 'eslint-webpack-plugin' ) ;
22const TerserPlugin = require ( 'terser-webpack-plugin' ) ;
33const CopyPlugin = require ( 'copy-webpack-plugin' ) ;
4- const webpack = require ( 'webpack' ) ;
54const path = require ( 'path' ) ;
65const fs = require ( 'fs' ) ;
76const cp = require ( 'child_process' ) ;
@@ -125,19 +124,6 @@ mod.rules.push(
125124 } ,
126125) ;
127126
128- let mode = 'production' ;
129- try {
130- const configFile = fs . readFileSync ( 'project/config.xml' , 'latin1' ) ;
131- const res = / < [ \s ] * ?s a n d b o x [ \s ] * ?> ( .* ) < \/ [ \s ] * ?s a n d b o x [ \s ] * ?> /
132- . exec ( configFile ) ;
133- if ( res && parseInt ( res [ 1 ] ) == 1 ) mode = 'development' ;
134- } catch ( error ) {
135- console . error (
136- 'Error - Can\'t read config.xml file. '
137- + 'Webpack mode set to production.'
138- ) ;
139- }
140-
141127/**
142128 * Creates a webpack config entry for a LORIS module named
143129 * mname.
@@ -172,24 +158,66 @@ function lorisModule(mname, entries) {
172158 'react-dom' : 'ReactDOM' ,
173159 } ,
174160 devtool : 'source-map' ,
175- plugins : [
176- new webpack . DefinePlugin ( {
177- 'process.env.NODE_ENV' : `"${ mode } "` ,
178- } ) ,
179- ...modulePlugins ,
180- ] ,
161+ plugins : modulePlugins ,
181162 optimization : optimization ,
182163 resolve : resolve ,
183164 module : mod ,
184- mode : 'none' ,
185165 stats : 'errors-only' ,
186166 } ;
187167}
188168
169+ const plugins = [
170+ new CopyPlugin ( {
171+ patterns : [
172+ {
173+ from : path . resolve ( __dirname , 'node_modules/react/umd' ) ,
174+ to : path . resolve ( __dirname , 'htdocs/vendor/js/react' ) ,
175+ force : true ,
176+ globOptions : {
177+ ignore : [ 'react.profiling.min.js' ] ,
178+ } ,
179+ filter : async ( path ) => {
180+ const file = path . split ( '\\' ) . pop ( ) . split ( '/' ) . pop ( ) ;
181+ const keep = [
182+ 'react.development.js' ,
183+ 'react.production.min.js' ,
184+ ] ;
185+ return keep . includes ( file ) ;
186+ } ,
187+ } ,
188+ {
189+ from : path . resolve ( __dirname , 'node_modules/react-dom/umd' ) ,
190+ to : path . resolve ( __dirname , 'htdocs/vendor/js/react' ) ,
191+ force : true ,
192+ filter : async ( path ) => {
193+ const file = path . split ( '\\' ) . pop ( ) . split ( '/' ) . pop ( ) ;
194+ const keep = [
195+ 'react-dom.development.js' ,
196+ 'react-dom.production.min.js' ,
197+ ] ;
198+ return keep . includes ( file ) ;
199+ } ,
200+ } ,
201+ ] ,
202+ } ) ,
203+ ] ;
204+
205+ process . env . NODE_ENV == 'development' && plugins . push ( new ESLintPlugin ( {
206+ extensions : [ 'ts' , 'tsx' , 'js' , 'jsx' ] ,
207+ files : [
208+ 'modules/' ,
209+ 'jsx/' ,
210+ 'jslib/' ,
211+ 'htdocs/js/' ,
212+ 'webpack.config.js' ,
213+ 'npm-postinstall.js' ,
214+ ] ,
215+ cache : true ,
216+ } ) ) ;
217+
189218let config = [
190219 // Core components
191220 {
192- mode : mode ,
193221 entry : {
194222 DynamicDataTable : './jsx/DynamicDataTable.js' ,
195223 PaginationLinks : './jsx/PaginationLinks.js' ,
@@ -211,53 +239,7 @@ let config = [
211239 'react-dom' : 'ReactDOM' ,
212240 } ,
213241 devtool : 'source-map' ,
214- plugins : [
215- new ESLintPlugin ( {
216- extensions : [ 'ts' , 'tsx' , 'js' , 'jsx' ] ,
217- files : [
218- 'modules/' ,
219- 'jsx/' ,
220- 'jslib/' ,
221- 'htdocs/js/' ,
222- 'webpack.config.js' ,
223- 'npm-postinstall.js' ,
224- ] ,
225- cache : true ,
226- } ) ,
227- new CopyPlugin ( {
228- patterns : [
229- {
230- from : path . resolve ( __dirname , 'node_modules/react/umd' ) ,
231- to : path . resolve ( __dirname , 'htdocs/vendor/js/react' ) ,
232- force : true ,
233- globOptions : {
234- ignore : [ 'react.profiling.min.js' ] ,
235- } ,
236- filter : async ( path ) => {
237- const file = path . split ( '\\' ) . pop ( ) . split ( '/' ) . pop ( ) ;
238- const keep = [
239- 'react.development.js' ,
240- 'react.production.min.js' ,
241- ] ;
242- return keep . includes ( file ) ;
243- } ,
244- } ,
245- {
246- from : path . resolve ( __dirname , 'node_modules/react-dom/umd' ) ,
247- to : path . resolve ( __dirname , 'htdocs/vendor/js/react' ) ,
248- force : true ,
249- filter : async ( path ) => {
250- const file = path . split ( '\\' ) . pop ( ) . split ( '/' ) . pop ( ) ;
251- const keep = [
252- 'react-dom.development.js' ,
253- 'react-dom.production.min.js' ,
254- ] ;
255- return keep . includes ( file ) ;
256- } ,
257- } ,
258- ] ,
259- } ) ,
260- ] ,
242+ plugins : plugins ,
261243 optimization : optimization ,
262244 resolve : resolve ,
263245 module : mod ,
0 commit comments