@nx/rspack 0.0.0-pr-28218-5048fd1
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/LICENSE +22 -0
- package/README.md +117 -0
- package/executors.json +35 -0
- package/generators.json +31 -0
- package/migrations.json +98 -0
- package/module-federation.d.ts +1 -0
- package/module-federation.js +4 -0
- package/package.json +49 -0
- package/plugin.d.ts +2 -0
- package/plugin.js +6 -0
- package/src/executors/dev-server/dev-server.impl.d.ts +6 -0
- package/src/executors/dev-server/dev-server.impl.js +50 -0
- package/src/executors/dev-server/lib/get-dev-server-config.d.ts +4 -0
- package/src/executors/dev-server/lib/get-dev-server-config.js +69 -0
- package/src/executors/dev-server/lib/serve-path.d.ts +3 -0
- package/src/executors/dev-server/lib/serve-path.js +44 -0
- package/src/executors/dev-server/schema.d.ts +12 -0
- package/src/executors/dev-server/schema.json +45 -0
- package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.d.ts +6 -0
- package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.js +177 -0
- package/src/executors/module-federation-dev-server/schema.d.ts +18 -0
- package/src/executors/module-federation-dev-server/schema.json +98 -0
- package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.d.ts +21 -0
- package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.js +214 -0
- package/src/executors/module-federation-ssr-dev-server/schema.json +79 -0
- package/src/executors/module-federation-static-server/module-federation-static-server.impl.d.ts +12 -0
- package/src/executors/module-federation-static-server/module-federation-static-server.impl.js +244 -0
- package/src/executors/module-federation-static-server/schema.d.ts +3 -0
- package/src/executors/module-federation-static-server/schema.json +14 -0
- package/src/executors/rspack/rspack.impl.d.ts +6 -0
- package/src/executors/rspack/rspack.impl.js +118 -0
- package/src/executors/rspack/schema.d.ts +34 -0
- package/src/executors/rspack/schema.json +177 -0
- package/src/executors/ssr-dev-server/lib/wait-until-server-is-listening.d.ts +1 -0
- package/src/executors/ssr-dev-server/lib/wait-until-server-is-listening.js +39 -0
- package/src/executors/ssr-dev-server/schema.d.ts +11 -0
- package/src/executors/ssr-dev-server/schema.json +36 -0
- package/src/executors/ssr-dev-server/ssr-dev-server.impl.d.ts +8 -0
- package/src/executors/ssr-dev-server/ssr-dev-server.impl.js +38 -0
- package/src/generators/application/application.d.ts +3 -0
- package/src/generators/application/application.js +90 -0
- package/src/generators/application/lib/create-ts-config.d.ts +3 -0
- package/src/generators/application/lib/create-ts-config.js +49 -0
- package/src/generators/application/lib/normalize-options.d.ts +5 -0
- package/src/generators/application/lib/normalize-options.js +42 -0
- package/src/generators/application/schema.d.ts +16 -0
- package/src/generators/application/schema.json +98 -0
- package/src/generators/configuration/configuration.d.ts +4 -0
- package/src/generators/configuration/configuration.js +79 -0
- package/src/generators/configuration/schema.d.ts +12 -0
- package/src/generators/configuration/schema.json +73 -0
- package/src/generators/init/init.d.ts +5 -0
- package/src/generators/init/init.js +71 -0
- package/src/generators/init/schema.d.ts +11 -0
- package/src/generators/init/schema.json +31 -0
- package/src/generators/preset/preset.d.ts +3 -0
- package/src/generators/preset/preset.js +34 -0
- package/src/generators/preset/schema.d.ts +18 -0
- package/src/generators/preset/schema.json +71 -0
- package/src/index.d.ts +6 -0
- package/src/index.js +9 -0
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.d.ts +2 -0
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +9 -0
- package/src/plugins/generate-package-json-plugin.d.ts +12 -0
- package/src/plugins/generate-package-json-plugin.js +46 -0
- package/src/plugins/plugin.d.ts +9 -0
- package/src/plugins/plugin.js +149 -0
- package/src/utils/config.d.ts +17 -0
- package/src/utils/config.js +22 -0
- package/src/utils/create-compiler.d.ts +7 -0
- package/src/utils/create-compiler.js +33 -0
- package/src/utils/generator-utils.d.ts +34 -0
- package/src/utils/generator-utils.js +444 -0
- package/src/utils/get-copy-patterns.d.ts +9 -0
- package/src/utils/get-copy-patterns.js +22 -0
- package/src/utils/jest-utils.d.ts +1 -0
- package/src/utils/jest-utils.js +8 -0
- package/src/utils/mode-utils.d.ts +2 -0
- package/src/utils/mode-utils.js +6 -0
- package/src/utils/model.d.ts +6 -0
- package/src/utils/model.js +2 -0
- package/src/utils/module-federation/build-static.remotes.d.ts +4 -0
- package/src/utils/module-federation/build-static.remotes.js +69 -0
- package/src/utils/module-federation/dependencies.d.ts +6 -0
- package/src/utils/module-federation/dependencies.js +56 -0
- package/src/utils/module-federation/get-remotes-for-host.d.ts +16 -0
- package/src/utils/module-federation/get-remotes-for-host.js +99 -0
- package/src/utils/module-federation/index.d.ts +6 -0
- package/src/utils/module-federation/index.js +9 -0
- package/src/utils/module-federation/models/index.d.ts +47 -0
- package/src/utils/module-federation/models/index.js +2 -0
- package/src/utils/module-federation/package-json.d.ts +8 -0
- package/src/utils/module-federation/package-json.js +12 -0
- package/src/utils/module-federation/parse-static-remotes-config.d.ts +13 -0
- package/src/utils/module-federation/parse-static-remotes-config.js +34 -0
- package/src/utils/module-federation/plugins/runtime-library-control.plugin.d.ts +3 -0
- package/src/utils/module-federation/plugins/runtime-library-control.plugin.js +54 -0
- package/src/utils/module-federation/public-api.d.ts +8 -0
- package/src/utils/module-federation/public-api.js +20 -0
- package/src/utils/module-federation/remotes.d.ts +19 -0
- package/src/utils/module-federation/remotes.js +77 -0
- package/src/utils/module-federation/secondary-entry-points.d.ts +12 -0
- package/src/utils/module-federation/secondary-entry-points.js +104 -0
- package/src/utils/module-federation/share.d.ts +48 -0
- package/src/utils/module-federation/share.js +235 -0
- package/src/utils/module-federation/start-remote-proxies.d.ts +5 -0
- package/src/utils/module-federation/start-remote-proxies.js +45 -0
- package/src/utils/module-federation/start-ssr-remote-proxies.d.ts +5 -0
- package/src/utils/module-federation/start-ssr-remote-proxies.js +59 -0
- package/src/utils/module-federation/typescript.d.ts +4 -0
- package/src/utils/module-federation/typescript.js +53 -0
- package/src/utils/module-federation/with-module-federation/package-json.d.ts +8 -0
- package/src/utils/module-federation/with-module-federation/package-json.js +12 -0
- package/src/utils/module-federation/with-module-federation/utils.d.ts +12 -0
- package/src/utils/module-federation/with-module-federation/utils.js +76 -0
- package/src/utils/module-federation/with-module-federation/with-module-federation-ssr.d.ts +3 -0
- package/src/utils/module-federation/with-module-federation/with-module-federation-ssr.js +55 -0
- package/src/utils/module-federation/with-module-federation/with-module-federation.d.ts +8 -0
- package/src/utils/module-federation/with-module-federation/with-module-federation.js +70 -0
- package/src/utils/normalize-assets.d.ts +1 -0
- package/src/utils/normalize-assets.js +42 -0
- package/src/utils/read-rspack-options.d.ts +10 -0
- package/src/utils/read-rspack-options.js +37 -0
- package/src/utils/resolve-user-defined-rspack-config.d.ts +3 -0
- package/src/utils/resolve-user-defined-rspack-config.js +38 -0
- package/src/utils/versions.d.ts +21 -0
- package/src/utils/versions.js +24 -0
- package/src/utils/with-nx.d.ts +3 -0
- package/src/utils/with-nx.js +187 -0
- package/src/utils/with-react.d.ts +3 -0
- package/src/utils/with-react.js +69 -0
- package/src/utils/with-web.d.ts +9 -0
- package/src/utils/with-web.js +106 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function normalizeAssets(assets: any[], root: string, sourceRoot: string): any[];
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizeAssets = normalizeAssets;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const fs_1 = require("fs");
|
|
6
|
+
const path_1 = require("path");
|
|
7
|
+
function normalizeAssets(assets, root, sourceRoot) {
|
|
8
|
+
return assets.map((asset) => {
|
|
9
|
+
if (typeof asset === 'string') {
|
|
10
|
+
const assetPath = (0, devkit_1.normalizePath)(asset);
|
|
11
|
+
const resolvedAssetPath = (0, path_1.resolve)(root, assetPath);
|
|
12
|
+
const resolvedSourceRoot = (0, path_1.resolve)(root, sourceRoot);
|
|
13
|
+
if (!resolvedAssetPath.startsWith(resolvedSourceRoot)) {
|
|
14
|
+
throw new Error(`The ${resolvedAssetPath} asset path must start with the project source root: ${sourceRoot}`);
|
|
15
|
+
}
|
|
16
|
+
const isDirectory = (0, fs_1.statSync)(resolvedAssetPath).isDirectory();
|
|
17
|
+
const input = isDirectory
|
|
18
|
+
? resolvedAssetPath
|
|
19
|
+
: (0, path_1.dirname)(resolvedAssetPath);
|
|
20
|
+
const output = (0, path_1.relative)(resolvedSourceRoot, (0, path_1.resolve)(root, input));
|
|
21
|
+
const glob = isDirectory ? '**/*' : (0, path_1.basename)(resolvedAssetPath);
|
|
22
|
+
return {
|
|
23
|
+
input,
|
|
24
|
+
output,
|
|
25
|
+
glob,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
if (asset.output.startsWith('..')) {
|
|
30
|
+
throw new Error('An asset cannot be written to a location outside of the output path.');
|
|
31
|
+
}
|
|
32
|
+
const assetPath = (0, devkit_1.normalizePath)(asset.input);
|
|
33
|
+
const resolvedAssetPath = (0, path_1.resolve)(root, assetPath);
|
|
34
|
+
return {
|
|
35
|
+
...asset,
|
|
36
|
+
input: resolvedAssetPath,
|
|
37
|
+
// Now we remove starting slash to make Webpack place it from the output root.
|
|
38
|
+
output: asset.output.replace(/^\//, ''),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Configuration } from '@rspack/core';
|
|
2
|
+
/**
|
|
3
|
+
* Reads the Rspack options from a give Rspack configuration. The configuration can be:
|
|
4
|
+
* 1. A standard config object
|
|
5
|
+
* 2. A standard function that returns a config object
|
|
6
|
+
* 3. A Nx-specific composable function that takes Nx context, rspack config, and returns the config object.
|
|
7
|
+
*
|
|
8
|
+
* @param rspackConfig
|
|
9
|
+
*/
|
|
10
|
+
export declare function readRspackOptions(rspackConfig: unknown): Promise<Configuration>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readRspackOptions = readRspackOptions;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const config_1 = require("./config");
|
|
6
|
+
/**
|
|
7
|
+
* Reads the Rspack options from a give Rspack configuration. The configuration can be:
|
|
8
|
+
* 1. A standard config object
|
|
9
|
+
* 2. A standard function that returns a config object
|
|
10
|
+
* 3. A Nx-specific composable function that takes Nx context, rspack config, and returns the config object.
|
|
11
|
+
*
|
|
12
|
+
* @param rspackConfig
|
|
13
|
+
*/
|
|
14
|
+
async function readRspackOptions(rspackConfig) {
|
|
15
|
+
let config;
|
|
16
|
+
if ((0, config_1.isNxRspackComposablePlugin)(rspackConfig)) {
|
|
17
|
+
config = await rspackConfig({}, {
|
|
18
|
+
// These values are only used during build-time, so passing stubs here just to read out
|
|
19
|
+
// the returned config object.
|
|
20
|
+
options: {
|
|
21
|
+
root: devkit_1.workspaceRoot,
|
|
22
|
+
projectRoot: '',
|
|
23
|
+
sourceRoot: '',
|
|
24
|
+
},
|
|
25
|
+
context: { root: devkit_1.workspaceRoot, cwd: undefined, isVerbose: false },
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
else if (typeof rspackConfig === 'function') {
|
|
29
|
+
config = await rspackConfig({
|
|
30
|
+
production: true, // we want the production build options
|
|
31
|
+
}, {});
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
config = rspackConfig;
|
|
35
|
+
}
|
|
36
|
+
return config;
|
|
37
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveUserDefinedRspackConfig = resolveUserDefinedRspackConfig;
|
|
4
|
+
const config_utils_1 = require("@nx/devkit/src/utils/config-utils");
|
|
5
|
+
const internal_1 = require("@nx/js/src/internal");
|
|
6
|
+
function resolveUserDefinedRspackConfig(path, tsConfig,
|
|
7
|
+
/** Skip require cache and return latest content */
|
|
8
|
+
reload = false) {
|
|
9
|
+
if (reload) {
|
|
10
|
+
// Clear cache if the path is in the cache
|
|
11
|
+
if (require.cache[path]) {
|
|
12
|
+
// Clear all entries because config may import other modules
|
|
13
|
+
(0, config_utils_1.clearRequireCache)();
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
// Don't transpile non-TS files. This prevents workspaces libs from being registered via tsconfig-paths.
|
|
17
|
+
// There's an issue here with Nx workspace where loading plugins from source (via tsconfig-paths) can lead to errors.
|
|
18
|
+
if (!/\.(ts|mts|cts)$/.test(path)) {
|
|
19
|
+
return require(path);
|
|
20
|
+
}
|
|
21
|
+
const cleanupTranspiler = (0, internal_1.registerTsProject)(tsConfig);
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
23
|
+
const maybeCustomRspackConfig = require(path);
|
|
24
|
+
cleanupTranspiler();
|
|
25
|
+
// If the user provides a configuration in TS file
|
|
26
|
+
// then there are 3 cases for exporing an object. The first one is:
|
|
27
|
+
// `module.exports = { ... }`. And the second one is:
|
|
28
|
+
// `export default { ... }`. The ESM format is compiled into:
|
|
29
|
+
// `{ default: { ... } }`
|
|
30
|
+
// There is also a case of
|
|
31
|
+
// `{ default: { default: { ... } }`
|
|
32
|
+
const customRspackConfig = 'default' in maybeCustomRspackConfig
|
|
33
|
+
? 'default' in maybeCustomRspackConfig.default
|
|
34
|
+
? maybeCustomRspackConfig.default.default
|
|
35
|
+
: maybeCustomRspackConfig.default
|
|
36
|
+
: maybeCustomRspackConfig;
|
|
37
|
+
return customRspackConfig;
|
|
38
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare const rspackCoreVersion = "1.0.5";
|
|
2
|
+
export declare const rspackDevServerVersion = "1.0.5";
|
|
3
|
+
export declare const rspackPluginMinifyVersion = "^0.7.5";
|
|
4
|
+
export declare const rspackPluginReactRefreshVersion = "^1.0.0";
|
|
5
|
+
export declare const lessLoaderVersion = "~11.1.3";
|
|
6
|
+
export declare const reactVersion = "~18.2.0";
|
|
7
|
+
export declare const reactRefreshVersion = "~0.14.0";
|
|
8
|
+
export declare const reactDomVersion = "~18.2.0";
|
|
9
|
+
export declare const typesReactVersion = "~18.0.28";
|
|
10
|
+
export declare const typesReactDomVersion = "~18.0.10";
|
|
11
|
+
export declare const nestjsCommonVersion = "~9.0.0";
|
|
12
|
+
export declare const nestjsCoreVersion = "~9.0.0";
|
|
13
|
+
export declare const nestjsPlatformExpressVersion = "~9.0.0";
|
|
14
|
+
export declare const nestjsMicroservicesVersion = "~9.0.0";
|
|
15
|
+
export declare const lessVersion = "4.1.3";
|
|
16
|
+
export declare const sassVersion = "^1.42.1";
|
|
17
|
+
export declare const stylusVersion = "^0.55.0";
|
|
18
|
+
export declare const eslintPluginImportVersion = "2.27.5";
|
|
19
|
+
export declare const eslintPluginJsxA11yVersion = "6.7.1";
|
|
20
|
+
export declare const eslintPluginReactVersion = "7.32.2";
|
|
21
|
+
export declare const eslintPluginReactHooksVersion = "4.6.0";
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.eslintPluginReactHooksVersion = exports.eslintPluginReactVersion = exports.eslintPluginJsxA11yVersion = exports.eslintPluginImportVersion = exports.stylusVersion = exports.sassVersion = exports.lessVersion = exports.nestjsMicroservicesVersion = exports.nestjsPlatformExpressVersion = exports.nestjsCoreVersion = exports.nestjsCommonVersion = exports.typesReactDomVersion = exports.typesReactVersion = exports.reactDomVersion = exports.reactRefreshVersion = exports.reactVersion = exports.lessLoaderVersion = exports.rspackPluginReactRefreshVersion = exports.rspackPluginMinifyVersion = exports.rspackDevServerVersion = exports.rspackCoreVersion = void 0;
|
|
4
|
+
exports.rspackCoreVersion = '1.0.5';
|
|
5
|
+
exports.rspackDevServerVersion = '1.0.5';
|
|
6
|
+
exports.rspackPluginMinifyVersion = '^0.7.5';
|
|
7
|
+
exports.rspackPluginReactRefreshVersion = '^1.0.0';
|
|
8
|
+
exports.lessLoaderVersion = '~11.1.3';
|
|
9
|
+
exports.reactVersion = '~18.2.0';
|
|
10
|
+
exports.reactRefreshVersion = '~0.14.0';
|
|
11
|
+
exports.reactDomVersion = '~18.2.0';
|
|
12
|
+
exports.typesReactVersion = '~18.0.28';
|
|
13
|
+
exports.typesReactDomVersion = '~18.0.10';
|
|
14
|
+
exports.nestjsCommonVersion = '~9.0.0';
|
|
15
|
+
exports.nestjsCoreVersion = '~9.0.0';
|
|
16
|
+
exports.nestjsPlatformExpressVersion = '~9.0.0';
|
|
17
|
+
exports.nestjsMicroservicesVersion = '~9.0.0';
|
|
18
|
+
exports.lessVersion = '4.1.3';
|
|
19
|
+
exports.sassVersion = '^1.42.1';
|
|
20
|
+
exports.stylusVersion = '^0.55.0';
|
|
21
|
+
exports.eslintPluginImportVersion = '2.27.5';
|
|
22
|
+
exports.eslintPluginJsxA11yVersion = '6.7.1';
|
|
23
|
+
exports.eslintPluginReactVersion = '7.32.2';
|
|
24
|
+
exports.eslintPluginReactHooksVersion = '4.6.0';
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.withNx = withNx;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const core_1 = require("@rspack/core");
|
|
6
|
+
const fs_1 = require("fs");
|
|
7
|
+
const license_webpack_plugin_1 = require("license-webpack-plugin");
|
|
8
|
+
const path = tslib_1.__importStar(require("path"));
|
|
9
|
+
const path_1 = require("path");
|
|
10
|
+
const generate_package_json_plugin_1 = require("../plugins/generate-package-json-plugin");
|
|
11
|
+
const get_copy_patterns_1 = require("./get-copy-patterns");
|
|
12
|
+
const normalize_assets_1 = require("./normalize-assets");
|
|
13
|
+
function withNx(_opts = {}) {
|
|
14
|
+
return function makeConfig(config, { options, context }) {
|
|
15
|
+
const isProd = process.env.NODE_ENV === 'production' || options.mode === 'production';
|
|
16
|
+
const project = context.projectGraph.nodes[context.projectName];
|
|
17
|
+
const sourceRoot = path.join(context.root, project.data.sourceRoot);
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
19
|
+
const tsconfigPaths = require('tsconfig-paths');
|
|
20
|
+
const { paths } = tsconfigPaths.loadConfig(options.tsConfig);
|
|
21
|
+
const alias = Object.keys(paths).reduce((acc, k) => {
|
|
22
|
+
acc[k] = path.join(context.root, paths[k][0]);
|
|
23
|
+
return acc;
|
|
24
|
+
}, {});
|
|
25
|
+
const plugins = config.plugins ?? [];
|
|
26
|
+
if (options.extractLicenses) {
|
|
27
|
+
/**
|
|
28
|
+
* Needed to prevent an issue with Rspack and Workspaces where the
|
|
29
|
+
* workspace's root package.json file is added to the dependency tree
|
|
30
|
+
*/
|
|
31
|
+
let rootPackageJsonName;
|
|
32
|
+
const pathToRootPackageJson = (0, path_1.join)(context.root, 'package.json');
|
|
33
|
+
if ((0, fs_1.existsSync)(pathToRootPackageJson)) {
|
|
34
|
+
try {
|
|
35
|
+
const rootPackageJson = JSON.parse((0, fs_1.readFileSync)(pathToRootPackageJson, 'utf-8'));
|
|
36
|
+
rootPackageJsonName = rootPackageJson.name;
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
// do nothing
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
plugins.push(new license_webpack_plugin_1.LicenseWebpackPlugin({
|
|
43
|
+
stats: {
|
|
44
|
+
warnings: false,
|
|
45
|
+
errors: false,
|
|
46
|
+
},
|
|
47
|
+
outputFilename: `3rdpartylicenses.txt`,
|
|
48
|
+
/**
|
|
49
|
+
* Needed to prevent an issue with Rspack and Workspaces where the
|
|
50
|
+
* workspace's root package.json file is added to the dependency tree
|
|
51
|
+
*/
|
|
52
|
+
excludedPackageTest: (packageName) => {
|
|
53
|
+
if (!rootPackageJsonName) {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
return packageName === rootPackageJsonName;
|
|
57
|
+
},
|
|
58
|
+
}));
|
|
59
|
+
}
|
|
60
|
+
if (options.generatePackageJson) {
|
|
61
|
+
const mainOutputFile = options.main.split('/').pop().split('.')[0] + '.js';
|
|
62
|
+
plugins.push(new generate_package_json_plugin_1.GeneratePackageJsonPlugin({
|
|
63
|
+
tsConfig: options.tsConfig,
|
|
64
|
+
outputFileName: options.outputFileName ?? mainOutputFile,
|
|
65
|
+
}, context));
|
|
66
|
+
}
|
|
67
|
+
plugins.push(new core_1.rspack.CopyRspackPlugin({
|
|
68
|
+
patterns: (0, get_copy_patterns_1.getCopyPatterns)((0, normalize_assets_1.normalizeAssets)(options.assets, context.root, sourceRoot)),
|
|
69
|
+
}));
|
|
70
|
+
plugins.push(new core_1.rspack.ProgressPlugin());
|
|
71
|
+
options.fileReplacements.forEach((item) => {
|
|
72
|
+
alias[item.replace] = item.with;
|
|
73
|
+
});
|
|
74
|
+
const externals = {};
|
|
75
|
+
let externalsType;
|
|
76
|
+
if (options.target === 'node') {
|
|
77
|
+
const projectDeps = context.projectGraph.dependencies[context.projectName];
|
|
78
|
+
for (const dep of Object.values(projectDeps)) {
|
|
79
|
+
const externalNode = context.projectGraph.externalNodes[dep.target];
|
|
80
|
+
if (externalNode) {
|
|
81
|
+
externals[externalNode.data.packageName] =
|
|
82
|
+
externalNode.data.packageName;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
externalsType = 'commonjs';
|
|
86
|
+
}
|
|
87
|
+
const updated = {
|
|
88
|
+
...config,
|
|
89
|
+
target: options.target,
|
|
90
|
+
mode: options.mode,
|
|
91
|
+
entry: {},
|
|
92
|
+
context: (0, path_1.join)(context.root, context.projectGraph.nodes[context.projectName].data.root),
|
|
93
|
+
devtool: options.sourceMap === 'hidden'
|
|
94
|
+
? 'hidden-source-map'
|
|
95
|
+
: options.sourceMap
|
|
96
|
+
? 'source-map'
|
|
97
|
+
: false,
|
|
98
|
+
output: {
|
|
99
|
+
path: path.join(context.root, options.outputPath),
|
|
100
|
+
publicPath: '/',
|
|
101
|
+
filename: isProd && options.target !== 'node'
|
|
102
|
+
? '[name].[contenthash:8].js'
|
|
103
|
+
: '[name].js',
|
|
104
|
+
chunkFilename: isProd && options.target !== 'node'
|
|
105
|
+
? '[name].[contenthash:8].js'
|
|
106
|
+
: '[name].js',
|
|
107
|
+
cssFilename: isProd && options.target !== 'node'
|
|
108
|
+
? '[name].[contenthash:8].css'
|
|
109
|
+
: '[name].css',
|
|
110
|
+
cssChunkFilename: isProd && options.target !== 'node'
|
|
111
|
+
? '[name].[contenthash:8].css'
|
|
112
|
+
: '[name].css',
|
|
113
|
+
assetModuleFilename: isProd && options.target !== 'node'
|
|
114
|
+
? '[name].[contenthash:8][ext]'
|
|
115
|
+
: '[name][ext]',
|
|
116
|
+
},
|
|
117
|
+
devServer: {
|
|
118
|
+
...(config.devServer ?? {}),
|
|
119
|
+
port: config.devServer?.port ?? 4200,
|
|
120
|
+
hot: config.devServer?.hot ?? true,
|
|
121
|
+
},
|
|
122
|
+
module: {
|
|
123
|
+
rules: [
|
|
124
|
+
{
|
|
125
|
+
test: /\.js$/,
|
|
126
|
+
loader: 'builtin:swc-loader',
|
|
127
|
+
exclude: /node_modules/,
|
|
128
|
+
options: {
|
|
129
|
+
jsc: {
|
|
130
|
+
parser: {
|
|
131
|
+
syntax: 'ecmascript',
|
|
132
|
+
},
|
|
133
|
+
externalHelpers: true,
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
type: 'javascript/auto',
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
test: /\.ts$/,
|
|
140
|
+
loader: 'builtin:swc-loader',
|
|
141
|
+
exclude: /node_modules/,
|
|
142
|
+
options: {
|
|
143
|
+
jsc: {
|
|
144
|
+
parser: {
|
|
145
|
+
syntax: 'typescript',
|
|
146
|
+
decorators: true,
|
|
147
|
+
},
|
|
148
|
+
transform: {
|
|
149
|
+
legacyDecorator: true,
|
|
150
|
+
decoratorMetadata: true,
|
|
151
|
+
},
|
|
152
|
+
externalHelpers: true,
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
type: 'javascript/auto',
|
|
156
|
+
},
|
|
157
|
+
],
|
|
158
|
+
},
|
|
159
|
+
plugins: plugins,
|
|
160
|
+
resolve: {
|
|
161
|
+
// There are some issues resolving workspace libs in a monorepo.
|
|
162
|
+
// It looks to be an issue with rspack itself, but will check back after Nx 16 release
|
|
163
|
+
// once I can reproduce a small example repo with rspack only.
|
|
164
|
+
alias,
|
|
165
|
+
// We need to define the extensions that rspack can resolve
|
|
166
|
+
extensions: ['...', '.ts', '.tsx', '.jsx'],
|
|
167
|
+
// tsConfigPath: path.join(context.root, options.tsConfig),
|
|
168
|
+
},
|
|
169
|
+
infrastructureLogging: {
|
|
170
|
+
debug: false,
|
|
171
|
+
},
|
|
172
|
+
externals,
|
|
173
|
+
externalsType,
|
|
174
|
+
stats: {
|
|
175
|
+
colors: true,
|
|
176
|
+
preset: 'normal',
|
|
177
|
+
},
|
|
178
|
+
};
|
|
179
|
+
const mainEntry = options.main
|
|
180
|
+
? options.outputFileName
|
|
181
|
+
? path.parse(options.outputFileName).name
|
|
182
|
+
: 'main'
|
|
183
|
+
: 'main';
|
|
184
|
+
updated.entry[mainEntry] = path.resolve(context.root, options.main);
|
|
185
|
+
return updated;
|
|
186
|
+
};
|
|
187
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.withReact = withReact;
|
|
4
|
+
const with_web_1 = require("./with-web");
|
|
5
|
+
function withReact(opts = {}) {
|
|
6
|
+
return function makeConfig(config, { options, context }) {
|
|
7
|
+
const isDev = process.env.NODE_ENV === 'development' || options.mode === 'development';
|
|
8
|
+
config = (0, with_web_1.withWeb)({ ...opts, cssModules: true })(config, {
|
|
9
|
+
options,
|
|
10
|
+
context,
|
|
11
|
+
});
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
13
|
+
const ReactRefreshPlugin = require('@rspack/plugin-react-refresh');
|
|
14
|
+
const react = {
|
|
15
|
+
runtime: 'automatic',
|
|
16
|
+
development: isDev,
|
|
17
|
+
refresh: isDev,
|
|
18
|
+
};
|
|
19
|
+
return {
|
|
20
|
+
...config,
|
|
21
|
+
plugins: [
|
|
22
|
+
...(config.plugins || []),
|
|
23
|
+
isDev && new ReactRefreshPlugin(),
|
|
24
|
+
].filter(Boolean),
|
|
25
|
+
module: {
|
|
26
|
+
...config.module,
|
|
27
|
+
rules: [
|
|
28
|
+
...(config.module.rules || []),
|
|
29
|
+
{
|
|
30
|
+
test: /\.jsx$/,
|
|
31
|
+
loader: 'builtin:swc-loader',
|
|
32
|
+
exclude: /node_modules/,
|
|
33
|
+
options: {
|
|
34
|
+
jsc: {
|
|
35
|
+
parser: {
|
|
36
|
+
syntax: 'ecmascript',
|
|
37
|
+
jsx: true,
|
|
38
|
+
},
|
|
39
|
+
transform: {
|
|
40
|
+
react,
|
|
41
|
+
},
|
|
42
|
+
externalHelpers: true,
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
type: 'javascript/auto',
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
test: /\.tsx$/,
|
|
49
|
+
loader: 'builtin:swc-loader',
|
|
50
|
+
exclude: /node_modules/,
|
|
51
|
+
options: {
|
|
52
|
+
jsc: {
|
|
53
|
+
parser: {
|
|
54
|
+
syntax: 'typescript',
|
|
55
|
+
tsx: true,
|
|
56
|
+
},
|
|
57
|
+
transform: {
|
|
58
|
+
react,
|
|
59
|
+
},
|
|
60
|
+
externalHelpers: true,
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
type: 'javascript/auto',
|
|
64
|
+
},
|
|
65
|
+
],
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Configuration } from '@rspack/core';
|
|
2
|
+
import { SharedConfigContext } from './model';
|
|
3
|
+
export interface WithWebOptions {
|
|
4
|
+
stylePreprocessorOptions?: {
|
|
5
|
+
includePaths?: string[];
|
|
6
|
+
};
|
|
7
|
+
cssModules?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare function withWeb(opts?: WithWebOptions): (config: Configuration, { options, context }: SharedConfigContext) => Configuration;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.withWeb = withWeb;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const core_1 = require("@rspack/core");
|
|
6
|
+
const path = tslib_1.__importStar(require("path"));
|
|
7
|
+
function withWeb(opts = {}) {
|
|
8
|
+
return function makeConfig(config, { options, context }) {
|
|
9
|
+
const isProd = process.env.NODE_ENV === 'production' || options.mode === 'production';
|
|
10
|
+
const projectRoot = path.join(context.root, context.projectGraph.nodes[context.projectName].data.root);
|
|
11
|
+
const includePaths = [];
|
|
12
|
+
if (opts?.stylePreprocessorOptions?.includePaths?.length > 0) {
|
|
13
|
+
opts.stylePreprocessorOptions.includePaths.forEach((includePath) => includePaths.push(path.resolve(context.root, includePath)));
|
|
14
|
+
}
|
|
15
|
+
let lessPathOptions = {};
|
|
16
|
+
if (includePaths.length > 0) {
|
|
17
|
+
lessPathOptions = {
|
|
18
|
+
paths: includePaths,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
...config,
|
|
23
|
+
experiments: {
|
|
24
|
+
css: true,
|
|
25
|
+
},
|
|
26
|
+
module: {
|
|
27
|
+
...config.module,
|
|
28
|
+
rules: [
|
|
29
|
+
...(config.module.rules || []),
|
|
30
|
+
{
|
|
31
|
+
test: /\.css$/,
|
|
32
|
+
type: opts?.cssModules ? 'css/module' : undefined,
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
test: /\.css$/,
|
|
36
|
+
type: 'css',
|
|
37
|
+
use: [
|
|
38
|
+
{
|
|
39
|
+
loader: require.resolve('postcss-loader'),
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
test: /\.scss$|\.sass$/,
|
|
45
|
+
type: opts?.cssModules ? 'css/module' : undefined,
|
|
46
|
+
use: [
|
|
47
|
+
{
|
|
48
|
+
loader: require.resolve('sass-loader'),
|
|
49
|
+
options: {
|
|
50
|
+
sourceMap: !!options.sourceMap,
|
|
51
|
+
sassOptions: {
|
|
52
|
+
fiber: false,
|
|
53
|
+
// bootstrap-sass requires a minimum precision of 8
|
|
54
|
+
precision: 8,
|
|
55
|
+
includePaths,
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
test: /.less$/,
|
|
63
|
+
type: opts?.cssModules ? 'css/module' : undefined,
|
|
64
|
+
use: [
|
|
65
|
+
{
|
|
66
|
+
loader: require.resolve('less-loader'),
|
|
67
|
+
options: {
|
|
68
|
+
sourceMap: !!options.sourceMap,
|
|
69
|
+
lessOptions: {
|
|
70
|
+
javascriptEnabled: true,
|
|
71
|
+
...lessPathOptions,
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
],
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
test: /\.styl$/,
|
|
79
|
+
use: [
|
|
80
|
+
{
|
|
81
|
+
loader: require.resolve('stylus-loader'),
|
|
82
|
+
options: {
|
|
83
|
+
sourceMap: !!options.sourceMap,
|
|
84
|
+
stylusOptions: {
|
|
85
|
+
include: includePaths,
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
],
|
|
90
|
+
},
|
|
91
|
+
].filter((a) => !!a),
|
|
92
|
+
},
|
|
93
|
+
plugins: [
|
|
94
|
+
...config.plugins,
|
|
95
|
+
new core_1.rspack.HtmlRspackPlugin({
|
|
96
|
+
template: options.indexHtml
|
|
97
|
+
? path.join(context.root, options.indexHtml)
|
|
98
|
+
: path.join(projectRoot, 'src/index.html'),
|
|
99
|
+
}),
|
|
100
|
+
new core_1.rspack.DefinePlugin({
|
|
101
|
+
'process.env.NODE_ENV': isProd ? "'production'" : "'development'",
|
|
102
|
+
}),
|
|
103
|
+
],
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
}
|