-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.example.config.js
85 lines (81 loc) · 2.3 KB
/
webpack.example.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
const path = require("path");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const { babel } = require("./package.json");
const isProd = process.env.NODE_ENV === "production";
console.log("Webpack building with NODE_ENV", process.env.NODE_ENV);
module.exports = {
target: "web",
entry: "./example-src/example.js",
mode: isProd ? "production" : "development",
output: {
filename: "example.js",
path: path.resolve(__dirname, "example-dist/")
},
module: {
rules: [
{
test: /\.js$/,
use: [
{
loader: "babel-loader",
options: {
presets: babel.presets,
plugins: babel.plugins
}
}
]
},
// CSS
{
test: /\.css$/,
sideEffects: true,
use: [
{
loader: isProd ? MiniCssExtractPlugin.loader : "style-loader"
},
{
loader: "css-loader",
options: {
importLoaders: 1,
sourceMap: true
}
},
{
loader: "postcss-loader",
options: {
ident: "postcss",
plugins: function(loader) {
return [
require("postcss-import")({
root: "./example-src/example.css"
}),
require("postcss-url")(),
require("postcss-preset-env")({
browsers: "last 2 versions",
stage: 3,
features: {
"nesting-rules": false /* disable css nesting which does not allow nesting of selectors without white spaces between them */,
"custom-media-queries": true
}
}),
require("postcss-nested") /*replace cssnext nesting with this one which allows for sass style nesting*/,
require("postcss-reporter")({
clearAllMessages: false
})
];
}
}
}
],
include: [path.resolve(__dirname, "example")]
}
]
},
plugins: [
isProd
? new MiniCssExtractPlugin({
filename: "example.css"
})
: null
].filter(Boolean)
};