forked from internetarchive/openlibrary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
109 lines (97 loc) · 3.47 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
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
/* eslint-env node, es6 */
// https://webpack.js.org/configuration
const
webpack = require('webpack'),
path = require('path'),
prod = process.env.NODE_ENV === 'production',
// The output directory for all build artifacts. Only absolute paths are accepted by
// output.path.
distDir = path.resolve(__dirname, 'static/build');
module.exports = {
// Apply the rule of silence: https://wikipedia.org/wiki/Unix_philosophy.
stats: {
all: false,
// Output a timestamp when a build completes. Useful when watching files.
builtAt: true,
errors: true,
warnings: true
},
// Fail on the first build error instead of tolerating it for prod builds. This seems to
// correspond to optimization.noEmitOnErrors.
bail: prod,
// Specify that all paths are relative the Webpack configuration directory not the current
// working directory.
context: __dirname,
// A map of ResourceLoader module / entry chunk names to JavaScript files to pack.
entry: {
all: './openlibrary/plugins/openlibrary/js/index.js'
},
resolve: {
alias: {}
},
plugins: [
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery'
})
],
module: {
rules: [ {
test: /\.js$/,
use: {
loader: 'babel-loader',
options: {
// Beware of https://github.com/babel/babel-loader/issues/690.
// Changes to browsers require manual invalidation.
cacheDirectory: true
}
}
}, {
test: /\.less$/,
loader: [
'style-loader',
'css-loader',
'less-loader' // compiles Less to CSS
]
} ]
},
optimization: {
splitChunks: {
cacheGroups: {
// Turn off webpack's default 'vendors' cache group. If this is desired
// later on, we can explicitly turn this on for clarity.
// https://webpack.js.org/plugins/split-chunks-plugin/#optimization-splitchunks
vendors: false,
}
},
// Don't produce production output when a build error occurs.
noEmitOnErrors: prod
},
output: {
// Specify the destination of all build products.
path: distDir,
// base path for build products when referenced from production
// (see https://webpack.js.org/guides/public-path/)
publicPath: '/static/build/',
// Store outputs per module in files named after the modules. For the JavaScript entry
// itself, append .js to each ResourceLoader module entry name.
filename: '[name].js',
// This option determines the name of **non-entry** chunk files.
chunkFilename: '[name].[contenthash].js',
// Expose the module.exports of each module entry chunk through the global
// ol (open library)
library: [ 'ol' ],
libraryTarget: 'this'
},
// 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',
mode: prod,
performance: {
maxAssetSize: 703 * 1024,
maxEntrypointSize: 703 * 1024,
// Size violations for prod builds fail; development builds are unchecked.
hints: prod ? 'error' : false
}
};