-
Notifications
You must be signed in to change notification settings - Fork 560
/
webpack.config.js
173 lines (167 loc) · 4.87 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
172
173
const autoprefixer = require('autoprefixer');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const spawnSync = require('child_process').spawnSync;
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');
const NodePolyfillPlugin = require('node-polyfill-webpack-plugin');
const fs = require('fs');
function readConfig() {
const configPath = fs.existsSync('./config-local.json')
? './config-local.json'
: './config.json';
try {
const config = fs.readFileSync(configPath, 'utf8');
return JSON.parse(config);
} catch (e) {
// eslint-disable-next-line no-console
console.error(
`Could not load the required configuration file.\n` +
'Please consult the project README.md for further information.'
);
throw e;
}
}
function getConfig() {
var config = readConfig();
var pkg = require('./package.json');
config.version = pkg.version;
return config;
}
module.exports = () => {
const isDevMode = process.env.NODE_ENV === 'development';
const config = getConfig();
return {
context: __dirname + '/lib',
mode: isDevMode ? 'development' : 'production',
devtool:
process.env.SOURCEMAP || (isDevMode && 'eval-cheap-module-source-map'),
entry: ['./boot'],
output: {
filename: 'app.[fullhash].js',
chunkFilename: '[name].[chunkhash].js',
...(config.is_app_engine && {
publicPath: config.web_app_url + '/',
}),
},
// target: 'browserslist', // this seems like it should be "node" or "electron-renderer" but those both crash
module: {
rules: [
{
test: /\.[jt]sx?$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
},
],
},
{
test: /\.(sa|sc|c)ss$/,
use: [
isDevMode ? 'style-loader' : MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
sourceMap: isDevMode,
},
},
{
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: [autoprefixer()],
},
sourceMap: isDevMode,
},
},
{
loader: 'sass-loader',
options: {
sassOptions: {
includePaths: [__dirname + '/lib'],
},
sourceMap: isDevMode,
},
},
],
},
{
test: /\.ttf$/,
type: 'asset/resource',
},
],
},
resolve: {
extensions: ['.js', '.jsx', '.json', '.scss', '.css', '.ts', '.tsx'],
modules: ['node_modules'],
},
plugins: [
new NodePolyfillPlugin({
includeAliases: [
'Buffer',
'buffer',
'path',
'process',
'stream',
'util',
],
}),
new HtmlWebpackPlugin({
'build-platform': process.platform,
'build-reference': spawnSync('git', ['describe', '--always', '--dirty'])
.stdout.toString('utf8')
.replace('\n', ''),
favicon: process.cwd() + '/resources/images/favicon.ico',
'node-version': process.version,
template: 'index.ejs',
title: 'Simplenote',
}),
new MiniCssExtractPlugin({
filename: isDevMode ? '[name].css' : '[name].[fullhash].css',
chunkFilename: isDevMode ? '[id].css' : '[id].[fullhash].css',
}),
new MonacoWebpackPlugin({
languages: [],
// don't include features we disable. these generally correspond to the options
// passed to editor initialization in note-content-editor.tsx
// @see https://github.com/microsoft/monaco-editor/blob/main/webpack-plugin/README.md#options
features: [
'!bracketMatching',
'!codeAction',
'!codelens',
'!colorPicker',
'!comment',
'!diffEditor',
'!diffEditorBreadcrumbs',
'!folding',
'!gotoError',
'!gotoLine',
'!gotoSymbol',
'!gotoZoom',
'!inspectTokens',
'!multicursor',
'!parameterHints',
'!quickCommand',
'!quickHelp',
'!quickOutline',
'!referenceSearch',
'!rename',
'!snippet',
'!stickyScroll',
'!suggest',
'!toggleHighContrast',
'!unicodeHighlighter',
],
}),
new webpack.DefinePlugin({
__TEST__: JSON.stringify(process.env.NODE_ENV === 'test'),
config: JSON.stringify(config),
}),
new webpack.IgnorePlugin({
resourceRegExp: /^\.\/locale$/,
contextRegExp: /moment$/,
}),
],
};
};