This repository was archived by the owner on Oct 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathwebpack.config.js
More file actions
162 lines (153 loc) · 4.16 KB
/
webpack.config.js
File metadata and controls
162 lines (153 loc) · 4.16 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
const path = require("path");
const webpack = require("webpack");
const babel = require("./config/babel");
const env = process.env.NODE_ENV || "development";
const useCordova = (process.env.USE_CORDOVA || "false") === "true";
const isProd = env === "production";
const hotReload = process.env.LIVERELOAD === "true" && !isProd;
const out = path.resolve(__dirname, "dist");
const exclusions = /node_modules/;
process.stderr.write(`Building with env = ${env}\n`);
// plugin management
const HTML = require("html-webpack-plugin");
const Clean = require("clean-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const SpriteLoaderPlugin = require("svg-sprite-loader/plugin");
const plugins = [
...require("maji/lib/webpack").plugins,
new HTML({
template: "src/index.html",
useCordova,
inject: true,
minify: isProd
}),
new Clean(["dist"], { verbose: false, exclude: [".keep"] }),
new MiniCssExtractPlugin({
filename: "[name].[contenthash].css",
chunkFilename: "[id].[contenthash].css"
}),
new SpriteLoaderPlugin()
];
const optimization = {
splitChunks: isProd && { chunks: "all" },
minimize: isProd,
// prints more readable module names in the browser console on HMR updates, in dev
namedModules: !isProd,
// prevent emitting assets with errors, in dev
noEmitOnErrors: !isProd
};
if (!isProd && hotReload) {
plugins.push(
// enable HMR globally
new webpack.HotModuleReplacementPlugin()
);
}
// end of plugin management
// optionally live-reloadable entry points
const entryPoints = function() {
const items = hotReload
? ["webpack-hot-middleware/client?noInfo=true&reload=true"]
: [];
items.push(...arguments);
return items;
};
const postcssLoader = {
loader: "postcss-loader",
options: {
plugins: () => [require("autoprefixer")]
}
};
/**
* All of Maji's peerDependencies will be aliased to the versions
* in this app's node_modules folder. This prevents building with
* multiple versions of the same dependency.
*
* See: https://medium.com/@penx/managing-dependencies-in-a-node-package-so-that-they-are-compatible-with-npm-link-61befa5aaca7
*/
const majiAliases = (function() {
const dependencies = require("maji/package.json").peerDependencies || {};
return Object.keys(dependencies).reduce((aliases, packageName) => {
aliases[packageName] = path.resolve(
__dirname,
`./node_modules/${packageName}`
);
return aliases;
}, {});
})();
module.exports = {
mode: isProd ? "production" : "development",
entry: {
app: entryPoints("./src/index.js")
},
output: {
path: out,
filename: "[name].[hash].js",
publicPath: "./"
},
module: {
rules: [
{
test: /.*/,
include: path.resolve(__dirname, "src/assets"),
exclude: path.resolve(__dirname, "src/assets/icons"),
options: {
name: "[name]-[hash].[ext]"
},
loader: "file-loader"
},
{
test: /\.jsx?$/,
exclude: exclusions,
loader: "babel-loader",
options: babel
},
{ test: /\.yml$/, loader: "json-loader!yaml-loader" },
{
test: /\.scss$/,
use: [
isProd ? MiniCssExtractPlugin.loader : "style-loader",
{
loader: "css-loader",
options: {
modules: true,
localIdentName: "[path][name]__[local]--[hash:base64:5]"
}
},
postcssLoader,
"sass-loader"
],
exclude: /shell.scss$/
},
{
test: /shell.scss$/,
use: [
isProd ? MiniCssExtractPlugin.loader : "style-loader",
"css-loader",
postcssLoader,
"sass-loader"
]
},
{
test: /\.svg$/,
include: path.resolve(__dirname, "src/assets/icons"),
loader: "svg-sprite-loader",
options: {
extract: true
}
}
]
},
resolve: {
alias: Object.assign(
{
src: path.resolve(__dirname, "./src"),
config: path.resolve(__dirname, "./config")
},
majiAliases
),
symlinks: false
},
devtool: isProd ? "source-map" : "eval",
plugins,
optimization
};