forked from IBMa/equal-access
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
171 lines (165 loc) · 6.6 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
// const ExtensionReloader = require('webpack-ext-reloader');
const locateContentScripts = require('./utils/locateContentScripts');
const Dotenv = require('dotenv-webpack');
const sourceRootPath = path.join(__dirname, 'src');
const archivePath = path.join(__dirname, '..', 'rule-server', 'dist', 'static');
const contentScriptsPath = path.join(sourceRootPath, 'ts', 'contentScripts');
const distRootPath = path.join(__dirname, 'dist');
const nodeEnv = process.env.NODE_ENV ? process.env.NODE_ENV : 'development';
const webBrowser = process.env.WEB_BROWSER ? process.env.WEB_BROWSER : 'chrome';
const contentScripts = locateContentScripts(contentScriptsPath);
// const extensionReloader = nodeEnv === "watch" || nodeEnv === "watch_local" ? new ExtensionReloader({
// port: 9128,
// reloadPage: true,
// entries: {
// background: 'background',
// extensionPage: ['popup', 'options', 'devtools', 'devtoolsPanel', 'devtoolsSubpanel'],
// contentScript: Object.keys(contentScripts),
// }
// }) : () => { this.apply = () => { } };
const dotenv_path = nodeEnv === "production" ? ".env_production" : nodeEnv === "watch_local" ? "./.env_local" : "./.env_development";
console.log(`[INFO] Using environment ${dotenv_path}`);
module.exports = {
watch: nodeEnv === 'watch' || nodeEnv === "watch_local",
entry: {
background: path.join(sourceRootPath, 'ts', 'background', 'index.ts'),
options: path.join(sourceRootPath, 'ts', 'options', 'index.tsx'),
popup: path.join(sourceRootPath, 'ts', 'popup', 'index.tsx'),
devtools: path.join(sourceRootPath, 'ts', 'devtools', 'index.tsx'),
devtoolsPanel: path.join(sourceRootPath, 'ts', 'devtoolsPanel', 'index.tsx'),
devtoolsSubpanel: path.join(sourceRootPath, 'ts', 'devtoolsSubpanel', 'index.tsx'),
draw: path.join(sourceRootPath, 'ts', 'contentScripts', 'index.ts'),
tabListeners: path.join(sourceRootPath, 'ts', 'tab', 'tabListeners.ts'),
usingAC: path.join(sourceRootPath, 'ts', 'usingAC', 'index.tsx'),
...contentScripts,
quickGuideAC: path.join(sourceRootPath, 'ts', 'quickGuideAC', 'index.tsx'),
...contentScripts,
},
output: {
path: distRootPath,
filename: '[name].js',
},
optimization: nodeEnv.includes("watch") ? {
minimize: false
} : {
splitChunks: {
maxSize: 3500000,
chunks: "all"
}
},
resolve: {
extensions: ['.js', '.ts', '.tsx', '.json'],
},
module: {
rules: [
{ test: /\.(js|ts|tsx)?$/, loader: "ts-loader", exclude: /node_modules/ },
{
test: /\.scss$/,
use: [
"style-loader", // creates style nodes from JS strings
"css-loader", // translates CSS into CommonJS
"sass-loader" // compiles Sass to CSS, using Node Sass by default
]
},
{
test: /\.svg$/,
use: ['@svgr/webpack', 'url-loader'],
}
]
},
plugins: [
new Dotenv({
path: dotenv_path
}),
new HtmlWebpackPlugin({
template: path.join(sourceRootPath, 'html', 'options.html'),
inject: 'body',
filename: 'options.html',
title: 'Accessibility Checker Extension - Options Page',
chunks: ['options']
}),
new HtmlWebpackPlugin({
template: path.join(sourceRootPath, 'html', 'popup.html'),
inject: 'body',
filename: 'popup.html',
title: 'Accessibility Checker Extension - Popup Page',
chunks: ['popup']
}),
new HtmlWebpackPlugin({
template: path.join(sourceRootPath, 'html', 'devtools.html'),
inject: 'body',
filename: 'devtools.html',
title: 'Accessibility Checker Extension',
chunks: ['devtools']
}),
new HtmlWebpackPlugin({
template: path.join(sourceRootPath, 'html', 'devtoolsPanel.html'),
inject: 'body',
filename: 'devtoolsPanel.html',
title: 'Accessibility Checker Extension',
chunks: ['devtoolsPanel']
}),
new HtmlWebpackPlugin({
template: path.join(sourceRootPath, 'html', 'devtoolsSubpanel.html'),
inject: 'body',
filename: 'devtoolsSubpanel.html',
title: 'Accessibility Checker Extension',
chunks: ['devtoolsSubpanel']
}),
new HtmlWebpackPlugin({
template: path.join(sourceRootPath, 'html', 'reports.html'),
inject: 'body',
filename: 'reports.html',
title: 'Accessibility Checker Extension',
chunks: ['reports']
}),
new HtmlWebpackPlugin({
template: path.join(sourceRootPath, 'html', 'usingAC.html'),
inject: 'body',
filename: 'usingAC.html',
title: 'Accessibility Checker Extension - User Guide',
chunks: ['usingAC']
}),
new HtmlWebpackPlugin({
template: path.join(sourceRootPath, 'html', 'quickGuideAC.html'),
inject: 'body',
filename: 'quickGuideAC.html',
title: 'Accessibility Checker Extension - Quick Guide',
chunks: ['quickGuideAC']
}),
new CopyWebpackPlugin({
patterns: [
{
from: path.join(sourceRootPath, 'assets'),
to: path.join(distRootPath, 'assets')
},
{
from: path.join(sourceRootPath, 'manifest.json'),
to: path.join(distRootPath, 'manifest.json'),
toType: 'file',
},
{
from: path.join(archivePath, "archives.json"),
to: path.join(distRootPath, "archives.json"),
toType: 'file'
},
{
from: path.join(archivePath, "archives"),
to: path.join(distRootPath, "archives")
}
]}),
new webpack.DefinePlugin({
'NODE_ENV': JSON.stringify(nodeEnv),
'WEB_BROWSER': JSON.stringify(webBrowser),
}),
// extensionReloader,
],
}
if (nodeEnv === 'production') {
module.exports.plugins.push(new CleanWebpackPlugin({ verbose: true, dry: false }));
}