-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
84 lines (81 loc) · 2.19 KB
/
webpack.config.js
File metadata and controls
84 lines (81 loc) · 2.19 KB
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
const path = require("path");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const ExtensionReloader = require("./scripts/ext-reloader");
const isDev = process.env.NODE_ENV !== "production";
// パス設定
const ROOT = __dirname; // プロジェクトルート
const SRC = path.resolve(ROOT, "src"); // srcフォルダ
const PUBLIC = path.resolve(ROOT, "public"); // 静的ファイル
const DIST = path.resolve(ROOT, "dist"); // 出力先
module.exports = {
mode: isDev ? "development" : "production",
devtool: isDev ? "inline-source-map" : false,
context: SRC,
entry: {
background: isDev ? path.join(SRC, "background.dev.ts") : path.join(SRC, "background.ts"),
content: path.join(SRC, "content", "index.ts"),
popup: path.join(SRC, "popup", "index.ts")
},
output: {
path: DIST,
filename: "[name].js",
publicPath: "",
clean: true
},
resolve: {
extensions: [".ts", ".tsx", ".js"],
modules: [SRC, "node_modules"]
},
module: {
rules: [
{
test: /\.css$/,
use: ["style-loader", "css-loader"]
},
{
test: /\.tsx?$/,
use: "ts-loader",
exclude: /node_modules/
},
{
test: /\.(png|jpg|jpeg|gif|svg|webp)$/i,
type: "asset/resource",
generator: {
filename: "assets/[name][ext]"
}
}
]
},
plugins: (() => {
const plugins = [
new CopyWebpackPlugin({
patterns: [
// public の静的ファイルをコピー(manifest.dev.json / manifest.prod.json は除外)
{
from: PUBLIC,
to: "./",
filter: (resourcePath) => {
return !/manifest\.(dev|prod)\.json$/.test(resourcePath);
}
},
// 適切な manifest を manifest.json として出力
{
from: path.join(PUBLIC, `manifest.${isDev ? "dev" : "prod"}.json`),
to: "manifest.json"
}
]
})
];
if (isDev) {
plugins.unshift(new ExtensionReloader());
}
return plugins;
})(),
cache: {
type: "filesystem"
},
performance: {
hints: isDev ? false : "warning"
},
stats: isDev ? "minimal" : "normal"
};