-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrspack.config.js
More file actions
231 lines (227 loc) · 7.36 KB
/
Copy pathrspack.config.js
File metadata and controls
231 lines (227 loc) · 7.36 KB
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
const path = require('path');
const { rspack } = require('@rspack/core');
const { getAppConfig, getWebBundlePath, getAdConfig } = require('./dev/config');
const StripSourceMapCommentsPlugin = require('./dev/stripSourceMapComments');
module.exports = (env, options) => {
const { mode = 'development' } = options;
const prod = mode === 'production';
const platform = process.env.ACODE_PLATFORM || 'android';
const { variant } = getAppConfig(platform);
const ads = getAdConfig(platform, prod ? 'Release' : 'Debug');
const isDev = process.env.DEV_MODE === 'true';
const devHost = process.env.DEV_HOST || '';
const devPort = process.env.DEV_PORT || '';
const devProto = isDev ? (process.env.DEV_PROTO || '') : '';
const typescriptLoader = {
loader: 'builtin:swc-loader',
options: { jsc: { parser: { syntax: 'typescript', tsx: false }, target: 'es2015' } },
};
const rules = [
{
test: /typescript[\\/]lib[\\/]lib\..*\.d\.ts$/,
type: 'asset/source',
},
// Native APIs are plain TypeScript; only editor sources use the JSX loader.
{
test: /\.tsx?$/,
exclude: /node_modules/,
oneOf: [
{ include: /[\\/]src[\\/](?:native|platforms)[\\/]/, use: [typescriptLoader] },
{ use: [typescriptLoader, path.resolve(__dirname, 'dev/custom-loaders/html-tag-jsx-loader.js')] },
],
},
// JavaScript files
{
test: /\.m?js$/,
oneOf: [
// Node modules - use builtin:swc-loader only
// The codemirror-lsp-client submodule is installed through a "file:"
// dependency, so it resolves to its real path outside node_modules. It
// still ships pre-built code and must not go through the source loaders.
{
include: /[\\/](?:node_modules|codemirror-lsp-client)[\\/]/,
use: [
{
loader: 'builtin:swc-loader',
options: {
jsc: {
parser: {
syntax: 'ecmascript',
},
target: 'es2015',
},
},
},
],
},
// Source JS files - Custom JSX loader + SWC (JSX will be removed first)
{
use: [
{
loader: 'builtin:swc-loader',
options: {
jsc: {
parser: {
syntax: 'ecmascript',
jsx: false,
},
target: 'es2015',
},
},
},
path.resolve(__dirname, 'dev/custom-loaders/html-tag-jsx-loader.js'),
],
},
],
},
// Handlebars and Markdown files
{
test: /\.(hbs|md)$/,
type: 'asset/source',
},
// Module CSS/SCSS (with .m prefix)
{
test: /\.m\.(sa|sc|c)ss$/,
use: [
'raw-loader',
'postcss-loader',
'sass-loader',
],
type: 'javascript/auto',
},
{
test: /\.svg$/,
resourceQuery: /raw/,
type: 'asset/source',
},
{
test: /\.(png|svg|jpg|jpeg|ico|webp)(\?.*)?$/,
resourceQuery: /inline/,
type: 'asset/inline',
},
// Asset files
{
test: /\.(png|svg|jpg|jpeg|ico|ttf|webp|eot|woff|webm|mp4|wav)(\?.*)?$/,
resourceQuery: { not: [/raw/, /inline/] },
type: 'asset/resource',
},
// Regular CSS files do not need Sass processing. Passing icon CSS through
// Sass converts escaped private-use code points into literal characters in
// production, which Android's asset WebView renders as missing glyphs.
{
test: /(?<!\.m)\.css$/,
type: 'javascript/auto',
use: [
rspack.CssExtractRspackPlugin.loader,
'css-loader',
'postcss-loader',
],
},
// Regular Sass/SCSS files
{
test: /\.(?<!\.m\.)(sa|sc)ss$/,
type: 'javascript/auto',
use: [
rspack.CssExtractRspackPlugin.loader,
'css-loader',
'postcss-loader',
'sass-loader',
],
},
];
const main = {
mode,
node: {
__dirname: false,
__filename: false,
},
entry: {
boot: './src/boot.js',
native: './src/native/index.ts',
main: './src/main.js',
console: './src/lib/console.js',
consoleWorker: './src/lib/consoleWorker.js',
searchInFilesWorker: './src/sidebarApps/searchInFiles/worker.js',
searchIndexWorker: './src/sidebarApps/searchInFiles/indexWorker.js',
htmlLspWorker: './src/cm/lsp/workers/html.worker.ts',
cssLspWorker: './src/cm/lsp/workers/css.worker.ts',
jsonLspWorker: './src/cm/lsp/workers/json.worker.ts',
typescriptLspWorker: './src/cm/lsp/workers/typescript.worker.ts',
},
output: {
path: getWebBundlePath(),
filename: 'build/[name].js',
chunkFilename: 'build/[name].chunk.js',
assetModuleFilename: 'build/[name][ext]',
publicPath: 'auto',
clean: !isDev,
},
// TypeScript's Node-only plugin loader uses a dynamic require. It is never
// reached by the browser worker, but Rspack cannot prove that statically.
ignoreWarnings: [
{
module: /typescript[\\/]lib[\\/]typescript\.js$/,
message: /Critical dependency/,
},
],
module: {
rules,
exprContextCritical: false,
parser: {
javascript: {
exportsPresence: 'error',
requireAlias: false,
},
},
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.mjs', '.json'],
fallback: {
path: require.resolve('path-browserify'),
crypto: false,
},
modules: ['node_modules', 'src'],
roots: [],
},
plugins: [
new StripSourceMapCommentsPlugin(),
new rspack.CopyRspackPlugin({
patterns: [
{ from: 'src/index.html', to: 'index.html' },
{ from: 'src/res/logo.svg', to: 'logo.svg' },
{ from: 'src/res/favicon.ico', to: 'favicon.ico' },
{ from: 'src/res/icons/*.svg', to: 'icons/[name][ext]' },
],
}),
...(variant === 'paid' ? [new rspack.NormalModuleReplacementPlugin(
/^(?:\.\/|lib\/)(startAd|rewardedAd)(?:\.js)?$/,
(resource) => {
const name = path.basename(resource.request).replace(/\.js$/, '');
resource.request = path.resolve(__dirname, 'src/lib/paid', `${name}.js`);
},
)] : []),
new rspack.DefinePlugin({
__FREE__: JSON.stringify(variant === 'free'),
IS_IOS: JSON.stringify(platform === 'ios'),
IS_ANDROID: JSON.stringify(platform === 'android'),
PLATFORM: JSON.stringify(platform),
ADMOB_APP_ID: JSON.stringify(ads.appId),
ADMOB_BANNER_ID: JSON.stringify(ads.banner),
ADMOB_INTERSTITIAL_ID: JSON.stringify(ads.interstitial),
ADMOB_REWARDED_ID: JSON.stringify(ads.rewarded),
ADMOB_ACADEMY_REWARDED_ID: JSON.stringify(ads.academyRewarded),
ADMOB_ACADEMY_INTERSTITIAL_ID: JSON.stringify(ads.academyInterstitial),
ADMOB_APP_OPEN_ID: JSON.stringify(ads.appOpen),
__FDROID__: JSON.stringify(process.env.ACODE_FDROID === 'true'),
__DEV_MODE__: JSON.stringify(isDev),
__DEV_HOST__: JSON.stringify(devHost),
__DEV_PORT__: JSON.stringify(devPort),
__DEV_PROTO__: JSON.stringify(devProto),
}),
new rspack.CssExtractRspackPlugin({
filename: 'build/[name].css',
}),
],
};
return [main];
};