forked from internetarchive/bookreader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
61 lines (56 loc) · 1.57 KB
/
webpack.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
const path = require('path');
module.exports = buildJSFiles([
'BookReader.js',
'plugins/menu_toggle/plugin.menu_toggle.js',
'plugins/plugin.archive_analytics.js',
'plugins/plugin.autoplay.js',
'plugins/plugin.chapters.js',
'plugins/plugin.iframe.js',
'plugins/plugin.mobile_nav.js',
'plugins/plugin.print.js',
'plugins/plugin.resume.js',
'plugins/plugin.search.js',
'plugins/plugin.themes.js',
'plugins/plugin.url.js',
'plugins/plugin.vendor-fullscreen.js',
'plugins/tts/plugin.tts.js',
]);
/**
* Applies bundling to the listed files.
*/
function buildJSFiles(files) {
const nestedDirRegex = new RegExp('/(.*)/');
return files.map((filePath) => {
const flattenedFilePath = filePath.replace(nestedDirRegex, '/');
return buildJsFromTo({
from: filePath,
to: `BookReader/${flattenedFilePath}`
});
});
}
/**
* Applies webpack config to files that it is bundling.
*
* @param {Object} opts
* @param {String} opts.from
* @param {String} opts.to
*/
function buildJsFromTo({ from: srcEntryFile, to: outputFile }) {
return {
mode: 'production',
entry: './' + path.join('src/js/', srcEntryFile),
module: {
rules: [
{ test: /\.js$/, exclude: /node_modules/, loader: "babel-loader" }
]
},
output: {
filename: path.basename(outputFile),
path: path.resolve(__dirname, path.parse(outputFile).dir)
},
// Accurate source maps at the expense of build time.
// The source map is intentionally exposed
// to users via sourceMapFilename for prod debugging.
devtool: 'source-map'
};
}