@sleeperhq/mini-core 4.0.1 → 4.0.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sleeperhq/mini-core",
3
- "version": "4.0.1",
3
+ "version": "4.0.2",
4
4
  "description": "Core library frameworks for developing Sleeper Mini Apps.",
5
5
  "main": "index.ts",
6
6
  "types": "index.d.ts",
package/rspack.config.js CHANGED
@@ -45,7 +45,13 @@ module.exports = env => {
45
45
  const dev = mode === 'development';
46
46
 
47
47
  const sharedDeps = Object.keys(dependencies).reduce((acc, key) => {
48
- acc[key] = { eager: dev, requiredVersion: dependencies[key] };
48
+ acc[key] = {
49
+ requiredVersion: dependencies[key],
50
+ // Only set eager for development to prevent sync loading issues in production
51
+ eager: dev && (key === 'react' || key === 'react-native'),
52
+ // Only set singleton for critical packages
53
+ ...(key === 'react' || key === 'react-native' ? { singleton: true } : {})
54
+ };
49
55
  return acc;
50
56
  }, {});
51
57
 
@@ -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
+ };