Repository navigation
Expand file tree
/
Copy pathwebpack.config.js
More file actions
executable file
·277 lines (245 loc) · 9.64 KB
/
Copy pathwebpack.config.js
File metadata and controls
executable file
·277 lines (245 loc) · 9.64 KB
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
const Encore = require("@symfony/webpack-encore")
const dotenv = require("dotenv")
const webpack = require("webpack")
const fs = require("fs")
const path = require("path")
const env = dotenv.config({ quiet: true })
if (!Encore.isRuntimeEnvironmentConfigured()) {
Encore.configureRuntimeEnvironment(process.env.NODE_ENV || "dev")
}
const isProd = Encore.isProduction()
Encore.setOutputPath("public/build/")
.setManifestKeyPrefix("public/build/")
.setPublicPath("/build")
// Desktop build notifications are optional. Keep them disabled by default
// because webpack-notifier pulls node-notifier, which is not compatible with
// the ESM-only uuid package on newer Node.js versions and breaks the build.
if (process.env.CHAMILO_WEBPACK_NOTIFICATIONS === "1") {
Encore.enableBuildNotifications()
}
// Clean output only in production to speed up development builds.
if (isProd) {
Encore.cleanupOutputBeforeBuild()
}
Encore.addEntry("legacy_app", "./assets/js/legacy/app.js")
.addEntry("legacy_exercise", "./assets/js/legacy/exercise.js")
.addEntry("legacy_free-jqgrid", "./assets/js/legacy/free-jqgrid.js")
.addEntry("legacy_lp", "./assets/js/legacy/lp.js")
.addEntry("legacy_document", "./assets/js/legacy/document.js")
.addEntry("legacy_framereadyloader", "./assets/js/legacy/frameReadyLoader.js")
.addEntry("vue", "./assets/vue/main.js")
.addEntry("vue_installer", "./assets/vue/main_installer.js")
.addEntry("translatehtml", "./assets/js/translatehtml.js")
.addEntry("glossary_auto", "./assets/js/glossary-auto.js")
.addEntry("mathjax_render", "./assets/js/mathjax-render.js")
.addStyleEntry("app", "./assets/css/app.scss")
.addStyleEntry("css/chat", "./assets/css/chat.scss")
.addStyleEntry("css/document", "./assets/css/document.scss")
.addStyleEntry("css/editor", "./assets/css/editor.scss")
.addStyleEntry("css/editor_content", "./assets/css/editor_content.scss")
.addStyleEntry("css/markdown", "./assets/css/markdown.scss")
.addStyleEntry("css/print", "./assets/css/print.scss")
.addStyleEntry("css/responsive", "./assets/css/responsive.scss")
.addStyleEntry("css/scorm", "./assets/css/scorm.scss")
.enableSingleRuntimeChunk()
.enableSourceMaps(!isProd)
// Enable @babel/preset-env polyfills.
.configureBabel(() => {})
.configureBabelPresetEnv((config) => {
config.useBuiltIns = "usage"
config.corejs = 3
})
.enableSassLoader()
.enableTypeScriptLoader(function (tsConfig) {
tsConfig.transpileOnly = true
})
.enableVueLoader(() => {}, { version: 3, runtimeCompilerBuild: false })
.autoProvidejQuery()
.enablePostCssLoader((options) => {
options.postcssOptions = {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
}
})
.copyFiles([
{
from: "./node_modules/multiselect-two-sides/dist/js",
pattern: /(multiselect.js)$/,
to: "libs/multiselect-two-sides/dist/js/multiselect.js",
},
{
from: "./node_modules/pwstrength-bootstrap/dist/",
pattern: /(pwstrength-bootstrap.js)$/,
to: "libs/pwstrength-bootstrap/dist/pwstrength-bootstrap.js",
},
{
from: "./node_modules/readmore-js",
pattern: /(readmore.js)$/,
to: "libs/readmore-js/readmore.js",
},
{
from: "./node_modules/js-cookie/src/",
pattern: /(js.cookie.js)$/,
to: "libs/js-cookie/src/js.cookie.js",
},
{
from: "./node_modules/qtip2/dist/basic",
pattern: /(jquery.qtip.js)$/,
to: "libs/qtip2/dist/jquery.qtip.js",
},
{
from: "./node_modules/qtip2/dist/basic",
pattern: /(jquery.qtip.css)$/,
to: "libs/qtip2/dist/jquery.qtip.css",
},
{
from: "./node_modules/flatpickr/dist",
pattern: /flatpickr\.min\.(css|js)$/,
to: "flatpickr/[name].[ext]",
},
{
from: "./node_modules/flatpickr/dist/l10n",
to: "flatpickr/l10n/[name].[ext]",
},
{
from: "./node_modules/chart.js/dist/",
to: "libs/chartjs/[name].[ext]",
pattern: /\.(js|css)$/,
},
])
.addPlugin(
new webpack.DefinePlugin({
ENV_CUSTOM_VUE_TEMPLATE: JSON.stringify(env.parsed?.APP_CUSTOM_VUE_TEMPLATE),
}),
)
.configureDevServerOptions((options) => {
options.host = "0.0.0.0"
})
// Enable production-only hashing features.
// This keeps dev builds faster and avoids unnecessary hashed asset handling while developing.
if (isProd) {
Encore.enableIntegrityHashes()
Encore.enableVersioning()
}
Encore.copyFiles({
from: "./node_modules/mediaelement/build",
to: "libs/mediaelement/[path][name].[ext]",
})
Encore.copyFiles({
from: "./node_modules/mediaelement-plugins/dist",
to: "libs/mediaelement/plugins/[path][name].[ext]",
})
// MathJax: only the SVG output bundle is served, plus its font package.
// MathJax 4 ships fonts separately and falls back to cdn.jsdelivr.net, so the
// font has to be copied too and pointed at from assets/js/mathjax-render.js.
// includeSubdirectories is off on the two single-file rules to keep
// require.context from walking the whole 50MB font package.
Encore.copyFiles({
from: "./node_modules/mathjax",
pattern: /tex-svg\.js$/,
to: "libs/mathjax/[name].[ext]",
includeSubdirectories: false,
})
// Speech Rule Engine worker: MathJax spawns it on every typeset to build the
// accessible description of a formula, and resolves it against its own
// directory. Without this the browser logs a failed importScripts on each run.
Encore.copyFiles({
from: "./node_modules/mathjax/sre",
pattern: /\.(js|json)$/,
to: "libs/mathjax/sre/[path][name].[ext]",
})
Encore.copyFiles({
from: "./node_modules/@mathjax/mathjax-newcm-font",
pattern: /svg\.js$/,
to: "libs/mathjax-fonts/mathjax-newcm-font/[name].[ext]",
includeSubdirectories: false,
})
Encore.copyFiles({
from: "./node_modules/@mathjax/mathjax-newcm-font/svg",
pattern: /\.js$/,
to: "libs/mathjax-fonts/mathjax-newcm-font/svg/[path][name].[ext]",
})
Encore.copyFiles({
from: "node_modules/moment/locale",
to: "libs/locale/[path][name].[ext]",
})
Encore.copyFiles({
from: "./node_modules/select2/dist/css",
to: "libs/select2/css/[name].[ext]",
})
Encore.copyFiles({
from: "./node_modules/select2/dist/js",
to: "libs/select2/js/[name].[ext]",
})
class CopyUnhashedAssetsPlugin {
apply(compiler) {
compiler.hooks.afterEmit.tap("CopyUnhashedAssetsPlugin", () => {
// Only production builds emit content hashes. Development builds already write
// the unhashed filenames, so copying a hashed file left over by an earlier
// production build would silently overwrite them with stale content.
if (!isProd) {
return
}
const buildPath = path.resolve(__dirname, "public/build")
const cssPath = path.join(buildPath, "css")
const qtipDistPath = path.join(buildPath, "libs/qtip2/dist")
if (!fs.existsSync(buildPath)) {
return
}
// Read each directory once and reuse the listing for every lookup below,
// instead of re-scanning the (large) build directory on every match.
const buildFiles = fs.readdirSync(buildPath)
// Copy the first file matching `pattern` in `dir` to `target`, dropping the content hash.
const copyUnhashed = (dir, files, pattern, target) => {
const match = files.find((f) => f.match(pattern))
if (match) {
fs.copyFileSync(path.join(dir, match), path.join(dir, target))
}
}
// Copy legacy_document.js without hash.
copyUnhashed(buildPath, buildFiles, /^legacy_document\.[a-f0-9]+\.js$/, "legacy_document.js")
// Copy legacy_exercise.js without hash.
copyUnhashed(buildPath, buildFiles, /^legacy_exercise\.[a-f0-9]+\.js$/, "legacy_exercise.js")
// Do not copy runtime.js without hash.
// A non-versioned runtime file can be cached and become desynchronized
// from hashed chunks, causing ChunkLoadError ("missing") at runtime.
// Copy document.css and editor_content.css without hash.
if (fs.existsSync(cssPath)) {
const cssFiles = fs.readdirSync(cssPath)
copyUnhashed(cssPath, cssFiles, /^document\.[a-f0-9]+\.css$/, "document.css")
copyUnhashed(cssPath, cssFiles, /^editor_content\.[a-f0-9]+\.css$/, "editor_content.css")
}
// Copy legacy_framereadyloader.js and .css without hash.
copyUnhashed(buildPath, buildFiles, /^legacy_framereadyloader\.[a-f0-9]+\.js$/, "legacy_framereadyloader.js")
copyUnhashed(buildPath, buildFiles, /^legacy_framereadyloader\.[a-f0-9]+\.css$/, "legacy_framereadyloader.css")
// Keep unhashed qTip assets for legacy direct references.
if (fs.existsSync(qtipDistPath)) {
const qtipFiles = fs.readdirSync(qtipDistPath)
copyUnhashed(qtipDistPath, qtipFiles, /^jquery\.qtip\.js$/, "jquery.qtip.js")
copyUnhashed(qtipDistPath, qtipFiles, /^jquery\.qtip\.css$/, "jquery.qtip.css")
}
// Copy glossary_auto.js without hash.
copyUnhashed(buildPath, buildFiles, /^glossary_auto\.[a-f0-9]+\.js$/, "glossary_auto.js")
})
}
}
Encore.addPlugin(new CopyUnhashedAssetsPlugin())
const config = Encore.getWebpackConfig()
// Use explicit runtime/chunk global names to reduce collisions
// when multiple bundles are loaded on the same page.
config.output = config.output || {}
config.output.uniqueName = "chamilo"
config.output.chunkLoadingGlobal = "webpackChunkChamilo"
// Enable persistent filesystem cache to speed up rebuilds.
config.cache = {
type: "filesystem",
}
// Use a lightweight source map in development to lower the build's memory peak.
// The default ("inline-source-map") inlines full per-module maps and is the main
// driver of "JavaScript heap out of memory" failures on smaller servers.
if (!isProd) {
config.devtool = "eval-cheap-module-source-map"
}
module.exports = config