-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
161 lines (151 loc) · 4.18 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
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
const path = require("path");
const webpack = require("webpack");
const babel = require("./config/babel");
const uglify = require("./config/uglify");
const env = process.env.NODE_ENV || "development";
const isProd = env === "production";
const out = path.resolve(__dirname, "dist");
const exclusions = /node_modules/;
const ExtractText = require("extract-text-webpack-plugin");
const extractShellCss = new ExtractText("shell.[hash].css");
const extractOtherCss = new ExtractText("styles.[hash].css");
process.stderr.write(`Building with env = ${env}\n`);
const getGitRevision = function() {
const GitRevPlugin = require("git-revision-webpack-plugin");
return new GitRevPlugin({
commithashCommand: "rev-parse --short HEAD 2> /dev/null || echo untracked"
}).commithash();
};
const getNpmVersion = function() {
return require("./package.json").version;
};
// plugin management
const HTML = require("html-webpack-plugin");
const Clean = require("clean-webpack-plugin");
const SpriteLoaderPlugin = require("svg-sprite-loader/plugin");
const plugins = [
new HTML({
template: "src/index.html",
inject: false,
minify: false
}),
new Clean(["dist"]),
new webpack.optimize.CommonsChunkPlugin({
name: "vendor"
}),
new webpack.DefinePlugin({
"process.env.NODE_ENV": JSON.stringify(env),
__BUILD_IDENTIFIER__: JSON.stringify(getGitRevision()),
__VERSION_NUMBER__: JSON.stringify(getNpmVersion())
}),
extractShellCss,
extractOtherCss,
new SpriteLoaderPlugin()
];
if (isProd) {
plugins.push(
new webpack.LoaderOptionsPlugin({ minimize: true, debug: false }),
new webpack.optimize.UglifyJsPlugin(uglify)
);
} else {
plugins.push(
// enable HMR globally
new webpack.HotModuleReplacementPlugin(),
// prints more readable module names in the browser console on HMR updates
new webpack.NamedModulesPlugin(),
// prevent emitting assets with errors
new webpack.NoEmitOnErrorsPlugin()
);
}
// end of plugin management
// optionally live-reloadable entry points
const entryPoints = function() {
const items = isProd
? []
: ["webpack-hot-middleware/client?noInfo=true&reload=true"];
items.push(...arguments);
return items;
};
const postcssLoader = {
loader: "postcss-loader",
options: {
plugins: () => [require("autoprefixer")]
}
};
module.exports = {
entry: {
//app: entryPoints("./src/index.js"),
app: entryPoints("./src/scratch.js"),
vendor: ["preact", "preact-router"]
},
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$/,
loader: isProd
? extractOtherCss.extract({
use: ["css-loader?modules", postcssLoader, "sass-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$/,
loader: isProd
? extractShellCss.extract({
use: ["css-loader", postcssLoader, "sass-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: {
src: path.resolve(__dirname, "./src"),
config: path.resolve(__dirname, "./config")
},
symlinks: false
},
devtool: isProd ? "source-map" : "eval",
plugins
};