-
Notifications
You must be signed in to change notification settings - Fork 3
/
webpack.config.ts
89 lines (87 loc) · 2.77 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
import * as CleanWebpackPlugin from "clean-webpack-plugin";
import * as CopyWebpackPlugin from "copy-webpack-plugin";
import * as ExtractTextPlugin from "extract-text-webpack-plugin";
import * as fs from "fs";
import * as HtmlWebpackPlugin from "html-webpack-plugin";
import { resolve } from "path";
import * as webpack from "webpack";
import * as ZipPlugin from "zip-webpack-plugin";
const config: webpack.Configuration = {
entry: {
background: resolve(__dirname, "app/background.ts"),
manifest: resolve(__dirname, "app/manifest.ts"),
options: resolve(__dirname, "app/options/options.ts"),
},
output: {
filename: "[name].js",
path: resolve(__dirname, `dist/${process.env.BROWSER}`),
},
optimization: {
minimize: false,
namedChunks: true,
namedModules: true,
occurrenceOrder: true,
removeEmptyChunks: true,
removeAvailableModules: true,
},
resolve: {
extensions: [".ts"]
},
module: {
rules: [
{
test: /manifest\.ts$/,
use: ExtractTextPlugin.extract({use: []})
},
{
test: /\.ts$/,
use: "ts-loader",
},
{
test: /\.(png|svg)$/,
use: [{
loader: "file-loader",
options: {
context: resolve(__dirname, "app"),
name: "[path][name].[ext]",
outputPath: "",
publicPath: "/",
}
}]
},
]
},
plugins: [
new CleanWebpackPlugin([
resolve(__dirname, `dist/${process.env.BROWSER}/*`),
], {verbose: false}),
new webpack.EnvironmentPlugin([
"BROWSER",
"npm_package_name",
"npm_package_version",
"npm_package_description",
"npm_package_homepage",
]),
new ExtractTextPlugin("[name].json"),
new HtmlWebpackPlugin({
chunks: ["options"],
filename: "options.html",
template: resolve(__dirname, "app/options/options.ejs"),
}),
new CopyWebpackPlugin([
{from: resolve(__dirname, "README.md")},
{from: resolve(__dirname, "app/_locales"), to: "_locales"},
]),
...(process.argv.includes("production") ? [
new ZipPlugin({
exclude: /(manifest|messages)\.js$/,
filename: [
process.env.npm_package_name,
process.env.npm_package_version,
process.env.BROWSER,
].join("-") + ".zip"
})
] : [])
],
};
export default config;