-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
81 lines (79 loc) · 2.8 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
import path from 'path';
import { createRequire } from 'module';
import { fileURLToPath } from 'url';
import webpack from 'webpack';
import CopyPlugin from 'copy-webpack-plugin';
import ResolveTypeScriptPlugin from 'resolve-typescript-plugin';
const require = createRequire(import.meta.url);
const filename = fileURLToPath(import.meta.url);
const dirname = path.dirname(filename);
/* eslint-disable-next-line import/no-default-export */
export default {
entry: {
background: ['./src/chrome-extension/background.ts'],
'content-script': ['./src/chrome-extension/content-script.ts'],
options: ['./src/chrome-extension/options.ts'],
},
// https://webpack.js.org/guides/typescript/
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
],
},
// without this, I can't satisfy emacs TIDE's need for import lines to exclude
// the .ts suffix, as it calls into tsc without webpack preprocessing.
//
// https://stackoverflow.com/questions/43595555/webpack-cant-resolve-typescript-modules
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx', '.json'],
plugins: [new ResolveTypeScriptPlugin()],
fallback: {
// The node-asana library uses the node API and expects users to
// use webpack to polyfill it when using BrowserJS:
//
// https://webpack.js.org/configuration/resolve/
fs: false, // not particularly used by asana
url: require.resolve('url'),
util: require.resolve('util'),
stream: require.resolve('stream-browserify'),
buffer: require.resolve('buffer'),
// see the plugins key below for more complex handling of
// process.
},
},
mode: 'development', // override with webpack --mode=production on CLI builds
output: {
path: path.resolve(dirname, 'dist/chrome-extension'),
filename: '[name].js',
},
// 'inline-source-map' is suggested by https://webpack.js.org/guides/typescript/
// 'cheap-module-source-map' is suggested by https://stackoverflow.com/questions/48047150/chrome-extension-compiled-by-webpack-throws-unsafe-eval-error
devtool: 'cheap-module-source-map',
plugins: [
// node-asana uses process.nextTick, which this provides:
new webpack.ProvidePlugin({
process: 'process/browser',
}),
// The node-util polyfill looks up 'process.env.NODE_DEBUG' to
// toggle debugging without checking for process.env existing.
//
// The node-process polyfill doesn't provide process.env at all.
//
// There's no note of this on the webpack page recommending
// node polyfills.
//
// https://github.com/browserify/node-util/issues/43
new webpack.DefinePlugin({
process: {
env: '{}',
},
}),
new CopyPlugin({
patterns: [{ from: 'static/chrome-extension' }],
}),
],
};