-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
102 lines (100 loc) · 3.45 KB
/
webpack.config.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
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
const path = require('path');
const webpack = require('webpack');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const package = require('./package.json');
module.exports = (env, argv) => ({
entry: {
// Output multiple files, one for each main page - important!: also include the polyfills in the output bundle
'reliquary-extension.user': argv.mode === 'production' ? [
'./src/utils/enable-polyfills.ts',
'./src/index.ts'
] : './src/index.ts',
},
output: {
filename: '[name].js',
// Path on disk for output file
path: path.resolve(__dirname, 'dist'),
// Path in webpack-dev-server for compiled files (has priority over disk files in case both exist)
publicPath: '/dist/',
},
resolve: {
extensions: ['.js', '.ts'], // enable autocompleting .ts and .js extensions when using import '...'
alias: {
// Enable importing source files by their absolute path by prefixing with "@/"
// Note: this also requires typescript to be able to find the imports (though it doesn't use them other than for type checking), see tsconfig.json
"@": path.join(__dirname, "src"),
}
},
module: {
// import/exports
rules: [{
test: /\.css$/,
use: ['style-loader', 'css-loader'],
}, {
test: /\.scss$/,
use: [
'style-loader',
'css-loader',
'sass-loader'
]
}, {
test: /\.ts$/,
use: [argv.mode === 'production' ? { loader: 'babel-loader' } : undefined,
{
loader: 'ts-loader',
options: {
/*
Required for webpack-dev-server to support HMR (hot module reloading) from typescript files
This however disables all type checking errors/warnings
These are then re-enabled through ForkTsCheckerWebpackPlugin
NOTE: the default behavior is to refresh the entire page on changes in a module
this can be prevented by adding the following code (essentially manually replacing your imported functions with the updated version):
But it needs to be done everywhere the module is used, and for every import that you want to update without refreshing the page...
if (module.hot) {
module.hot.accept('./exports-string', () => {
const { valueToLog } = require('./exports-string'); // original imported value doesn't update, so you need to import it again
document.write(`HMR valueToLog: ${valueToLog}`);
});
}
*/
transpileOnly: true,
appendTsSuffixTo: [/\.vue$/],
}
}].filter(v => v != null)
}, {
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
}]
},
plugins: [
new ForkTsCheckerWebpackPlugin({
vue: true
}),
// new BundleAnalyzerPlugin(),
new CleanWebpackPlugin(['dist'], {
verbose: false,
}),
new webpack.BannerPlugin(
`// ==UserScript==
// @name ${package.name}
// @namespace https://github.com/kcmertens/
// @description ${package.description}
// @match *://wf.xuerian.net/*
// @version ${package.version}
// @license ${package.licence}
// @grant GM.getValue
// @grant GM.setValue
// @downloadURL ${getUpdateUrl(argv)}
// @updateURL ${getUpdateUrl(argv)}
// ==/UserScript==`)
],
devtool: argv.mode === 'development' ? 'eval-source-map' : 'source-map'
});
function getUpdateUrl(argv) {
switch (argv.mode) {
case 'production': return 'https://github.com/KCMertens/wf-reliquery-extension/raw/master/dist/reliquary-extension.user.js';
default: return 'http://localhost:8080/dist/reliquary-extension.user.js'
}
}