forked from toolkit-for-ynab/toolkit-for-ynab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
145 lines (135 loc) · 4.21 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
const path = require('path');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const webpack = require('webpack');
const BUILD_ROOT = './dist';
const BUILD_PATH = `${BUILD_ROOT}/extension`;
const CODE_SOURCE_DIR = './src';
module.exports = function (env) {
const validBuildTypes = ['beta', 'development', 'production'];
if (!env || !validBuildTypes.includes(env.buildType)) {
console.log(`Invalid --env.buildType provided. Must be one of: [${validBuildTypes.join('|')}]`);
process.exit(1);
}
const config = {
mode: 'none',
entry: {
'background/background': path.resolve(`${CODE_SOURCE_DIR}/core/background/index.js`),
'options/options': path.resolve(`${CODE_SOURCE_DIR}/core/options/index.tsx`),
'popup/popup': path.resolve(`${CODE_SOURCE_DIR}/core/popup/index.tsx`),
'content-scripts/extension-bridge': path.resolve(
`${CODE_SOURCE_DIR}/core/content-scripts/extension-bridge.js`
),
'web-accessibles/ynab-toolkit': path.resolve(`${CODE_SOURCE_DIR}/extension/index.js`),
},
devtool: env.buildType !== 'production' ? 'inline-source-map' : false,
output: {
path: path.join(__dirname, BUILD_ROOT),
filename: 'extension/[name].js',
},
resolve: {
alias: {
toolkit: path.resolve(__dirname, CODE_SOURCE_DIR),
'toolkit-reports': path.resolve(
__dirname,
path.join(CODE_SOURCE_DIR, 'extension', 'features', 'toolkit-reports')
),
},
extensions: ['.js', '.jsx', '.ts', '.tsx'],
modules: ['node_modules'],
},
module: {
rules: [
{
test: /\.tsx?$/,
exclude: /node_modules/,
include: [path.resolve(__dirname, CODE_SOURCE_DIR)],
use: [
{
loader: 'ts-loader',
},
],
},
{
test: /\.jsx?$/,
exclude: /node_modules/,
include: [path.resolve(__dirname, CODE_SOURCE_DIR)],
use: [
{
loader: 'babel-loader',
},
],
},
{
test: /\.css$/,
include: [path.resolve(__dirname, CODE_SOURCE_DIR)],
use: [
{
loader: 'to-string-loader',
},
{
loader: 'css-loader',
options: {
esModule: false,
},
},
],
},
{
test: /\.scss$/,
use: ['style-loader', 'css-loader', 'sass-loader'],
},
{
test: /\.svg$/,
use: [
{
loader: 'svg-url-loader',
options: {
limit: 10000,
},
},
],
},
],
},
plugins: [
new webpack.ProgressPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(env.buildType),
}),
new CleanWebpackPlugin(),
new CopyWebpackPlugin({
patterns: [
{
from: path.join(__dirname, `${CODE_SOURCE_DIR}/assets/common`),
to: path.join(__dirname, `${BUILD_PATH}/assets`),
},
{
from: path.join(__dirname, `${CODE_SOURCE_DIR}/assets/environment/${env.buildType}`),
to: path.join(__dirname, `${BUILD_PATH}/assets`),
},
{
from: path.join(__dirname, `${CODE_SOURCE_DIR}/manifest.json`),
to: path.join(__dirname, `${BUILD_PATH}`),
},
{
from: path.join(__dirname, `${CODE_SOURCE_DIR}/core/background`),
to: path.join(__dirname, `${BUILD_PATH}/background`),
globOptions: { ignore: '**/*.js' },
},
{
from: path.join(__dirname, `${CODE_SOURCE_DIR}/core/options`),
to: path.join(__dirname, `${BUILD_PATH}/options`),
globOptions: { ignore: '**/*.{js,jsx,ts,tsx}' },
},
{
from: path.join(__dirname, `${CODE_SOURCE_DIR}/core/popup`),
to: path.join(__dirname, `${BUILD_PATH}/popup`),
globOptions: { ignore: '**/*.{js,jsx,ts,tsx}' },
},
],
}),
],
};
return config;
};