-
Notifications
You must be signed in to change notification settings - Fork 76
/
webpack.config.js
131 lines (128 loc) · 4.01 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
const webpack = require("webpack");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const ManifestPlugin = require("webpack-manifest-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const path = require("path");
process.env.NODE_ENV = process.env.NODE_ENV || "development";
const DEBUG =
process.env.NODE_ENV === "development" ||
process.env.NODE_ENV === undefined;
const HOST = process.env.HOST || "localhost";
const devtool = DEBUG ? "#inline-source-map" : "#eval";
const fileName = DEBUG ? "[name]" : "[name]-[hash]";
const plugins = [
new MiniCssExtractPlugin({
filename: `${fileName}.css`,
}),
new HtmlWebpackPlugin({
template: path.join(__dirname, "public/index.html"),
inject: false,
favicon: path.join(__dirname, "public/favicon.ico"),
files: {
js: `${fileName}.js`,
css: `${fileName}.css`,
},
minify: {
removeComments: true,
// collapseWhitespace: true,
removeRedundantAttributes: true,
useShortDoctype: true,
removeEmptyAttributes: true,
removeStyleLinkTypeAttributes: true,
keepClosingSlash: true,
// minifyJS: true,
// minifyCSS: true,
// minifyURLs: true,
},
ADSENSE_AD_CLIENT: process.env.ADSENSE_AD_CLIENT,
ADSENSE_AD_SLOT_PC1: process.env.ADSENSE_AD_SLOT_PC1,
ADSENSE_AD_SLOT_PC2: process.env.ADSENSE_AD_SLOT_PC2,
ADSENSE_AD_SLOT_MOBILE: process.env.ADSENSE_AD_SLOT_MOBILE,
GOOGLE_ANALYTICS_TRACKING_ID: process.env.GOOGLE_ANALYTICS_TRACKING_ID,
}),
new webpack.DefinePlugin({
"process.env": {
NODE_ENV: JSON.stringify(process.env.NODE_ENV || "development"),
GITHUB_API_TOKEN: JSON.stringify(
process.env.GITHUB_API_TOKEN || ""
),
TWITTER_ID: JSON.stringify(process.env.TWITTER_ID || ""),
},
}),
new CopyWebpackPlugin([
{
from: path.join(__dirname, "/*Data.json"),
to: path.join(__dirname, "/dist/"),
},
{
from: path.join(__dirname, "/imgs/"),
to: path.join(__dirname, "/dist/imgs/"),
ignore: ["*.txt"],
},
{
from: path.join(__dirname, "/otherImages/"),
to: path.join(__dirname, "/dist/otherImages/"),
},
{
from: path.join(__dirname, "/charaimgs/"),
to: path.join(__dirname, "/dist/charaimgs/"),
ignore: ["*.txt"],
},
]),
// new webpack.optimize.UglifyJsPlugin({
// compress: {
// screw_ie8: true, // React doesn't support IE8
// warnings: false,
// },
// mangle: {
// screw_ie8: true,
// },
// output: {
// comments: false,
// screw_ie8: true,
// },
// }),
new ManifestPlugin({
fileName: "asset-manifest.json",
}),
];
module.exports = {
devtool: devtool,
entry: ["./src/content.js", "./css/style.css", "./css/smartphone.css"],
output: {
path: path.join(__dirname, "dist"),
filename: `${fileName}.js`,
},
module: {
rules: [
{
test: /.jsx?$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
},
},
{
test: /.css$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
publicPath: "css",
},
},
"css-loader",
],
},
],
},
plugins: plugins,
devServer: {
contentBase: [path.join(__dirname, "/dist")],
compress: true,
host: HOST,
port: 8000,
},
mode: process.env.NODE_ENV || "development",
};