forked from canonical/snapcraft.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
71 lines (66 loc) · 2.28 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
/* eslint-env node */
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
const production = process.env.ENVIRONMENT !== "devel";
// turn on uglify plugin on production
const plugins = production
? [
new UglifyJsPlugin({
sourceMap: true
})
]
: [];
module.exports = {
entry: {
"global-nav": "./static/js/base/global-nav.js",
base: "./static/js/base/base.js",
release: "./static/js/publisher/release.js",
public: "./static/js/public/public.js",
// TODO:
// publisher bundle is big (webpack warning) - try to chunk it down
// https://github.com/canonical-web-and-design/snapcraft.io/issues/1246
publisher: "./static/js/publisher/publisher.js"
},
output: {
filename: "[name].js",
path: __dirname + "/static/js/dist"
},
mode: production ? "production" : "development",
devtool: production ? "source-map" : "eval-source-map",
module: {
rules: [
{
test: /\.js$/,
// Exclude node_modules from using babel-loader
// except some that use ES6 modules and need to be transpiled:
// such as swiper http://idangero.us/swiper/get-started/
// and also react-dnd related
exclude: /node_modules\/(?!(dom7|ssr-window|swiper|dnd-core|react-dnd|react-dnd-html5-backend)\/).*/,
use: {
loader: "babel-loader"
}
},
// TODO:
// we should get rid of using globals making expose-loader unnecessary
// https://github.com/canonical-web-and-design/snapcraft.io/issues/1245
// loaders are evaluated from bottom to top (right to left)
// so first transpile via babel, then expose as global
{
test: require.resolve(__dirname + "/static/js/base/base.js"),
use: ["expose-loader?snapcraft.base", "babel-loader"]
},
{
test: require.resolve(__dirname + "/static/js/publisher/release.js"),
use: ["expose-loader?snapcraft.release", "babel-loader"]
},
{
test: require.resolve(__dirname + "/static/js/publisher/publisher.js"),
use: ["expose-loader?snapcraft.publisher", "babel-loader"]
},
{
test: require.resolve(__dirname + "/static/js/public/public.js"),
use: ["expose-loader?snapcraft.public", "babel-loader"]
}
]
},
plugins: plugins
};