-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.dev.js
70 lines (67 loc) · 1.76 KB
/
webpack.dev.js
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
const webpack = require('webpack');
const merge = require('webpack-merge');
const common = require('./webpack.common.js');
const WebpackUserscript = require('webpack-userscript');
const ExtensionReloader = require('webpack-extension-reloader');
function getConf(env, name) {
const plugins = [];
if (env.userscript) {
plugins.push(new WebpackUserscript({
headers: {
name: 'CR Queue Sorter',
version: `[version]-build.[buildNo]`,
match: 'https://www.crunchyroll.com/home/queue',
grant: [
'unsafeWindow'
]
},
proxyScript: {
baseUrl: 'http://127.0.0.1:5001/userscript',
filename: '[basename].proxy.user.js',
enable: true
}
}));
}
if (env.chrome) {
plugins.push(
new ExtensionReloader({
port: 9090, // Which port use to create the server
reloadPage: true, // Force the reload of the page also
entries: { // The entries used for the content/background scripts or extension pages
contentScript: 'content-script',
background: 'background',
// extensionPage: 'popup',
}
})
);
}
return merge(common(env), {
name,
watch: true,
mode: 'development',
plugins: [
...plugins
],
devtool: 'inline-source-map'
});
}
module.exports = (env) => {
env = env || {};
let {
userscript,
chrome
} = env;
env.chrome = false;
env.userscript = false;
if (!userscript && !chrome) {
userscript = chrome = true;
}
const configs = [];
if (userscript) {
configs.push(getConf({ ...env, userscript: true, subdir: 'userscript' }, 'userscript'));
}
if (chrome) {
configs.push(getConf({ ...env, chrome: true, subdir: 'chrome' }, 'chrome'));
}
return configs;
};