-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
170 lines (165 loc) · 5.26 KB
/
webpack.config.js
File metadata and controls
170 lines (165 loc) · 5.26 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
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
const {join} = require("path");
const {VueLoaderPlugin} = require("vue-loader");
const fs = require('fs');
const CopyPlugin = require("copy-webpack-plugin");
const HtmlWebpackPlugin = require('html-webpack-plugin')
const webpack = require("webpack");
const pack = require('./package.json');
function modify_manifest(buffer, browser_type, version, mode) {
// copy-webpack-plugin passes a buffer
let manifest = JSON.parse(buffer.toString());
let icons = {
16: "images/icon16.png",
32: "images/icon32.png",
48: "images/icon48.png",
128: "images/icon128.png"
}
manifest.author = pack.author
manifest.description = pack.description
manifest.icons = icons
manifest.manifest_version = 3
manifest.permissions.push("scripting")
manifest.host_permissions = ["<all_urls>"]
manifest.action = {
default_icon: icons,
default_title: manifest.name
}
manifest.web_accessible_resources = [{
resources: ["js/*.js", "js/*.map","css/*.css",
"*.woff", "*.woff2", "*.ttf", "home.html", "options.html"],
matches: ["<all_urls>"]
}]
if (browser_type === "firefox") {
// Firefox specific
manifest.browser_specific_settings = {
"gecko": {
"id": "webtvremote@maoserr.com"
}
}
manifest.options_ui.open_in_tab = true
manifest.background = {
scripts: ["js/service_worker.js"]
}
} else {
// Chrome specific
manifest.background = {
service_worker: "js/service_worker.js"
}
}
// Dynamic version
manifest.version = version;
// pretty print to JSON with two spaces
return JSON.stringify(manifest, null, 2);
}
module.exports = (env, argv) => {
let out_dir = "dist/chrome"
let ver = "1.0.0"
if (env.version) {
ver = env.version
}
if (env.browser_type === "firefox") {
out_dir = "dist/firefox"
}
if (argv.mode === "production") {
out_dir = out_dir + "_prod"
}
return {
optimization: {
minimize: argv.mode === "production",
// EJS uses new Function
minimizer: [],
splitChunks: {
minSize: 100000,
maxSize: 3500000,
chunks: 'all',
}
},
entry: fs.readdirSync(join(__dirname, "src/entry"))
.reduce((acc, v) => (
{...acc, [v.replace('.ts', '')]: join(__dirname, "src/entry", v)}
), {}),
devtool: 'cheap-module-source-map',
module: {
rules: [
{
test: /\.vue$/,
loader: "vue-loader",
},
{
test: /\.tsx?$/,
loader: 'ts-loader',
options: {
appendTsSuffixTo: [/\.vue$/],
},
exclude: /node_modules/,
},
{
test: /\.css$/,
use: [
'style-loader',
'css-loader'
]
}
],
},
output: {
path: join(__dirname, out_dir),
filename: "js/[name].js",
clean: true,
},
resolve: {
extensions: [".tsx", ".ts", ".js", '.vue', '.json'],
alias: {
'vue': '@vue/runtime-dom'
},
fallback: {
"fs": false,
"buffer": require.resolve("buffer"),
"path": require.resolve("path-browserify")
}
},
plugins: [
new VueLoaderPlugin(),
new HtmlWebpackPlugin({
chunks: ['options'],
filename: 'options.html',
template: 'templates/default.html'
}),
new HtmlWebpackPlugin({
chunks: ['main'],
filename: 'main.html',
template: 'templates/default.html'
}),
new webpack.DefinePlugin({
__VUE_OPTIONS_API__: "true",
__VUE_PROD_DEVTOOLS__: "false",
__VUE_PROD_HYDRATION_MISMATCH_DETAILS__: "false"
}),
new CopyPlugin({
patterns: [
{from: "assets"},
{
from: "src/manifest.json",
to: "manifest.json",
transform(content, path) {
return modify_manifest(content, env.browser_type, ver, argv.mode)
}
}
],
}),
new webpack.NormalModuleReplacementPlugin(/node:/, (resource) => {
const mod = resource.request.replace(/^node:/, "");
switch (mod) {
case "buffer":
resource.request = "buffer";
break;
case "stream":
resource.request = "readable-stream";
break;
default:
throw new Error(`Not found ${mod}`);
}
})
],
}
}