@sleeperhq/mini-core 4.0.1 → 4.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/build_mini.js +28 -9
- package/mini_packages.json +1 -1
- package/package.json +1 -1
- package/webpack.config.js +325 -0
package/bin/build_mini.js
CHANGED
|
@@ -5,10 +5,11 @@ const os = require('os');
|
|
|
5
5
|
const path = require('path');
|
|
6
6
|
const readLine = require('readline');
|
|
7
7
|
const fs = require('fs');
|
|
8
|
+
const yargs = require('yargs');
|
|
8
9
|
|
|
9
10
|
const isWindows = os.platform() === 'win32';
|
|
10
11
|
|
|
11
|
-
const getCommands = (projectName) => {
|
|
12
|
+
const getCommands = (projectName, useWebpack = false) => {
|
|
12
13
|
// Pathing
|
|
13
14
|
const distPath = path.join('dist', projectName);
|
|
14
15
|
const zipFilePath = `${distPath}.zip`;
|
|
@@ -26,6 +27,9 @@ const getCommands = (projectName) => {
|
|
|
26
27
|
};
|
|
27
28
|
const reactNativeCliPath = path.join('node_modules', 'react-native', 'cli.js');
|
|
28
29
|
|
|
30
|
+
// Choose config file based on useWebpack flag
|
|
31
|
+
const configFile = useWebpack ? 'webpack.config.js' : 'rspack.config.js';
|
|
32
|
+
|
|
29
33
|
// Commands
|
|
30
34
|
const removeDir = (isWindows ? 'rmdir /s /q ' : 'rm -rf ');
|
|
31
35
|
// TODO (Windows): double check this zip command.
|
|
@@ -47,7 +51,7 @@ const getCommands = (projectName) => {
|
|
|
47
51
|
--sourcemap-output "${sourcemapOutputPath[platform]}" \
|
|
48
52
|
--minify true \
|
|
49
53
|
--assets-dest "${assetsDestPath[platform]}" \
|
|
50
|
-
--webpackConfig ./node_modules/@sleeperhq/mini-core
|
|
54
|
+
--webpackConfig ./node_modules/@sleeperhq/mini-core/${configFile}`;
|
|
51
55
|
};
|
|
52
56
|
|
|
53
57
|
// Exposed
|
|
@@ -88,15 +92,15 @@ const spawnProcess = (command, errorMessage) => {
|
|
|
88
92
|
};
|
|
89
93
|
|
|
90
94
|
const printError = (error) => {
|
|
91
|
-
console.error("\n\
|
|
95
|
+
console.error("\n\x1b[91m" + error + "\x1b[0m");
|
|
92
96
|
};
|
|
93
97
|
|
|
94
98
|
const printInfo = (message) => {
|
|
95
|
-
console.log("\n\
|
|
99
|
+
console.log("\n\x1b[96m" + message + "\x1b[0m");
|
|
96
100
|
};
|
|
97
101
|
|
|
98
102
|
const printComplete = (message) => {
|
|
99
|
-
console.log("\
|
|
103
|
+
console.log("\x1b[92m" + message + "\x1b[0m");
|
|
100
104
|
};
|
|
101
105
|
|
|
102
106
|
const getInput = (message, fallback) => {
|
|
@@ -106,7 +110,7 @@ const getInput = (message, fallback) => {
|
|
|
106
110
|
});
|
|
107
111
|
|
|
108
112
|
return new Promise((resolve) => {
|
|
109
|
-
interface.question("\n\
|
|
113
|
+
interface.question("\n\x1b[96m[current: " + fallback + "]\x1b[0m " + message, (name) => {
|
|
110
114
|
const result = name.trim();
|
|
111
115
|
if (!result) {
|
|
112
116
|
resolve(fallback);
|
|
@@ -136,7 +140,11 @@ const validateProjectName = (name) => {
|
|
|
136
140
|
return regex.test(name);
|
|
137
141
|
}
|
|
138
142
|
|
|
139
|
-
const main = async () => {
|
|
143
|
+
const main = async (useWebpack = false) => {
|
|
144
|
+
// Print configuration info
|
|
145
|
+
const configType = useWebpack ? 'webpack' : 'rspack';
|
|
146
|
+
printInfo(`Using ${configType} configuration`);
|
|
147
|
+
|
|
140
148
|
// Enter project name.
|
|
141
149
|
const fallback = getProjectName();
|
|
142
150
|
const projectName = await getInput("Enter project name (return to skip): ", fallback);
|
|
@@ -150,7 +158,7 @@ const main = async () => {
|
|
|
150
158
|
setProjectName(projectName);
|
|
151
159
|
}
|
|
152
160
|
|
|
153
|
-
const commands = getCommands(projectName);
|
|
161
|
+
const commands = getCommands(projectName, useWebpack);
|
|
154
162
|
|
|
155
163
|
const shouldClean = await getInput("Clean and rebuild project? (y/n): ", 'y');
|
|
156
164
|
if (shouldClean === 'y') {
|
|
@@ -186,4 +194,15 @@ const main = async () => {
|
|
|
186
194
|
process.exit(0);
|
|
187
195
|
};
|
|
188
196
|
|
|
189
|
-
|
|
197
|
+
// Set up command line arguments
|
|
198
|
+
const argv = yargs(process.argv.slice(2))
|
|
199
|
+
.option('webpack', {
|
|
200
|
+
alias: 'w',
|
|
201
|
+
type: 'boolean',
|
|
202
|
+
description: 'Use webpack configuration instead of rspack',
|
|
203
|
+
default: false,
|
|
204
|
+
})
|
|
205
|
+
.help()
|
|
206
|
+
.alias('help', 'h').argv;
|
|
207
|
+
|
|
208
|
+
main(argv.webpack).catch(console.error);
|
package/mini_packages.json
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"@react-navigation/native": "6.1.17",
|
|
20
20
|
"@react-navigation/stack": "6.4.0",
|
|
21
21
|
"@shopify/flash-list": "1.7.6",
|
|
22
|
-
"@sleeperhq/mini-core": "4.0.
|
|
22
|
+
"@sleeperhq/mini-core": "4.0.3",
|
|
23
23
|
"amazon-cognito-identity-js": "6.3.2",
|
|
24
24
|
"crypto-js": "3.3.0",
|
|
25
25
|
"decimal.js-light": "2.5.1",
|
package/package.json
CHANGED
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const TerserPlugin = require('../../../node_modules/terser-webpack-plugin');
|
|
3
|
+
const Repack = require('../../../node_modules/@callstack/repack');
|
|
4
|
+
const config = require('../../../app.json');
|
|
5
|
+
const {dependencies} = require('../../../package.json');
|
|
6
|
+
const {RebuildNotifyPlugin} = require('./src/plugins/rebuildNotifyPlugin')
|
|
7
|
+
|
|
8
|
+
const {samples, selectedSample} = config;
|
|
9
|
+
const sampleClassPath = `../../../src/${samples[selectedSample]}`;
|
|
10
|
+
const sampleClassPathLocal = `./src/${samples[selectedSample]}`
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* More documentation, installation, usage, motivation and differences with Metro is available at:
|
|
14
|
+
* https://github.com/callstack/repack/blob/main/README.md
|
|
15
|
+
*
|
|
16
|
+
* The API documentation for the functions and plugins used in this file is available at:
|
|
17
|
+
* https://re-pack.netlify.app/
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Webpack configuration.
|
|
22
|
+
* You can also export a static object or a function returning a Promise.
|
|
23
|
+
*
|
|
24
|
+
* @param env Environment options passed from either Webpack CLI or React Native CLI
|
|
25
|
+
* when running with `react-native start/bundle`.
|
|
26
|
+
*/
|
|
27
|
+
module.exports = env => {
|
|
28
|
+
const {
|
|
29
|
+
mode = 'development',
|
|
30
|
+
context = path.resolve(__dirname, '..', '..', '..'),
|
|
31
|
+
entry = './node_modules/@sleeperhq/mini-core/start.tsx',
|
|
32
|
+
platform,
|
|
33
|
+
minimize = mode === 'production',
|
|
34
|
+
devServer = undefined,
|
|
35
|
+
bundleFilename = undefined,
|
|
36
|
+
sourceMapFilename = undefined,
|
|
37
|
+
assetsPath = undefined,
|
|
38
|
+
reactNativePath = require.resolve('react-native'),
|
|
39
|
+
} = env;
|
|
40
|
+
|
|
41
|
+
if (!platform) {
|
|
42
|
+
throw new Error('Missing platform');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const dev = mode === 'development';
|
|
46
|
+
|
|
47
|
+
const sharedDeps = Object.keys(dependencies).reduce((acc, key) => {
|
|
48
|
+
acc[key] = { eager: dev, requiredVersion: dependencies[key] };
|
|
49
|
+
return acc;
|
|
50
|
+
}, {});
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Using Module Federation might require disabling hmr.
|
|
54
|
+
* Uncomment below to set `devServer.hmr` to `false`.
|
|
55
|
+
*
|
|
56
|
+
* Keep in mind that `devServer` object is not available
|
|
57
|
+
* when running `webpack-bundle` command. Be sure
|
|
58
|
+
* to check its value to avoid accessing undefined value,
|
|
59
|
+
* otherwise an error might occur.
|
|
60
|
+
*/
|
|
61
|
+
// if (devServer) {
|
|
62
|
+
// devServer.hmr = false;
|
|
63
|
+
// }
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Depending on your Babel configuration you might want to keep it.
|
|
67
|
+
* If you don't use `env` in your Babel config, you can remove it.
|
|
68
|
+
*
|
|
69
|
+
* Keep in mind that if you remove it you should set `BABEL_ENV` or `NODE_ENV`
|
|
70
|
+
* to `development` or `production`. Otherwise your production code might be compiled with
|
|
71
|
+
* in development mode by Babel.
|
|
72
|
+
*/
|
|
73
|
+
process.env.BABEL_ENV = mode;
|
|
74
|
+
|
|
75
|
+
return {
|
|
76
|
+
mode,
|
|
77
|
+
/**
|
|
78
|
+
* This should be always `false`, since the Source Map configuration is done
|
|
79
|
+
* by `SourceMapDevToolPlugin`.
|
|
80
|
+
*/
|
|
81
|
+
devtool: 'source-map',
|
|
82
|
+
context,
|
|
83
|
+
entry,
|
|
84
|
+
resolve: {
|
|
85
|
+
/**
|
|
86
|
+
* `getResolveOptions` returns additional resolution configuration for React Native.
|
|
87
|
+
* If it's removed, you won't be able to use `<file>.<platform>.<ext>` (eg: `file.ios.js`)
|
|
88
|
+
* convention and some 3rd-party libraries that specify `react-native` field
|
|
89
|
+
* in their `package.json` might not work correctly.
|
|
90
|
+
*/
|
|
91
|
+
...Repack.getResolveOptions(platform),
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Uncomment this to ensure all `react-native*` imports will resolve to the same React Native
|
|
95
|
+
* dependency. You might need it when using workspaces/monorepos or unconventional project
|
|
96
|
+
* structure. For simple/typical project you won't need it.
|
|
97
|
+
*/
|
|
98
|
+
// alias: {
|
|
99
|
+
// 'react-native': reactNativePath,
|
|
100
|
+
// },
|
|
101
|
+
alias: {
|
|
102
|
+
app: path.resolve(__dirname, sampleClassPath),
|
|
103
|
+
root: path.resolve(__dirname, '..', '..', '..'),
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
/**
|
|
107
|
+
* Configures output.
|
|
108
|
+
* It's recommended to leave it as it is unless you know what you're doing.
|
|
109
|
+
* By default Webpack will emit files into the directory specified under `path`. In order for the
|
|
110
|
+
* React Native app use them when bundling the `.ipa`/`.apk`, they need to be copied over with
|
|
111
|
+
* `Repack.OutputPlugin`, which is configured by default inside `Repack.RepackPlugin`.
|
|
112
|
+
*/
|
|
113
|
+
output: {
|
|
114
|
+
clean: true,
|
|
115
|
+
path: path.join(__dirname, '..', '..', '..', 'build', platform),
|
|
116
|
+
filename: dev
|
|
117
|
+
? 'index.bundle'
|
|
118
|
+
: platform === 'android'
|
|
119
|
+
? 'index.android.bundle'
|
|
120
|
+
: 'index.ios.bundle',
|
|
121
|
+
chunkFilename: '[name].chunk.bundle',
|
|
122
|
+
publicPath: Repack.getPublicPath({platform, devServer}),
|
|
123
|
+
uniqueName: config.name,
|
|
124
|
+
},
|
|
125
|
+
/**
|
|
126
|
+
* Configures optimization of the built bundle.
|
|
127
|
+
*/
|
|
128
|
+
optimization: {
|
|
129
|
+
/** Enables minification based on values passed from React Native CLI or from fallback. */
|
|
130
|
+
minimize,
|
|
131
|
+
/** Configure minimizer to process the bundle. */
|
|
132
|
+
minimizer: [
|
|
133
|
+
new TerserPlugin({
|
|
134
|
+
test: /\.(js)?bundle(\?.*)?$/i,
|
|
135
|
+
/**
|
|
136
|
+
* Prevents emitting text file with comments, licenses etc.
|
|
137
|
+
* If you want to gather in-file licenses, feel free to remove this line or configure it
|
|
138
|
+
* differently.
|
|
139
|
+
*/
|
|
140
|
+
extractComments: false,
|
|
141
|
+
terserOptions: {
|
|
142
|
+
format: {
|
|
143
|
+
comments: false,
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
}),
|
|
147
|
+
],
|
|
148
|
+
chunkIds: 'named',
|
|
149
|
+
},
|
|
150
|
+
/**
|
|
151
|
+
* We turn on polling so file updates can be recognized when used with Docker.
|
|
152
|
+
*/
|
|
153
|
+
watchOptions: {
|
|
154
|
+
poll: true,
|
|
155
|
+
aggregateTimeout: 600,
|
|
156
|
+
ignored: '**/node_modules',
|
|
157
|
+
},
|
|
158
|
+
module: {
|
|
159
|
+
/**
|
|
160
|
+
* This rule will process all React Native related dependencies with Babel.
|
|
161
|
+
* If you have a 3rd-party dependency that you need to transpile, you can add it to the
|
|
162
|
+
* `include` list.
|
|
163
|
+
*
|
|
164
|
+
* You can also enable persistent caching with `cacheDirectory` - please refer to:
|
|
165
|
+
* https://github.com/babel/babel-loader#options
|
|
166
|
+
*/
|
|
167
|
+
rules: [
|
|
168
|
+
{
|
|
169
|
+
test: /\.[jt]sx?$/,
|
|
170
|
+
include: [
|
|
171
|
+
/node_modules(.*[/\\])+react/,
|
|
172
|
+
/node_modules(.*[/\\])+@react-native/,
|
|
173
|
+
/node_modules(.*[/\\])+@react-navigation/,
|
|
174
|
+
/node_modules(.*[/\\])+@react-native-community/,
|
|
175
|
+
/node_modules(.*[/\\])+@expo/,
|
|
176
|
+
/node_modules(.*[/\\])+pretty-format/,
|
|
177
|
+
/node_modules(.*[/\\])+metro/,
|
|
178
|
+
/node_modules(.*[/\\])+he/,
|
|
179
|
+
/node_modules(.*[/\\])+abort-controller/,
|
|
180
|
+
/node_modules(.*[/\\])+@callstack\/repack/,
|
|
181
|
+
/node_modules(.*[/\\])+@sleeperhq\/mini-core/,
|
|
182
|
+
],
|
|
183
|
+
use: {
|
|
184
|
+
loader: 'babel-loader',
|
|
185
|
+
options: {
|
|
186
|
+
presets: [
|
|
187
|
+
'@react-native/babel-preset',
|
|
188
|
+
['@babel/preset-typescript', { allowDeclareFields: true }],
|
|
189
|
+
],
|
|
190
|
+
babelrc: false,
|
|
191
|
+
cacheDirectory: true,
|
|
192
|
+
sourceMaps: true,
|
|
193
|
+
},
|
|
194
|
+
},
|
|
195
|
+
},
|
|
196
|
+
/**
|
|
197
|
+
* Here you can adjust loader that will process your files.
|
|
198
|
+
*
|
|
199
|
+
* You can also enable persistent caching with `cacheDirectory` - please refer to:
|
|
200
|
+
* https://github.com/babel/babel-loader#options
|
|
201
|
+
*/
|
|
202
|
+
{
|
|
203
|
+
test: /\.[jt]sx?$/,
|
|
204
|
+
exclude: /node_modules/,
|
|
205
|
+
use: {
|
|
206
|
+
loader: 'babel-loader',
|
|
207
|
+
options: {
|
|
208
|
+
presets: [
|
|
209
|
+
'@react-native/babel-preset',
|
|
210
|
+
['@babel/preset-typescript', { allowDeclareFields: true }],
|
|
211
|
+
],
|
|
212
|
+
// sourceType: "unambiguous",
|
|
213
|
+
plugins: devServer && devServer.hmr
|
|
214
|
+
? ['@babel/plugin-transform-runtime', 'module:react-refresh/babel']
|
|
215
|
+
: ['@babel/plugin-transform-runtime'],
|
|
216
|
+
babelrc: false,
|
|
217
|
+
comments: true, // necessary for named chunks
|
|
218
|
+
cacheDirectory: true,
|
|
219
|
+
sourceMaps: true,
|
|
220
|
+
},
|
|
221
|
+
},
|
|
222
|
+
},
|
|
223
|
+
dev && {
|
|
224
|
+
test: /\.[jt]sx?$/,
|
|
225
|
+
include: /src/,
|
|
226
|
+
loader: 'string-replace-loader',
|
|
227
|
+
options: {
|
|
228
|
+
search: 'console.log',
|
|
229
|
+
replace: 'log_mini',
|
|
230
|
+
}
|
|
231
|
+
},
|
|
232
|
+
/**
|
|
233
|
+
* This loader handles all static assets (images, video, audio and others), so that you can
|
|
234
|
+
* use (reference) them inside your application.
|
|
235
|
+
*
|
|
236
|
+
* If you wan to handle specific asset type manually, filter out the extension
|
|
237
|
+
* from `ASSET_EXTENSIONS`, for example:
|
|
238
|
+
* ```
|
|
239
|
+
* Repack.ASSET_EXTENSIONS.filter((ext) => ext !== 'svg')
|
|
240
|
+
* ```
|
|
241
|
+
*/
|
|
242
|
+
{
|
|
243
|
+
test: Repack.getAssetExtensionsRegExp(Repack.SCALABLE_ASSETS),
|
|
244
|
+
use: {
|
|
245
|
+
loader: '@callstack/repack/assets-loader',
|
|
246
|
+
options: {
|
|
247
|
+
// In order to support single file bundle uploads through our submission process,
|
|
248
|
+
// we need to encode image dependencies directly into the main bundle file as base64.
|
|
249
|
+
inline: true,
|
|
250
|
+
platform,
|
|
251
|
+
devServerEnabled: Boolean(devServer),
|
|
252
|
+
scalableAssetExtensions: Repack.SCALABLE_ASSETS,
|
|
253
|
+
},
|
|
254
|
+
},
|
|
255
|
+
},
|
|
256
|
+
{
|
|
257
|
+
test: Repack.getAssetExtensionsRegExp(Repack.NON_SCALABLE_ASSETS),
|
|
258
|
+
use: {
|
|
259
|
+
loader: '@callstack/repack/assets-loader',
|
|
260
|
+
options: {
|
|
261
|
+
inline: false, // all other assets must be uploaded separately, as they cannot be inlined.
|
|
262
|
+
platform,
|
|
263
|
+
devServerEnabled: Boolean(devServer),
|
|
264
|
+
scalableAssetExtensions: Repack.SCALABLE_ASSETS,
|
|
265
|
+
},
|
|
266
|
+
},
|
|
267
|
+
},
|
|
268
|
+
].filter(Boolean),
|
|
269
|
+
},
|
|
270
|
+
plugins: [
|
|
271
|
+
/**
|
|
272
|
+
* Configure other required and additional plugins to make the bundle
|
|
273
|
+
* work in React Native and provide good development experience with
|
|
274
|
+
* sensible defaults.
|
|
275
|
+
*
|
|
276
|
+
* `Repack.RepackPlugin` provides some degree of customization, but if you
|
|
277
|
+
* need more control, you can replace `Repack.RepackPlugin` with plugins
|
|
278
|
+
* from `Repack.plugins`.
|
|
279
|
+
*/
|
|
280
|
+
new Repack.RepackPlugin({
|
|
281
|
+
context,
|
|
282
|
+
mode,
|
|
283
|
+
platform,
|
|
284
|
+
devServer,
|
|
285
|
+
output: {
|
|
286
|
+
bundleFilename,
|
|
287
|
+
sourceMapFilename,
|
|
288
|
+
assetsPath,
|
|
289
|
+
},
|
|
290
|
+
extraChunks: [
|
|
291
|
+
{
|
|
292
|
+
include: new RegExp('.*'),
|
|
293
|
+
type: 'remote',
|
|
294
|
+
outputPath: path.join(__dirname, '..', '..', '..', 'dist', config.name, platform),
|
|
295
|
+
},
|
|
296
|
+
],
|
|
297
|
+
listenerIP: config.remoteIP,
|
|
298
|
+
}),
|
|
299
|
+
|
|
300
|
+
new Repack.plugins.ModuleFederationPlugin({
|
|
301
|
+
name: config.name,
|
|
302
|
+
exposes: {
|
|
303
|
+
app: sampleClassPathLocal,
|
|
304
|
+
},
|
|
305
|
+
shared: {
|
|
306
|
+
// Adding this here fixes the named chunks problem.
|
|
307
|
+
// It also makes sure any third party javascript packages are included in the container,
|
|
308
|
+
// not exported to a separate chunk.
|
|
309
|
+
// The only separate chunk is the exposed stuff.
|
|
310
|
+
...sharedDeps,
|
|
311
|
+
// if we don't do the above, then instead each package that is not included in this list will
|
|
312
|
+
// split off into a seperate chunk, and named chunks will break (assume that's a bug that we can fix).
|
|
313
|
+
},
|
|
314
|
+
}),
|
|
315
|
+
|
|
316
|
+
new RebuildNotifyPlugin(config),
|
|
317
|
+
|
|
318
|
+
// new Repack.plugins.ChunksToHermesBytecodePlugin({
|
|
319
|
+
// enabled: !dev,
|
|
320
|
+
// test: /\.(js)?bundle$/,
|
|
321
|
+
// exclude: /index\.bundle$/,
|
|
322
|
+
// }),
|
|
323
|
+
],
|
|
324
|
+
};
|
|
325
|
+
};
|