-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwebpack.config.js
More file actions
42 lines (38 loc) · 1.09 KB
/
webpack.config.js
File metadata and controls
42 lines (38 loc) · 1.09 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
const path = require('path');
const glob = require('glob');
const fs = require('fs');
const entries = {};
class CreateLoaderPlugin {
apply(compiler) {
compiler.hooks.afterEmit.tap('CreateLoaderPlugin', (compilation) => {
const { options: { entry, output: { path: dir } } } = compilation;
for(let key of Object.keys(entry)) {
let at = path.resolve(dir, key + '.user.js');
fs.writeFileSync(at, [
`// ==UserScript==
// @name wamei-${key}
// @namespace wamei
// @version 0.8
// @author wamei
// @match https://*.slack.com/*
// ==/UserScript==`,
fs.readFileSync(at),
].join('\n\n'));
}
});
}
}
glob.sync('./src/*.js').forEach((filename) => {
entries[filename.replace(/.\/src\/(.+)\.js/, '$1')] = filename;
});
module.exports = {
mode: 'production',
entry: entries,
output: {
filename: '[name].user.js',
path: path.join(__dirname, 'loaders'),
},
plugins: [
new CreateLoaderPlugin(),
],
};