-
Notifications
You must be signed in to change notification settings - Fork 3.9k
/
webpack.common.config.js
695 lines (670 loc) · 27.3 KB
/
webpack.common.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
/* eslint-env node */
'use strict';
var path = require('path');
var webpack = require('webpack');
var BundleTracker = require('webpack-bundle-tracker');
var Merge = require('webpack-merge');
var files = require('./webpack-config/file-lists.js');
var builtinBlocksJS = require('./webpack.builtinblocks.config.js');
var filesWithRequireJSBlocks = [
path.resolve(__dirname, 'common/static/common/js/components/utils/view_utils.js'),
/xmodule\/js\/src/
];
var defineHeader = /\(function ?\(((define|require|requirejs|\$)(, )?)+\) ?\{/;
var defineCallFooter = /\}\)\.call\(this, ((define|require)( \|\| RequireJS\.(define|require))?(, )?)+?\);/;
var defineDirectFooter = /\}\(((window\.)?(RequireJS\.)?(requirejs|define|require|jQuery)(, )?)+\)\);/;
var defineFancyFooter = /\}\).call\(\s*this(\s|.)*define(\s|.)*\);/;
var defineFooter = new RegExp('(' + defineCallFooter.source + ')|('
+ defineDirectFooter.source + ')|('
+ defineFancyFooter.source + ')', 'm');
var staticRootLms = process.env.STATIC_ROOT_LMS || './test_root/staticfiles';
var staticRootCms = process.env.STATIC_ROOT_CMS || (staticRootLms + '/studio');
class DieHardPlugin {
/* A small plugin which ensures that if Webpack fails, it causes the surrounding process to fail
* as well. This helps us prevent JavaScript CI from "false passing" upon build failures--that is,
* we want to avoid having another situation where the Webpack build breaks under Karma (our
* test runner) but Karma just lets it slide and moves on to the next test suite.
*
* One would imagine that this would be Webpack's default behavior (and maybe it is?) but,
* regardless, karma-webpack does not seem to consider Webpack build failures to be fatal errors
* without this plugin. We don't fully understand it, but this is good enough given that we plan
* to remove all JS in this repo soon (https://github.com/openedx/edx-platform/issues/31620).
*
* Inpsired by: https://github.com/codymikol/karma-webpack/issues/49#issuecomment-842682050
*/
apply(compiler) {
compiler.hooks.failed.tap('DieHardPlugin', (error) => {
console.error(error);
process.exit(1);
});
}
}
var workerConfig = function() {
try {
return {
webworker: {
target: 'webworker',
context: __dirname,
// eslint-disable-next-line global-require
entry: require('../workers.json'),
output: {
publicPath: "", // https://stackoverflow.com/a/65272040
filename: '[name].js',
path: path.resolve(__dirname, 'common/static/bundles')
},
plugins: [
new BundleTracker({
path: staticRootLms,
filename: 'webpack-worker-stats.json'
}),
new webpack.DefinePlugin({
'process.env.JS_ENV_EXTRA_CONFIG': JSON.parse(process.env.JS_ENV_EXTRA_CONFIG),
})
],
module: {
rules: [
{
test: /\.(js|jsx)$/,
include: [
/node_modules\//
],
use: 'babel-loader'
}
]
},
resolve: {
extensions: ['.js']
}
}
};
} catch (err) {
return null;
}
};
module.exports = Merge.smart({
web: {
context: __dirname,
entry: {
// Studio
Import: './cms/static/js/features/import/factories/import.js',
CourseOrLibraryListing: './cms/static/js/features_jsx/studio/CourseOrLibraryListing.jsx',
'js/factories/textbooks': './cms/static/js/factories/textbooks.js',
'js/factories/container': './cms/static/js/factories/container.js',
'js/factories/context_course': './cms/static/js/factories/context_course.js',
'js/factories/library': './cms/static/js/factories/library.js',
'js/factories/xblock_validation': './cms/static/js/factories/xblock_validation.js',
'js/factories/edit_tabs': './cms/static/js/factories/edit_tabs.js',
'js/sock': './cms/static/js/sock.js',
'js/factories/tag_count': './cms/static/js/factories/tag_count.js',
// LMS
SingleSupportForm: './lms/static/support/jsx/single_support_form.jsx',
AlertStatusBar: './lms/static/js/accessible_components/StatusBarAlert.jsx',
EntitlementSupportPage: './lms/djangoapps/support/static/support/jsx/entitlements/index.jsx',
LinkProgramEnrollmentsSupportPage: './lms/djangoapps/support/static/support/jsx/'
+ 'program_enrollments/index.jsx',
ProgramEnrollmentsInspectorPage: './lms/djangoapps/support/static/support/jsx/'
+ 'program_enrollments/inspector.jsx',
PasswordResetConfirmation: './lms/static/js/student_account/components/PasswordResetConfirmation.jsx',
StudentAccountDeletion: './lms/static/js/student_account/components/StudentAccountDeletion.jsx',
StudentAccountDeletionInitializer: './lms/static/js/student_account/StudentAccountDeletionInitializer.js',
ProblemBrowser: './lms/djangoapps/instructor/static/instructor/ProblemBrowser/index.jsx',
EnterpriseLearnerPortalModal: './lms/static/js/learner_dashboard/EnterpriseLearnerPortalModal.jsx',
// Learner Dashboard
EntitlementFactory: './lms/static/js/learner_dashboard/course_entitlement_factory.js',
EntitlementUnenrollmentFactory: './lms/static/js/learner_dashboard/entitlement_unenrollment_factory.js',
ProgramDetailsFactory: './lms/static/js/learner_dashboard/program_details_factory.js',
ProgramListFactory: './lms/static/js/learner_dashboard/program_list_factory.js',
UnenrollmentFactory: './lms/static/js/learner_dashboard/unenrollment_factory.js',
CompletionOnViewService: './lms/static/completion/js/CompletionOnViewService.js',
// Features
CourseSock: './openedx/features/course_experience/static/course_experience/js/CourseSock.js',
Currency: './openedx/features/course_experience/static/course_experience/js/currency.js',
CookiePolicyBanner: './common/static/js/src/CookiePolicyBanner.jsx',
// Common
ReactRenderer: './common/static/js/src/ReactRenderer.jsx',
XModuleShim: './xmodule/js/src/xmodule.js',
VerticalStudentView: './xmodule/assets/vertical/public/js/vertical_student_view.js',
commons: 'babel-polyfill'
},
output: {
publicPath: "", // https://stackoverflow.com/a/65272040
path: path.resolve(__dirname, 'common/static/bundles'),
library: {
type: 'window'
}
},
plugins: [
new webpack.ProgressPlugin(), // report progress during compilation
new webpack.NoEmitOnErrorsPlugin(),
new BundleTracker({
path: staticRootCms,
filename: 'webpack-stats.json'
}),
new BundleTracker({
path: staticRootLms,
filename: 'webpack-stats.json'
}),
new webpack.ProvidePlugin({
_: 'underscore',
$: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery',
Popper: 'popper.js', // used by bootstrap
CodeMirror: 'codemirror',
'edx.HtmlUtils': 'edx-ui-toolkit/js/utils/html-utils',
AjaxPrefix: 'ajax_prefix',
// This is used by some XModules/XBlocks, which don't have
// any other way to declare that dependency.
$script: 'scriptjs'
}),
new DieHardPlugin(),
],
module: {
noParse: [
// See sinon/webpack interaction weirdness:
// https://github.com/webpack/webpack/issues/304#issuecomment-272150177
// (I've tried every other suggestion solution on that page, this
// was the only one that worked.)
/\/sinon\.js|codemirror-compressed\.js|hls\.js|tinymce.js/
],
rules: [
{
test: files.namespacedRequire.concat(files.textBangUnderscore, filesWithRequireJSBlocks),
loader: 'string-replace-loader',
options: {
multiple: [
{ search: defineHeader, replace: '' },
{ search: defineFooter, replace: '' },
{
search: /(\/\* RequireJS) \*\//g,
replace(match, p1, offset, string) {
return p1;
}
},
{
search: /\/\* Webpack/g,
replace(match, p1, offset, string) {
return match + ' */';
}
},
{
search: /text!(.*?\.underscore)/g,
replace(match, p1, offset, string) {
return p1;
}
},
{ search: /RequireJS.require/g, replace: 'require' }
]
}
},
{
test: /\.(js|jsx)$/,
exclude: [
/node_modules/,
files.namespacedRequire,
files.textBangUnderscore,
filesWithRequireJSBlocks
],
use: 'babel-loader'
},
{
test: /\.(js|jsx)$/,
include: [
/paragon/
],
use: 'babel-loader'
},
{
test: path.resolve(__dirname, 'common/static/js/src/ajax_prefix.js'),
use: [
'babel-loader',
{
loader: 'exports-loader',
options: {
'this.AjaxPrefix': true
}
}
]
},
{
test: /\.underscore$/,
use: 'raw-loader'
},
{
test: /\.(woff2?|ttf|eot)(\?v=\d+\.\d+\.\d+)?$/,
loader: 'file-loader'
},
{
test: /\.svg$/,
loader: 'svg-inline-loader'
},
{
test: /xblock\/core/,
use: [
{
loader: 'exports-loader',
options: 'window.XBlock'
},
{
loader: 'imports-loader',
options: 'jquery,jquery.immediateDescendents,this=>window'
}
]
},
{
test: /xblock\/runtime.v1/,
use: [
{
loader: 'exports-loader',
options: 'window.XBlock'
},
{
loader: 'imports-loader',
options: 'XBlock=xblock/core,this=>window'
}
]
},
/** *****************************************************************************************************
/* BUILT-IN XBLOCK ASSETS WITH GLOBAL DEFINITIONS:
*
* The monstrous list of globally-namespace modules below is the result of a JS build refactoring.
* Originally, all of these modules were copied to common/static/xmodule/js/[module|descriptors]/, and
* this file simply contained the lines:
*
* {
* test: /descriptors\/js/,
* loader: 'imports-loader?this=>window'
* },
* {
* test: /modules\/js/,
* loader: 'imports-loader?this=>window'
* },
*
* We removed that asset copying because it added complexity to the build, but as a result, in order to
* preserve exact parity with the preexisting global namespace, we had to enumerate all formely-copied
* modules here. It is very likely that many of these modules do not need to be in this list. Future
* refactorings are welcome to try to prune the list down to the minimal set of modules. As far as
* we know, the only modules that absolutely need to be added to the global namespace are those
* which define module types, for example "Problem" (in xmodule/js/src/capa/display.js).
*/
{
test: /xmodule\/assets\/word_cloud\/src\/js\/word_cloud.js/,
use: [
{
loader: 'imports-loader',
options: 'this=>window'
}
]
},
{
test: /xmodule\/js\/common_static\/js\/vendor\/draggabilly.js/,
use: [
{
loader: 'imports-loader',
options: 'this=>window'
}
]
},
{
test: /xmodule\/js\/src\/annotatable\/display.js/,
use: [
{
loader: 'imports-loader',
options: 'this=>window'
}
]
},
{
test: /xmodule\/js\/src\/capa\/display.js/,
use: [
{
loader: 'imports-loader',
options: 'this=>window'
}
]
},
{
test: /xmodule\/js\/src\/capa\/imageinput.js/,
use: [
{
loader: 'imports-loader',
options: 'this=>window'
}
]
},
{
test: /xmodule\/js\/src\/capa\/schematic.js/,
use: [
{
loader: 'imports-loader',
options: 'this=>window'
}
]
},
{
test: /xmodule\/js\/src\/collapsible.js/,
use: [
{
loader: 'imports-loader',
options: 'this=>window'
}
]
},
{
test: /xmodule\/js\/src\/conditional\/display.js/,
use: [
{
loader: 'imports-loader',
options: 'this=>window'
}
]
},
{
test: /xmodule\/js\/src\/html\/display.js/,
use: [
{
loader: 'imports-loader',
options: 'this=>window'
}
]
},
{
test: /xmodule\/js\/src\/html\/edit.js/,
use: [
{
loader: 'imports-loader',
options: 'this=>window'
}
]
},
{
test: /xmodule\/js\/src\/html\/imageModal.js/,
use: [
{
loader: 'imports-loader',
options: 'this=>window'
}
]
},
{
test: /xmodule\/js\/src\/javascript_loader.js/,
use: [
{
loader: 'imports-loader',
options: 'this=>window'
}
]
},
{
test: /xmodule\/js\/src\/lti\/lti.js/,
use: [
{
loader: 'imports-loader',
options: 'this=>window'
}
]
},
{
test: /xmodule\/js\/src\/poll\/poll.js/,
use: [
{
loader: 'imports-loader',
options: 'this=>window'
}
]
},
{
test: /xmodule\/js\/src\/poll\/poll_main.js/,
use: [
{
loader: 'imports-loader',
options: 'this=>window'
}
]
},
{
test: /xmodule\/js\/src\/problem\/edit.js/,
use: [
{
loader: 'imports-loader',
options: 'this=>window'
}
]
},
{
test: /xmodule\/js\/src\/raw\/edit\/metadata-only.js/,
use: [
{
loader: 'imports-loader',
options: 'this=>window'
}
]
},
{
test: /xmodule\/js\/src\/raw\/edit\/xml.js/,
use: [
{
loader: 'imports-loader',
options: 'this=>window'
}
]
},
{
test: /xmodule\/js\/src\/sequence\/display.js/,
use: [
{
loader: 'imports-loader',
options: 'this=>window'
}
]
},
{
test: /xmodule\/js\/src\/sequence\/edit.js/,
use: [
{
loader: 'imports-loader',
options: 'this=>window'
}
]
},
{
test: /xmodule\/js\/src\/tabs\/tabs-aggregator.js/,
use: [
{
loader: 'imports-loader',
options: 'this=>window'
}
]
},
{
test: /xmodule\/js\/src\/vertical\/edit.js/,
use: [
{
loader: 'imports-loader',
options: 'this=>window'
}
]
},
{
test: /xmodule\/js\/src\/video\/10_main.js/,
use: [
{
loader: 'imports-loader',
options: 'this=>window'
}
]
},
/*
* END BUILT-IN XBLOCK ASSETS WITH GLOBAL DEFINITIONS
***************************************************************************************************** */
{
test: /codemirror/,
use: [
{
loader: 'exports-loader',
options: 'window.CodeMirror'
}
]
},
{
test: /tinymce/,
use: [
{
loader: 'imports-loader',
options: 'this=>window'
}
]
},
{
test: /xmodule\/js\/src\/xmodule/,
use: [
{
loader: 'exports-loader',
options: 'window.XModule'
},
{
loader: 'imports-loader',
options: 'this=>window'
}
],
},
{
test: /mock-ajax/,
use: [
{
loader: 'imports-loader',
options: 'exports=>false'
}
]
},
{
test: /d3.min/,
use: [
'babel-loader',
{
loader: 'exports-loader',
options: {
d3: true
}
}
]
},
{
test: /logger/,
use: [
{
loader: 'imports-loader',
options: 'this=>window'
}
]
},
// spec files that use import
{
test: /lms\/static\/completion\/js\/spec\/ViewedEvent_spec.js/,
use: [
{
loader: 'imports-loader',
options: 'this=>window'
}
]
},
{
test: /\.js$/,
include: [
"/lms/static/js/learner_dashboard/spec/"
],
use: [
{
loader: 'imports-loader',
options: 'this=>window'
}
]
},
// end spec files that use import
]
},
resolve: {
extensions: ['.js', '.jsx', '.json'],
alias: {
AjaxPrefix: 'ajax_prefix',
accessibility: 'accessibility_tools',
codemirror: 'codemirror-compressed',
datepair: 'timepicker/datepair',
'edx-ui-toolkit': 'edx-ui-toolkit/src/', // @TODO: some paths in toolkit are not valid relative paths
ieshim: 'ie_shim',
jquery: 'jquery/src/jquery', // Use the non-diqst form of jQuery for better debugging + optimization
'jquery.flot': 'flot/jquery.flot.min',
'jquery.ui': 'jquery-ui.min',
'jquery.tinymce': 'jquery.tinymce.min',
'jquery.inputnumber': 'html5-input-polyfills/number-polyfill',
'jquery.qtip': 'jquery.qtip.min',
'jquery.smoothScroll': 'jquery.smooth-scroll.min',
'jquery.timepicker': 'timepicker/jquery.timepicker',
'backbone.associations': 'backbone-associations/backbone-associations-min',
squire: 'Squire',
tinymce: 'tinymce',
// See sinon/webpack interaction weirdness:
// https://github.com/webpack/webpack/issues/304#issuecomment-272150177
// (I've tried every other suggestion solution on that page, this
// was the only one that worked.)
// eslint-disable-next-line no-path-concat
sinon: __dirname + '/node_modules/sinon/pkg/sinon.js',
hls: 'hls.js/dist/hls.js'
},
modules: [
'cms/djangoapps/pipeline_js/js',
'cms/static',
'cms/static/cms/js',
'cms/templates/js',
'lms/static',
path.resolve(__dirname),
'xmodule/js/src',
'xmodule/assets/word_cloud/src/js',
'common/static',
'common/static/coffee/src',
'common/static/common/js',
'common/static/common/js/vendor/',
'common/static/common/js/components',
'common/static/js/src',
'common/static/js/vendor/',
'common/static/js/vendor/jQuery-File-Upload/js/',
'common/static/js/vendor/tinymce/js/tinymce',
'node_modules',
'common/static/xmodule'
],
// We used to have node: { fs: 'empty' } in this file,
// that is no longer supported. Adding this based on the recommendation in
// https://stackoverflow.com/questions/64361940/webpack-error-configuration-node-has-an-unknown-property-fs
//
// With this uncommented tests fail
// Tests failed in the following suites:
// * lms javascript
// * xmodule-webpack javascript
// Error: define cannot be used indirect
//
// fallback: {
// fs: false
// }
},
resolveLoader: {
alias: {
text: 'raw-loader' // Compatibility with RequireJSText's text! loader, uses raw-loader under the hood
}
},
externals: {
$: 'jQuery',
backbone: 'Backbone',
canvas: 'canvas',
gettext: 'gettext',
jquery: 'jQuery',
logger: 'Logger',
underscore: '_',
URI: 'URI',
XBlockToXModuleShim: 'XBlockToXModuleShim',
XModule: 'XModule'
},
watchOptions: {
poll: true
},
}
}, {web: builtinBlocksJS}, workerConfig());