-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathwebpack.config.js
More file actions
86 lines (80 loc) · 2.07 KB
/
webpack.config.js
File metadata and controls
86 lines (80 loc) · 2.07 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
const webpack = require("webpack");
const path = require("path");
const autoprefixer = require("autoprefixer");
const ExtractTextPlugin = require("extract-text-webpack-plugin");
module.exports = ({ dev }) => {
const devEntries = dev
? [
// For hot style updates
"webpack/hot/dev-server",
// The script refreshing the browser on none hot updates
"webpack-dev-server/client?http://localhost:8080"
]
: [];
const outputPath = path.resolve(__dirname, dev ? "build" : "dist");
const devPlugins = [new webpack.HotModuleReplacementPlugin()];
const buildPlugins = [
new ExtractTextPlugin("styles/styles.css"),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.UglifyJsPlugin()
];
const cssLoader = dev
? [
"style-loader",
"css-loader",
{
loader: "postcss-loader",
options: { plugins: [autoprefixer] }
}
]
: ExtractTextPlugin.extract({
fallback: "style-loader",
use: "css-loader!postcss-loader"
});
return {
// we have to require babel-polyfill first
// https://babeljs.io/docs/usage/polyfill/
entry: []
.concat("babel-polyfill")
.concat(devEntries)
.concat("./src/index.js"),
output: {
path: outputPath,
publicPath: "",
filename: "client.js"
},
module: {
rules: [
{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
use: ["babel-loader"]
},
{
test: /\.css$/,
use: cssLoader
},
{
test: /\.sass$/,
use: [
"style-loader",
{
loader: "css-loader",
options: {
modules: true,
localIdentName: `[name]__[local]___[hash:base64:5]`
}
},
{
loader: "sass-loader",
options: {
indentedSyntax: true
}
}
]
}
]
},
plugins: dev ? devPlugins : buildPlugins
};
};