forked from TotallyNot/fe_ext
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.common.ts
88 lines (84 loc) · 2.92 KB
/
webpack.common.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
import { join } from "path";
import { Configuration, WebpackPluginInstance } from "webpack";
import CopyPlugin from "copy-webpack-plugin";
import { LicenseWebpackPlugin } from "license-webpack-plugin";
const config: Configuration = {
entry: {
background: join(__dirname, "src/background/index.ts"),
popup: join(__dirname, "src/popup/index.ts"),
settings: join(__dirname, "src/settings/index.ts"),
acknowledgements: join(__dirname, "src/acknowledgements/index.ts"),
},
output: {
path: join(__dirname, "dist"),
filename: "js/[name].js",
},
module: {
rules: [
{
exclude: /node_modules/,
test: /\.tsx?$/,
use: "ts-loader",
},
{
test: /\.svg$/,
use: [
{
loader: "file-loader",
options: {
name: "[hash]-[name].[ext]",
outputPath: "static/images",
publicPath: "/static/images",
},
},
],
},
],
},
resolve: {
extensions: [".ts", ".js"],
alias: {
common: join(__dirname, "src/common"),
},
},
plugins: [
new CopyPlugin({
patterns: [
{
from: join(__dirname, "resources/manifest.json"),
to: join(__dirname, "dist/manifest.json"),
transform(content) {
const manifest = JSON.parse(content.toString());
const packageJSON = require("./package.json");
manifest.version = packageJSON.version;
manifest.version_name = `v${packageJSON.version}`;
manifest.description = packageJSON.description;
manifest.author = packageJSON.author;
return Buffer.from(JSON.stringify(manifest, null, 4));
},
},
],
}),
// typings are broken :/
// therefore, nuclear option
(new LicenseWebpackPlugin({
perChunkOutput: false,
stats: {
warnings: false,
errors: true,
},
outputFilename: "licenses.json",
renderLicenses: modules =>
JSON.stringify(
modules.map(module => ({
name: module.name,
version: module.packageJson.version,
author: (module.packageJson as any).author,
license: module.licenseId,
licenseText: module.licenseText,
}))
),
}) as unknown) as WebpackPluginInstance,
],
};
export default config;