-
Notifications
You must be signed in to change notification settings - Fork 3
/
webpack.config.js
89 lines (88 loc) · 2.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
const path = require('path');
const webpack = require('webpack');
const NodePolyfillPlugin = require("node-polyfill-webpack-plugin");
const CopyPlugin = require("copy-webpack-plugin");
const TerserPlugin = require('terser-webpack-plugin');
module.exports = function (env, argv) {
return {
entry: {
autorun: './src/content/autorun.tsx',
content: './src/content/index.tsx',
background: './src/background/background.ts',
standalone: {
import: './src/standalone/standalone.tsx',
library: { name: 'matrixHighlight', type: 'window' },
},
},
devtool: "source-map",
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
{
test: /\.css$/i,
use: 'css-loader',
},
{
test: /\.s[ac]ss$/i,
use: [
// Creates `style` nodes from JS strings
{
loader: "style-loader",
options: {
styleTagTransform: function (css, style) {
style.innerHTML = css;
if (!window._matrixHighlightStyleNodes) {
window._matrixHighlightStyleNodes = [];
}
window._matrixHighlightStyleNodes.unshift(style);
},
injectType: "styleTag",
}
},
// Translates CSS into CommonJS
"css-loader",
// Compiles Sass to CSS
"sass-loader",
],
},
],
},
plugins: [
new NodePolyfillPlugin(),
new CopyPlugin({ patterns: [
{ from: "public", to: "." },
{ from: "public-" + (env.browser || "firefox"), to: "." }
]}),
new webpack.ProvidePlugin({
XMLHttpRequest: 'xhr-shim'
}),
],
resolve: {
extensions: ['.tsx', '.ts', '.js'],
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'dist'),
},
optimization: {
// Replacing default minification because of https://stackoverflow.com/questions/49979397/chrome-says-my-content-script-isnt-utf-8
// Contributed by GitHub user @Stvad
minimize: true,
minimizer: [
new TerserPlugin({
parallel: true,
terserOptions: {
ecma: 6,
output: {
ascii_only: true
},
},
}),
],
},
};
};