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' ) ;
@@ -134,19 +133,6 @@ mod.rules.push(
134133 } ,
135134) ;
136135
137- let mode = 'production' ;
138- try {
139- const configFile = fs . readFileSync ( 'project/config.xml' , 'latin1' ) ;
140- const res = / < [ \s ] * ?s a n d b o x [ \s ] * ?> ( .* ) < \/ [ \s ] * ?s a n d b o x [ \s ] * ?> /
141- . exec ( configFile ) ;
142- if ( res && parseInt ( res [ 1 ] ) == 1 ) mode = 'development' ;
143- } catch ( error ) {
144- console . error (
145- 'Error - Can\'t read config.xml file. '
146- + 'Webpack mode set to production.'
147- ) ;
148- }
149-
150136/**
151137 * Creates a webpack config entry for a LORIS module named
152138 * mname.
@@ -181,24 +167,66 @@ function lorisModule(mname, entries) {
181167 'react-dom' : 'ReactDOM' ,
182168 } ,
183169 devtool : 'source-map' ,
184- plugins : [
185- new webpack . DefinePlugin ( {
186- 'process.env.NODE_ENV' : `"${ mode } "` ,
187- } ) ,
188- ...modulePlugins ,
189- ] ,
170+ plugins : modulePlugins ,
190171 optimization : optimization ,
191172 resolve : resolve ,
192173 module : mod ,
193- mode : 'none' ,
194174 stats : 'errors-only' ,
195175 } ;
196176}
197177
178+ const plugins = [
179+ new CopyPlugin ( {
180+ patterns : [
181+ {
182+ from : path . resolve ( __dirname , 'node_modules/react/umd' ) ,
183+ to : path . resolve ( __dirname , 'htdocs/vendor/js/react' ) ,
184+ force : true ,
185+ globOptions : {
186+ ignore : [ 'react.profiling.min.js' ] ,
187+ } ,
188+ filter : async ( path ) => {
189+ const file = path . split ( '\\' ) . pop ( ) . split ( '/' ) . pop ( ) ;
190+ const keep = [
191+ 'react.development.js' ,
192+ 'react.production.min.js' ,
193+ ] ;
194+ return keep . includes ( file ) ;
195+ } ,
196+ } ,
197+ {
198+ from : path . resolve ( __dirname , 'node_modules/react-dom/umd' ) ,
199+ to : path . resolve ( __dirname , 'htdocs/vendor/js/react' ) ,
200+ force : true ,
201+ filter : async ( path ) => {
202+ const file = path . split ( '\\' ) . pop ( ) . split ( '/' ) . pop ( ) ;
203+ const keep = [
204+ 'react-dom.development.js' ,
205+ 'react-dom.production.min.js' ,
206+ ] ;
207+ return keep . includes ( file ) ;
208+ } ,
209+ } ,
210+ ] ,
211+ } ) ,
212+ ] ;
213+
214+ process . env . NODE_ENV == 'development' && plugins . push ( new ESLintPlugin ( {
215+ extensions : [ 'ts' , 'tsx' , 'js' , 'jsx' ] ,
216+ files : [
217+ 'modules/' ,
218+ 'jsx/' ,
219+ 'jslib/' ,
220+ 'htdocs/js/' ,
221+ 'webpack.config.js' ,
222+ 'npm-postinstall.js' ,
223+ ] ,
224+ cache : true ,
225+ } ) ) ;
226+
198227let config = [
199228 // Core components
200229 {
201- mode : mode ,
202230 entry : {
203231 DynamicDataTable : './jsx/DynamicDataTable.js' ,
204232 PaginationLinks : './jsx/PaginationLinks.js' ,
@@ -220,53 +248,7 @@ let config = [
220248 'react-dom' : 'ReactDOM' ,
221249 } ,
222250 devtool : 'source-map' ,
223- plugins : [
224- new ESLintPlugin ( {
225- extensions : [ 'ts' , 'tsx' , 'js' , 'jsx' ] ,
226- files : [
227- 'modules/' ,
228- 'jsx/' ,
229- 'jslib/' ,
230- 'htdocs/js/' ,
231- 'webpack.config.js' ,
232- 'npm-postinstall.js' ,
233- ] ,
234- cache : true ,
235- } ) ,
236- new CopyPlugin ( {
237- patterns : [
238- {
239- from : path . resolve ( __dirname , 'node_modules/react/umd' ) ,
240- to : path . resolve ( __dirname , 'htdocs/vendor/js/react' ) ,
241- force : true ,
242- globOptions : {
243- ignore : [ 'react.profiling.min.js' ] ,
244- } ,
245- filter : async ( path ) => {
246- const file = path . split ( '\\' ) . pop ( ) . split ( '/' ) . pop ( ) ;
247- const keep = [
248- 'react.development.js' ,
249- 'react.production.min.js' ,
250- ] ;
251- return keep . includes ( file ) ;
252- } ,
253- } ,
254- {
255- from : path . resolve ( __dirname , 'node_modules/react-dom/umd' ) ,
256- to : path . resolve ( __dirname , 'htdocs/vendor/js/react' ) ,
257- force : true ,
258- filter : async ( path ) => {
259- const file = path . split ( '\\' ) . pop ( ) . split ( '/' ) . pop ( ) ;
260- const keep = [
261- 'react-dom.development.js' ,
262- 'react-dom.production.min.js' ,
263- ] ;
264- return keep . includes ( file ) ;
265- } ,
266- } ,
267- ] ,
268- } ) ,
269- ] ,
251+ plugins : plugins ,
270252 optimization : optimization ,
271253 resolve : resolve ,
272254 module : mod ,
0 commit comments