-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathwebpack.config.js
136 lines (130 loc) · 4.14 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
const CopyWebpackPlugin = require('copy-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const { DefinePlugin } = require('webpack');
const path = require('path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const {
transformManifest,
getBuildEnv,
generateTSCompilerOptionsOverride,
getDefineVariables,
} = require('./build-tools');
const rootDirectory = __dirname;
const buildEnv = getBuildEnv(rootDirectory);
const options = {
mode: buildEnv.NODE_ENV,
entry: {
'app-extension-reload': './src/content/app-extension-reload/index.ts',
'app-google-meet': './src/content/app-google-meet/index.ts',
'app-highlight-to-translate': './src/content/app-highlight-to-translate/index.ts',
'app-live-cc': './src/content/app-live-cc/index.ts',
background: './src/background/index.ts',
popup: './src/popup/index.ts',
offscreen: './src/offscreen/index.ts',
'common-styles': './src/styles/common/app.scss',
'popup-styles': './src/styles/popup/app.scss',
'transcriptions-styles': './src/styles/transcriptions/index.scss',
'app-extension-reload-styles': './src/styles/app-extension-reload/app.scss',
'app-highlight-to-translate-styles': './src/styles/app-highlight-to-translate/app.scss',
'app-meet-live-cc-styles': './src/styles/app-meet-live-cc/app.scss',
'audio-processor': './src/audio/processor.ts',
'audio-interceptor': './src/audio/interceptors/audio.ts',
'transcriptions': './src/transcriptions/index.ts',
},
module: {
rules: [
{
test: /\.(ts|tsx)$/,
use: [
{
loader: 'ts-loader',
options: {
instance: 'MAIN',
configFile: path.resolve(__dirname, 'tsconfig.json'),
context: path.resolve(__dirname),
compilerOptions: generateTSCompilerOptionsOverride(buildEnv),
},
},
],
exclude: /node_modules/,
},
{
test: /\.(js|jsx)$/,
use: [
{
loader: 'source-map-loader',
},
{
loader: 'babel-loader',
},
],
exclude: /node_modules/,
},
{
test: /\.(c|sc|sa)ss$/,
use: [MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader'],
},
], // do not forget to change/install your own TS loader
},
resolve: {
extensions: ['.js', '.ts', '.json'],
alias: {
// use the @config alias to reference the current config file
'@config': path.resolve(__dirname, 'src', 'config', 'index.ts'),
// slighly hacky way to inject config modules at build-time. DO NOT USE outside of config/index.ts.
'~inject-config-js': buildEnv.CONFIG_MODULE_PATH,
},
symlinks: false,
},
plugins: [
// Note: these variables are re-exported in consants.js
new DefinePlugin({
DEFINE_VARIABLES: JSON.stringify(getDefineVariables(buildEnv)),
}),
new CopyWebpackPlugin({
patterns: [
{
from: 'src/manifest.json',
to: buildEnv.BUILD_OUTPUT_PATH,
force: true,
transform: function (contentBuffer) {
return transformManifest(buildEnv, contentBuffer);
},
},
{ from: './src/popup/popup.html' },
{ from: './src/offscreen/offscreen.html' },
{ from: './src/images', to: 'images' },
{ from: './src/fonts', to: 'fonts' },
{ from: './src/locales', to: 'locales' },
{ from: './src/_locales', to: '_locales' },
{ from: './src/transcriptions/index.html', to: 'transcriptions.html' },
],
}),
new MiniCssExtractPlugin({
filename: '[name].css',
chunkFilename: '[id].[contenthash].css',
}),
],
output: {
filename: '[name].bundle.js',
path: `${buildEnv.BUILD_OUTPUT_PATH}`,
clean: true,
},
};
if (process.env.NODE_ENV === 'development') {
options.devtool = 'cheap-module-source-map';
options.optimization = {
minimize: false,
};
} else {
/* PRODUCTION */
options.optimization = {
minimize: true,
minimizer: [
new TerserPlugin({
extractComments: false,
}),
],
};
}
module.exports = options;