-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.userscript.js
65 lines (61 loc) · 1.82 KB
/
webpack.userscript.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
'use strict';
const CleanPlugin = require('clean-webpack-plugin');
const MinifyPlugin = require('babel-minify-webpack-plugin');
const UserscriptMeta = require('userscript-meta');
const WrapperPlugin = require('wrapper-webpack-plugin');
const { resolve } = require('path'),
src = resolve(__dirname, 'src'),
dist = resolve(__dirname, 'dist/userscript');
const p = require('./package.json');
module.exports = (env, argv) => ({
devtool: argv.mode === 'development' ? 'cheap-source-map' : '',
optimization: { minimize: false }, // necessary for Userscript-style comments
entry: {
'main': resolve(src, 'index.js')
},
output: {
path: dist,
filename: '[name].user.js',
libraryTarget: 'umd'
},
module: {
rules: [{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/env']
}
}
}, {
test: /\.scss$/,
exclude: /node_modules/,
use: [{
loader: 'style-loader'
}, {
loader: 'css-loader',
options: { minimize: true }
}, {
loader: 'sass-loader',
options: { outputStyle: 'compressed' }
}]
}]
},
plugins: [
new CleanPlugin([resolve(dist, '*.*')])
].concat(argv.mode === 'development' ? [] : [new MinifyPlugin()]).concat([
new WrapperPlugin({
header: UserscriptMeta.stringify({
name: p.name.split(/-/).map(v => v.charAt(0).toUpperCase() + v.slice(1)).join(' '), // kebab to title case
version: p.version,
description: p.description,
author: p.author,
namespace: p.homepage,
include: '*://www.google.tld/search*',
downloadURL: 'https://raw.githubusercontent.com/ccjmne/search-navigation-hotkeys/master/dist/userscript/main.user.js',
grant: 'none'
})
})
])
});