-
Notifications
You must be signed in to change notification settings - Fork 7
/
webpack.common.js
79 lines (77 loc) · 1.89 KB
/
webpack.common.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
const HtmlWebpackPlugin = require("html-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const DotWebpackPlugin = require("dotenv-webpack");
const ProgressBarPlugin = require("progress-bar-webpack-plugin");
const { minify } = require("html-minifier");
const path = require("path");
require("dotenv").config();
function p(filename) {
return path.join(__dirname, filename);
}
module.exports = {
entry: p("src/index.js"),
output: {
path: p("dist/client"),
filename: "[hash].bundle.js",
publicPath: "/"
},
plugins: [
new ProgressBarPlugin(),
new HtmlWebpackPlugin({
inject: false,
template: require("html-webpack-template"),
bodyHtmlSnippet: `<div class="root"><style type="text/css">html{background-size:cover;background:rgb(42, 56, 26);}</style></div>`,
favicon: p("src/favicon.ico"),
title: process.env.APP_NAME,
lang: "en-US"
}),
new CopyWebpackPlugin([
{
from: p("src/asset"),
to: p("dist/client/asset"),
transform(content, path) {
if (/\.svg$/.test(path))
return minify(content.toString());
return content;
}
}
]),
new DotWebpackPlugin()
],
module: {
rules: [
{
test: /\.jsx?/,
exclude: /node_modules/,
loader: "babel-loader"
},
{
test: /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
use: [
{
loader: "file-loader",
options: {
name: "[name].[ext]",
outputPath: "fonts/"
}
}
]
},
{
test: /\.css$/i,
use: [
"style-loader",
{ loader: "css-loader", options: { importLoaders: 1 } },
"postcss-loader"
]
},
{
test: /\.(html)$/,
loader: "html-loader"
}
]
},
node: {
fs: "empty"
}
}