-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
102 lines (100 loc) · 2.54 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
const pkg = require("./package");
const path = require("path");
const args = require("yargs").argv;
const IS_DEV = process.env.NODE_ENV !== "production";
const dirNode = path.resolve(__dirname, "node_modules");
const dirApp = path.resolve(__dirname, "src");
const dirAssets = path.resolve(__dirname, "assets");
const webpack = require("webpack");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const PostcssFlexbugsFixes = require("postcss-flexbugs-fixes");
const Autoprefixer = require("autoprefixer")({
browsers: ["last 2 version", "> 1%", "IE 10"]
});
/**
* Webpack Configuration
*/
module.exports = {
mode: "development",
target: "web",
entry: ["./src/index.js", "./client.js"],
output: {
filename: "[name].bundle.js",
path: path.resolve(__dirname, "dist")
},
resolve: {
modules: [dirAssets, dirApp, dirNode],
alias: {
"~": dirNode
}
},
module: {
rules: [
// BABEL
{
test: /\.js$/,
loader: "babel-loader",
include: [dirApp]
},
// SCSS | CSS
{
test: /\.(sa|sc|c)ss$/,
use: [
IS_DEV ? "style-loader" : MiniCssExtractPlugin.loader,
"css-loader",
{
loader: "postcss-loader",
options: {
sourceMap: IS_DEV,
plugins: [PostcssFlexbugsFixes, Autoprefixer]
}
},
{
loader: "sass-loader",
options: {
sourceMap: IS_DEV,
data: "$prefix: " + pkg.prefix + ";"
}
}
]
},
// FONTS/IMAGES
{
test: /\.(woff|woff2|ttf|eot|otf|svg|gif|png|jpe?g)$/i,
use: [
{
loader: "url-loader",
options: {
limit: 1024,
name(file) {
if (file.indexOf("fonts") > -1) {
return "fonts/[name].[ext]";
} else {
return "images/[name].[ext]";
}
},
fallback: "file-loader",
outputPath: "./",
publicPath: "/"
}
}
]
}
]
},
plugins: [
new webpack.DefinePlugin({
IS_DEV,
pkg
}),
new MiniCssExtractPlugin({
filename: module.hot ? "css/[name].css" : "css/[name].[contenthash].css",
chunkFilename: "css/[id].css"
}),
new HtmlWebpackPlugin({
template: path.join(__dirname, "/index.ejs"),
title: pkg.description
})
]
};