@omnific/react-scripts 0.1.0 → 0.1.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.
@@ -1,285 +0,0 @@
1
- import { a as isProduction, i as isDevelopment, r as getEnv } from "./env-DxzdvROc.js";
2
- import { createRequire } from "node:module";
3
- import { rspack } from "@rspack/core";
4
- import path from "node:path";
5
- import fs, { existsSync } from "node:fs";
6
- import { ReactRefreshRspackPlugin } from "@rspack/plugin-react-refresh";
7
- //#region paths.ts
8
- const appDirectory = fs.realpathSync(process.cwd());
9
- function resolveApp(relativePath) {
10
- return path.resolve(appDirectory, relativePath);
11
- }
12
- var paths_default = {
13
- appSrc: resolveApp("src"),
14
- appPath: resolveApp("."),
15
- appBuild: resolveApp("build"),
16
- appIndexJs: resolveApp("src/index.tsx"),
17
- publicUrlOrPath: isDevelopment() ? "/" : "./",
18
- appHtml: resolveApp("public/index.html"),
19
- appTsConfig: resolveApp("./tsconfig.json"),
20
- appNodeModules: resolveApp("node_modules"),
21
- appPackageJson: resolveApp("package.json"),
22
- appPublic: resolveApp("public"),
23
- config: resolveApp("react-scripts.config")
24
- };
25
- //#endregion
26
- //#region utils/find-entry-file.ts
27
- const fileExtensions = [
28
- "ts",
29
- "mts",
30
- "mjs",
31
- "cjs",
32
- "js"
33
- ];
34
- /**
35
- * Find a file with any of the supported JavaScript extensions
36
- * @param basePath - The base path without extension
37
- * @returns The file path with extension if found, or a default path
38
- */
39
- function findEntryFile(basePath) {
40
- for (const ext of fileExtensions) {
41
- const filePath = `${basePath}.${ext}`;
42
- if (existsSync(filePath)) return filePath;
43
- }
44
- }
45
- //#endregion
46
- //#region config.ts
47
- function isPlainObject(value) {
48
- return typeof value === "object" && value !== null;
49
- }
50
- function createConfigImportError(configPath, error) {
51
- const isTypeScriptConfig = /\.(cts|mts|ts)$/.test(configPath);
52
- const fileName = path.basename(configPath);
53
- return new Error(`Failed to load ${fileName} with native import().${isTypeScriptConfig ? ` Native TypeScript import requires Node.js >= 22.18.0. On older Node.js versions, rename the config file to .mjs or .cjs.` : ""}`, { cause: error });
54
- }
55
- async function loadReactScriptsConfig() {
56
- const configPath = findEntryFile(paths_default.config);
57
- if (!configPath) return {};
58
- let moduleNamespace;
59
- try {
60
- moduleNamespace = await import(configPath);
61
- } catch (error) {
62
- throw createConfigImportError(configPath, error);
63
- }
64
- const config = moduleNamespace.default ?? moduleNamespace;
65
- if (!isPlainObject(config)) throw new TypeError(`${path.basename(configPath)} must export a configuration object.`);
66
- return config;
67
- }
68
- //#endregion
69
- //#region utils/detect-package.ts
70
- const require$1 = createRequire(import.meta.url);
71
- function detectPackage(packageName) {
72
- try {
73
- require$1.resolve(packageName);
74
- return true;
75
- } catch {
76
- return false;
77
- }
78
- }
79
- //#endregion
80
- //#region alias.ts
81
- const moduleFileExtensions = [
82
- "ts",
83
- "tsx",
84
- "js",
85
- "json",
86
- "mjs",
87
- "jsx"
88
- ].map((ext) => `.${ext}`);
89
- const aliasSymbol = {
90
- src: "@",
91
- root: "@app"
92
- };
93
- const alias = {
94
- [aliasSymbol.src]: paths_default.appSrc,
95
- [aliasSymbol.root]: paths_default.appPath
96
- };
97
- //#endregion
98
- //#region rspack.config.ts
99
- const hasJsxRuntime = detectPackage("react/jsx-runtime");
100
- const hasTailwind = detectPackage("tailwindcss");
101
- const hasSwcHelper = detectPackage("@swc/helpers");
102
- const lessRegex = /\.less$/;
103
- const sassRegex = /\.(scss|sass)$/;
104
- const cssRegex = /\.css$/;
105
- const imageInlineSizeLimit = 1e4;
106
- const require = createRequire(import.meta.url);
107
- function resolvePackage(packageName) {
108
- return require.resolve(packageName);
109
- }
110
- async function createRspackConfig() {
111
- const isEnvironmentDevelopment = isDevelopment();
112
- const isEnvironmentProduction = isProduction();
113
- function getStyleLoaders(preProcessor) {
114
- const loaders = [
115
- isEnvironmentProduction && {
116
- loader: rspack.CssExtractRspackPlugin.loader,
117
- options: paths_default.publicUrlOrPath.startsWith(".") ? { publicPath: "../../" } : {}
118
- },
119
- {
120
- loader: "builtin:lightningcss-loader",
121
- /** @type {import('@rspack/core').LightningcssLoaderOptions} */
122
- options: { minify: isEnvironmentProduction }
123
- },
124
- {
125
- loader: resolvePackage("postcss-loader"),
126
- options: hasTailwind ? { postcssOptions: {
127
- ident: "postcss",
128
- config: false,
129
- plugins: [require("@tailwindcss/postcss")]
130
- } } : void 0
131
- }
132
- ].filter(Boolean);
133
- if (preProcessor) loaders.push(preProcessor);
134
- return loaders;
135
- }
136
- const config = {
137
- target: ["browserslist"],
138
- stats: "errors-warnings",
139
- mode: getEnv(),
140
- bail: isEnvironmentProduction,
141
- devtool: isEnvironmentDevelopment && "cheap-module-source-map",
142
- entry: paths_default.appIndexJs,
143
- output: {
144
- path: paths_default.appBuild,
145
- pathinfo: isEnvironmentDevelopment,
146
- filename: isEnvironmentProduction ? "static/js/[name].[contenthash:8].js" : "static/js/[name].js",
147
- chunkFilename: isEnvironmentProduction ? "static/js/[name].[contenthash:8].chunk.js" : "static/js/[name].chunk.js",
148
- assetModuleFilename: "static/media/[name].[hash][ext]",
149
- publicPath: paths_default.publicUrlOrPath,
150
- devtoolModuleFilenameTemplate: isEnvironmentProduction ? (info) => path.relative(paths_default.appSrc, info.absoluteResourcePath).replaceAll("\\", "/") : (info) => path.resolve(info.absoluteResourcePath).replaceAll("\\", "/")
151
- },
152
- infrastructureLogging: { level: "none" },
153
- optimization: {
154
- runtimeChunk: "single",
155
- splitChunks: {
156
- chunks: "async",
157
- minChunks: 1,
158
- minSize: 2e4,
159
- maxAsyncRequests: 30,
160
- maxInitialRequests: 30,
161
- cacheGroups: {
162
- vendors: {
163
- test: /[/\\]node_modules[/\\]/,
164
- name: "chunk-vendors",
165
- priority: -10,
166
- reuseExistingChunk: true
167
- },
168
- default: {
169
- minChunks: 2,
170
- priority: -20,
171
- reuseExistingChunk: true
172
- }
173
- }
174
- },
175
- minimizer: [new rspack.LightningCssMinimizerRspackPlugin(), new rspack.SwcJsMinimizerRspackPlugin({
176
- extractComments: false,
177
- minimizerOptions: {
178
- minify: true,
179
- mangle: true,
180
- ecma: 5,
181
- compress: { passes: 2 },
182
- format: { comments: false }
183
- }
184
- })]
185
- },
186
- resolve: {
187
- extensions: moduleFileExtensions,
188
- alias
189
- },
190
- module: {
191
- rules: [{ oneOf: [
192
- {
193
- test: [/\.avif$/],
194
- type: "asset",
195
- mimetype: "image/avif",
196
- parser: { dataUrlCondition: { maxSize: imageInlineSizeLimit } }
197
- },
198
- {
199
- test: [
200
- /\.bmp$/,
201
- /\.gif$/,
202
- /\.jpe?g$/,
203
- /\.png$/
204
- ],
205
- type: "asset",
206
- parser: { dataUrlCondition: { maxSize: imageInlineSizeLimit } }
207
- },
208
- {
209
- test: /\.[jt]sx?$/,
210
- exclude: [/node_modules/],
211
- use: {
212
- loader: "builtin:swc-loader",
213
- options: {
214
- jsc: {
215
- externalHelpers: hasSwcHelper,
216
- loose: true,
217
- parser: {
218
- syntax: "typescript",
219
- tsx: true
220
- },
221
- transform: { react: {
222
- throwIfNamespace: true,
223
- development: isEnvironmentDevelopment,
224
- useBuiltins: true,
225
- runtime: hasJsxRuntime ? "automatic" : "classic",
226
- refresh: isEnvironmentDevelopment
227
- } }
228
- },
229
- module: { type: "es6" }
230
- }
231
- }
232
- },
233
- {
234
- test: lessRegex,
235
- use: getStyleLoaders({ loader: resolvePackage("less-loader") }),
236
- sideEffects: true,
237
- type: "css/auto"
238
- },
239
- {
240
- test: sassRegex,
241
- use: getStyleLoaders({
242
- loader: resolvePackage("sass-loader"),
243
- options: {
244
- api: "modern-compiler",
245
- implementation: resolvePackage("sass-embedded")
246
- }
247
- }),
248
- sideEffects: true,
249
- type: "css/auto"
250
- },
251
- {
252
- test: cssRegex,
253
- use: getStyleLoaders(),
254
- sideEffects: true,
255
- type: "css/auto"
256
- },
257
- {
258
- exclude: [
259
- /^$/,
260
- /\.(js|mjs|jsx|ts|tsx)$/,
261
- /\.html$/,
262
- /\.json$/
263
- ],
264
- type: "asset/resource"
265
- }
266
- ] }],
267
- parser: { "css/auto": { namedExports: false } }
268
- },
269
- plugins: [
270
- new rspack.HtmlRspackPlugin({
271
- inject: true,
272
- template: paths_default.appHtml,
273
- minify: isEnvironmentProduction
274
- }),
275
- isEnvironmentDevelopment && new rspack.CaseSensitivePlugin(),
276
- isEnvironmentDevelopment && new ReactRefreshRspackPlugin()
277
- ],
278
- performance: false
279
- };
280
- const reactScriptsConfig = await loadReactScriptsConfig();
281
- if (reactScriptsConfig.configureRspack) reactScriptsConfig.configureRspack(config);
282
- return config;
283
- }
284
- //#endregion
285
- export { paths_default as n, createRspackConfig as t };