-
Notifications
You must be signed in to change notification settings - Fork 9
/
webpack.config.ts
117 lines (113 loc) · 3.69 KB
/
webpack.config.ts
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
import * as CleanWebpackPlugin from "clean-webpack-plugin";
import * as ExtractTextPlugin from "extract-text-webpack-plugin";
import * as HtmlWebpackPlugin from "html-webpack-plugin";
import * as MiniCssExtractPlugin from "mini-css-extract-plugin";
import { resolve } from "path";
import * as webpack from "webpack";
import * as ZipPlugin from "zip-webpack-plugin";
const REQUIRE_POLYFILL = process.env.BROWSER !== "firefox";
const IS_PROD = process.argv.includes("--run-prod");
function polyfillChunks(...chunks: string[]): string[] {
return REQUIRE_POLYFILL ? ["polyfill", ...chunks] : chunks;
}
const config: webpack.Configuration = {
entry: {
polyfill: resolve(__dirname, "app/polyfill.ts"),
background: resolve(__dirname, "app/background.ts"),
form: resolve(__dirname, "app/form/form.ts"),
manifest: resolve(__dirname, "app/manifest.ts"),
options: resolve(__dirname, "app/options/options.ts"),
popup: resolve(__dirname, "app/popup/popup.ts"),
},
output: {
filename: "[name].js",
path: resolve(`dist/${process.env.BROWSER}`),
},
optimization: {
minimize: false,
namedChunks: true,
namedModules: true,
removeEmptyChunks: true,
removeAvailableModules: true,
},
resolve: {
extensions: [".ts"],
},
module: {
rules: [
{
test: /\/manifest\.ts$/,
use: ExtractTextPlugin.extract({use: []}),
},
{
test: /\.ts$/,
use: "ts-loader",
},
{
test: /\.css$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: "css-loader",
},
],
},
{
test: /\.(png|svg)$/,
use: [{
loader: "file-loader",
options: {
context: resolve(__dirname, "app"),
name: "[path][name].[ext]",
outputPath: "",
publicPath: "/",
},
}],
},
],
},
plugins: [
new CleanWebpackPlugin([
resolve(`dist/${process.env.BROWSER}`),
], {verbose: false}),
new webpack.EnvironmentPlugin([
"BROWSER",
"npm_package_name",
"npm_package_version",
"npm_package_description",
"npm_package_homepage",
]),
new ExtractTextPlugin("manifest.json"),
new MiniCssExtractPlugin(),
new HtmlWebpackPlugin({
chunks: polyfillChunks("form"),
filename: "form.html",
template: resolve(__dirname, "app/form/form.html"),
}),
new HtmlWebpackPlugin({
chunks: polyfillChunks("options"),
filename: "options.html",
template: resolve(__dirname, "app/options/options.html"),
}),
new HtmlWebpackPlugin({
chunks: polyfillChunks("popup"),
filename: "popup.html",
template: resolve(__dirname, "app/popup/popup.html"),
}),
...(IS_PROD ? [
new ZipPlugin({
exclude: [
/\.map$/,
/manifest\.js$/,
...(REQUIRE_POLYFILL ? [] : [/polyfill\.js$/]),
],
filename: [
process.env.npm_package_name,
process.env.npm_package_version,
process.env.BROWSER,
].join("-") + ".zip",
}),
] : []),
],
};
export default config;