@razerspine/build 1.0.0

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.
Files changed (80) hide show
  1. package/CHANGELOG.md +750 -0
  2. package/LICENSE +15 -0
  3. package/README.md +232 -0
  4. package/dist/core/config-meta.d.ts +33 -0
  5. package/dist/core/config-meta.js +27 -0
  6. package/dist/core/create-base-config.d.ts +52 -0
  7. package/dist/core/create-base-config.js +180 -0
  8. package/dist/core/create-dev-config.d.ts +18 -0
  9. package/dist/core/create-dev-config.js +68 -0
  10. package/dist/core/create-prod-config.d.ts +12 -0
  11. package/dist/core/create-prod-config.js +56 -0
  12. package/dist/core/define-config.d.ts +67 -0
  13. package/dist/core/define-config.js +81 -0
  14. package/dist/core/index.d.ts +5 -0
  15. package/dist/core/index.js +14 -0
  16. package/dist/hosting/detect-hosting.d.ts +2 -0
  17. package/dist/hosting/detect-hosting.js +14 -0
  18. package/dist/hosting/get-redirects.d.ts +2 -0
  19. package/dist/hosting/get-redirects.js +8 -0
  20. package/dist/hosting/get-vercel-config.d.ts +2 -0
  21. package/dist/hosting/get-vercel-config.js +22 -0
  22. package/dist/index.d.ts +4 -0
  23. package/dist/index.js +27 -0
  24. package/dist/options/index.d.ts +2 -0
  25. package/dist/options/index.js +5 -0
  26. package/dist/options/normalize-options.d.ts +14 -0
  27. package/dist/options/normalize-options.js +38 -0
  28. package/dist/options/resolve-options.d.ts +3 -0
  29. package/dist/options/resolve-options.js +9 -0
  30. package/dist/options/validate-options.d.ts +2 -0
  31. package/dist/options/validate-options.js +28 -0
  32. package/dist/plugins/hosting-routing-plugin.d.ts +12 -0
  33. package/dist/plugins/hosting-routing-plugin.js +54 -0
  34. package/dist/plugins/html-templates-plugin.d.ts +16 -0
  35. package/dist/plugins/html-templates-plugin.js +82 -0
  36. package/dist/plugins/pug-templates-plugin.d.ts +16 -0
  37. package/dist/plugins/pug-templates-plugin.js +90 -0
  38. package/dist/presets/react/index.d.ts +1 -0
  39. package/dist/presets/react/index.js +5 -0
  40. package/dist/presets/react/react-preset.d.ts +66 -0
  41. package/dist/presets/react/react-preset.js +198 -0
  42. package/dist/rules/assets-rule.d.ts +27 -0
  43. package/dist/rules/assets-rule.js +32 -0
  44. package/dist/rules/index.d.ts +4 -0
  45. package/dist/rules/index.js +11 -0
  46. package/dist/rules/pug-rule.d.ts +16 -0
  47. package/dist/rules/pug-rule.js +27 -0
  48. package/dist/rules/scripts-rule.d.ts +15 -0
  49. package/dist/rules/scripts-rule.js +22 -0
  50. package/dist/rules/styles-rule.d.ts +21 -0
  51. package/dist/rules/styles-rule.js +28 -0
  52. package/dist/types/app-type.d.ts +1 -0
  53. package/dist/types/app-type.js +2 -0
  54. package/dist/types/base-webpack-config-type.d.ts +2 -0
  55. package/dist/types/base-webpack-config-type.js +2 -0
  56. package/dist/types/build-plugin-type.d.ts +24 -0
  57. package/dist/types/build-plugin-type.js +2 -0
  58. package/dist/types/config-option-type.d.ts +120 -0
  59. package/dist/types/config-option-type.js +2 -0
  60. package/dist/types/hosting-type.d.ts +1 -0
  61. package/dist/types/hosting-type.js +2 -0
  62. package/dist/types/index.d.ts +9 -0
  63. package/dist/types/index.js +2 -0
  64. package/dist/types/mode-type.d.ts +1 -0
  65. package/dist/types/mode-type.js +2 -0
  66. package/dist/types/script-type.d.ts +1 -0
  67. package/dist/types/script-type.js +2 -0
  68. package/dist/types/style-type.d.ts +1 -0
  69. package/dist/types/style-type.js +2 -0
  70. package/dist/types/templates-type.d.ts +1 -0
  71. package/dist/types/templates-type.js +2 -0
  72. package/dist/utils/dedupe-plugins.d.ts +5 -0
  73. package/dist/utils/dedupe-plugins.js +20 -0
  74. package/dist/utils/dedupe-rules.d.ts +9 -0
  75. package/dist/utils/dedupe-rules.js +27 -0
  76. package/dist/utils/index.d.ts +3 -0
  77. package/dist/utils/index.js +9 -0
  78. package/dist/utils/text-capitalize.d.ts +1 -0
  79. package/dist/utils/text-capitalize.js +6 -0
  80. package/package.json +91 -0
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ /**
3
+ * @module create-prod-config
4
+ * @description Finalizes the configuration for production builds with optimizations.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.createProdConfig = createProdConfig;
8
+ const webpack_merge_1 = require("webpack-merge");
9
+ const hosting_routing_plugin_1 = require("../plugins/hosting-routing-plugin");
10
+ const config_meta_1 = require("./config-meta");
11
+ const dedupe_plugins_1 = require("../utils/dedupe-plugins");
12
+ /**
13
+ * Creates a production configuration with minification and hosting-specific plugins.
14
+ * @param {Configuration} baseConfig - The base configuration from createBaseConfig.
15
+ * @param {Configuration} [options={}] - Additional Webpack overrides for production.
16
+ * @returns {Configuration} The optimized production configuration.
17
+ */
18
+ function createProdConfig(baseConfig, options = {}) {
19
+ var _a, _b;
20
+ const meta = (0, config_meta_1.getConfigMeta)(baseConfig);
21
+ const appType = (_a = meta === null || meta === void 0 ? void 0 : meta.appType) !== null && _a !== void 0 ? _a : 'mpa';
22
+ const defaultPlugins = [
23
+ new hosting_routing_plugin_1.HostingRoutingPlugin({ appType }),
24
+ ];
25
+ const defaultConfig = {
26
+ devtool: 'source-map',
27
+ optimization: {
28
+ minimize: true,
29
+ splitChunks: false,
30
+ runtimeChunk: false,
31
+ },
32
+ performance: {
33
+ hints: false,
34
+ },
35
+ };
36
+ const finalConfig = (0, webpack_merge_1.merge)(baseConfig, {
37
+ ...defaultConfig,
38
+ plugins: defaultPlugins,
39
+ }, options);
40
+ /**
41
+ * Build Plugins (prod lifecycle)
42
+ */
43
+ const metaWithPlugins = (0, config_meta_1.getConfigMeta)(baseConfig);
44
+ if (metaWithPlugins === null || metaWithPlugins === void 0 ? void 0 : metaWithPlugins.buildPlugins) {
45
+ for (const plugin of metaWithPlugins.buildPlugins) {
46
+ (_b = plugin.applyProd) === null || _b === void 0 ? void 0 : _b.call(plugin, finalConfig);
47
+ }
48
+ }
49
+ /**
50
+ * Re-dedupe plugins after merge and buildPlugins mutations
51
+ */
52
+ if (finalConfig.plugins) {
53
+ finalConfig.plugins = (0, dedupe_plugins_1.dedupePlugins)(finalConfig.plugins);
54
+ }
55
+ return finalConfig;
56
+ }
@@ -0,0 +1,67 @@
1
+ /**
2
+ * @module define-config
3
+ * @description User-friendly configuration wrapper for building Webpack configs.
4
+ *
5
+ * Provides:
6
+ * - Cleaner API for users
7
+ * - Support for dynamic and async config
8
+ * - Presets support (mapped to buildPlugins)
9
+ *
10
+ * Does NOT modify Webpack behavior directly.
11
+ * Delegates all logic to core config creators.
12
+ */
13
+ import { ConfigOptionType, ModeType, BuildPluginType } from '../types';
14
+ import { Configuration } from 'webpack';
15
+ /**
16
+ * Environment passed to config factory
17
+ */
18
+ type DefineEnv = {
19
+ mode: ModeType;
20
+ };
21
+ /**
22
+ * Extended config with presets support
23
+ */
24
+ type ExtendedConfig = ConfigOptionType & {
25
+ /**
26
+ * Optional presets (syntactic sugar for buildPlugins)
27
+ */
28
+ presets?: BuildPluginType[];
29
+ };
30
+ /**
31
+ * Supported config input formats:
32
+ *
33
+ * - Object config
34
+ * - Function config
35
+ * - Async function config
36
+ */
37
+ type DefineConfigInput = ExtendedConfig | ((env: DefineEnv) => ExtendedConfig) | ((env: DefineEnv) => Promise<ExtendedConfig>);
38
+ /**
39
+ * Output type:
40
+ * Always returns a function (Webpack-compatible)
41
+ */
42
+ type DefineConfigReturn = (env?: {
43
+ mode?: ModeType;
44
+ }) => Configuration | Promise<Configuration>;
45
+ /**
46
+ * Main config helper
47
+ *
48
+ * @example
49
+ * ```ts
50
+ * import {defineConfig, reactPreset} from '@razerspine/build';
51
+ *
52
+ * export default defineConfig({
53
+ * mode: 'development',
54
+ * scripts: 'ts',
55
+ * styles: 'scss',
56
+ * templates: {type: 'none'},
57
+ * presets: [reactPreset()]
58
+ * });
59
+ * ```
60
+ *
61
+ * @remarks
62
+ * - Always returns a function (Webpack-compatible)
63
+ * - Supports async config
64
+ * - Supports dynamic mode via CLI (`--mode`)
65
+ */
66
+ export declare function defineConfig(input: DefineConfigInput): DefineConfigReturn;
67
+ export {};
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ /**
3
+ * @module define-config
4
+ * @description User-friendly configuration wrapper for building Webpack configs.
5
+ *
6
+ * Provides:
7
+ * - Cleaner API for users
8
+ * - Support for dynamic and async config
9
+ * - Presets support (mapped to buildPlugins)
10
+ *
11
+ * Does NOT modify Webpack behavior directly.
12
+ * Delegates all logic to core config creators.
13
+ */
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.defineConfig = defineConfig;
16
+ const create_base_config_1 = require("./create-base-config");
17
+ const create_dev_config_1 = require("./create-dev-config");
18
+ const create_prod_config_1 = require("./create-prod-config");
19
+ /**
20
+ * Normalize config:
21
+ * - maps `presets` → `buildPlugins`
22
+ */
23
+ function normalizeConfig(config) {
24
+ const { presets, buildPlugins, ...rest } = config;
25
+ return {
26
+ ...rest,
27
+ buildPlugins: [
28
+ ...(buildPlugins || []),
29
+ ...(presets || []),
30
+ ],
31
+ };
32
+ }
33
+ /**
34
+ * Internal config resolver
35
+ */
36
+ async function resolveConfig(input, env) {
37
+ var _a, _b;
38
+ const mode = (_a = env === null || env === void 0 ? void 0 : env.mode) !== null && _a !== void 0 ? _a : 'development';
39
+ let rawConfig;
40
+ if (typeof input === 'function') {
41
+ rawConfig = await input({ mode });
42
+ }
43
+ else {
44
+ rawConfig = input;
45
+ }
46
+ const finalOptions = normalizeConfig({
47
+ ...rawConfig,
48
+ mode: (_b = rawConfig.mode) !== null && _b !== void 0 ? _b : mode,
49
+ });
50
+ const base = (0, create_base_config_1.createBaseConfig)(finalOptions);
51
+ if (finalOptions.mode === 'development') {
52
+ return (0, create_dev_config_1.createDevConfig)(base);
53
+ }
54
+ return (0, create_prod_config_1.createProdConfig)(base);
55
+ }
56
+ /**
57
+ * Main config helper
58
+ *
59
+ * @example
60
+ * ```ts
61
+ * import {defineConfig, reactPreset} from '@razerspine/build';
62
+ *
63
+ * export default defineConfig({
64
+ * mode: 'development',
65
+ * scripts: 'ts',
66
+ * styles: 'scss',
67
+ * templates: {type: 'none'},
68
+ * presets: [reactPreset()]
69
+ * });
70
+ * ```
71
+ *
72
+ * @remarks
73
+ * - Always returns a function (Webpack-compatible)
74
+ * - Supports async config
75
+ * - Supports dynamic mode via CLI (`--mode`)
76
+ */
77
+ function defineConfig(input) {
78
+ return (env) => {
79
+ return resolveConfig(input, env);
80
+ };
81
+ }
@@ -0,0 +1,5 @@
1
+ export { createBaseConfig } from './create-base-config';
2
+ export { createDevConfig } from './create-dev-config';
3
+ export { createProdConfig } from './create-prod-config';
4
+ export { defineConfig } from './define-config';
5
+ export { getConfigMeta, setConfigMeta } from './config-meta';
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setConfigMeta = exports.getConfigMeta = exports.defineConfig = exports.createProdConfig = exports.createDevConfig = exports.createBaseConfig = void 0;
4
+ var create_base_config_1 = require("./create-base-config");
5
+ Object.defineProperty(exports, "createBaseConfig", { enumerable: true, get: function () { return create_base_config_1.createBaseConfig; } });
6
+ var create_dev_config_1 = require("./create-dev-config");
7
+ Object.defineProperty(exports, "createDevConfig", { enumerable: true, get: function () { return create_dev_config_1.createDevConfig; } });
8
+ var create_prod_config_1 = require("./create-prod-config");
9
+ Object.defineProperty(exports, "createProdConfig", { enumerable: true, get: function () { return create_prod_config_1.createProdConfig; } });
10
+ var define_config_1 = require("./define-config");
11
+ Object.defineProperty(exports, "defineConfig", { enumerable: true, get: function () { return define_config_1.defineConfig; } });
12
+ var config_meta_1 = require("./config-meta");
13
+ Object.defineProperty(exports, "getConfigMeta", { enumerable: true, get: function () { return config_meta_1.getConfigMeta; } });
14
+ Object.defineProperty(exports, "setConfigMeta", { enumerable: true, get: function () { return config_meta_1.setConfigMeta; } });
@@ -0,0 +1,2 @@
1
+ import { HostingType } from '../types';
2
+ export declare function detectHosting(): HostingType;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.detectHosting = detectHosting;
4
+ function detectHosting() {
5
+ if (process.env.NETLIFY)
6
+ return 'netlify';
7
+ if (process.env.VERCEL)
8
+ return 'vercel';
9
+ if (process.env.CF_PAGES)
10
+ return 'cloudflare';
11
+ if (process.env.GITHUB_ACTIONS)
12
+ return 'github';
13
+ return 'static';
14
+ }
@@ -0,0 +1,2 @@
1
+ import { AppType } from '../types';
2
+ export declare function getRedirects(appType: AppType): string;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getRedirects = getRedirects;
4
+ function getRedirects(appType) {
5
+ return appType === 'spa'
6
+ ? '/* /index.html 200\n'
7
+ : '/* /404.html 404\n';
8
+ }
@@ -0,0 +1,2 @@
1
+ import { AppType } from '../types';
2
+ export declare function getVercelConfig(appType: AppType): string;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getVercelConfig = getVercelConfig;
4
+ function getVercelConfig(appType) {
5
+ // Vercel recommends using 'rewrites' for SPA fallback logic
6
+ const config = appType === 'spa'
7
+ ? {
8
+ rewrites: [
9
+ {
10
+ source: '/(.*)',
11
+ destination: '/index.html',
12
+ },
13
+ ],
14
+ }
15
+ : {
16
+ // For MPA, we don't strictly need rewrites for 404
17
+ // if we have a 404.html file, but we can keep it for clean URLs
18
+ cleanUrls: true,
19
+ trailingSlash: false
20
+ };
21
+ return JSON.stringify(config, null, 2);
22
+ }
@@ -0,0 +1,4 @@
1
+ export { createBaseConfig, createDevConfig, createProdConfig, defineConfig } from './core';
2
+ export { resolveOptions } from './options/resolve-options';
3
+ export { reactPreset } from './presets/react';
4
+ export * from './types';
package/dist/index.js ADDED
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.reactPreset = exports.resolveOptions = exports.defineConfig = exports.createProdConfig = exports.createDevConfig = exports.createBaseConfig = void 0;
18
+ var core_1 = require("./core");
19
+ Object.defineProperty(exports, "createBaseConfig", { enumerable: true, get: function () { return core_1.createBaseConfig; } });
20
+ Object.defineProperty(exports, "createDevConfig", { enumerable: true, get: function () { return core_1.createDevConfig; } });
21
+ Object.defineProperty(exports, "createProdConfig", { enumerable: true, get: function () { return core_1.createProdConfig; } });
22
+ Object.defineProperty(exports, "defineConfig", { enumerable: true, get: function () { return core_1.defineConfig; } });
23
+ var resolve_options_1 = require("./options/resolve-options");
24
+ Object.defineProperty(exports, "resolveOptions", { enumerable: true, get: function () { return resolve_options_1.resolveOptions; } });
25
+ var react_1 = require("./presets/react");
26
+ Object.defineProperty(exports, "reactPreset", { enumerable: true, get: function () { return react_1.reactPreset; } });
27
+ __exportStar(require("./types"), exports);
@@ -0,0 +1,2 @@
1
+ export { resolveOptions } from './resolve-options';
2
+ export type { NormalizedCoreOptions } from './normalize-options';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveOptions = void 0;
4
+ var resolve_options_1 = require("./resolve-options");
5
+ Object.defineProperty(exports, "resolveOptions", { enumerable: true, get: function () { return resolve_options_1.resolveOptions; } });
@@ -0,0 +1,14 @@
1
+ import { ConfigOptionType, AppType, ModeType, TemplatesType, StyleType, ScriptType } from '../types';
2
+ import { Configuration } from 'webpack';
3
+ export interface NormalizedCoreOptions {
4
+ mode: ModeType;
5
+ appType: AppType;
6
+ scripts: ScriptType;
7
+ styles: StyleType;
8
+ templates: {
9
+ type: TemplatesType;
10
+ entry?: string;
11
+ };
12
+ resolve: NonNullable<Configuration['resolve']>;
13
+ }
14
+ export declare function normalizeOptions(options: ConfigOptionType): NormalizedCoreOptions;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.normalizeOptions = normalizeOptions;
7
+ const path_1 = __importDefault(require("path"));
8
+ function normalizeOptions(options) {
9
+ var _a, _b, _c, _d, _e, _f, _g, _h;
10
+ const mode = (_a = options.mode) !== null && _a !== void 0 ? _a : 'development';
11
+ const appType = (_b = options.appType) !== null && _b !== void 0 ? _b : 'spa';
12
+ const templatesType = (_d = (_c = options.templates) === null || _c === void 0 ? void 0 : _c.type) !== null && _d !== void 0 ? _d : 'pug';
13
+ /**
14
+ * Resolve templates entry only when templates system is enabled
15
+ */
16
+ let templatesEntry;
17
+ if (templatesType !== 'none') {
18
+ templatesEntry =
19
+ (_f = (_e = options.templates) === null || _e === void 0 ? void 0 : _e.entry) !== null && _f !== void 0 ? _f : (appType === 'spa'
20
+ ? 'src/views/app.pug'
21
+ : 'src/views/pages');
22
+ }
23
+ return {
24
+ mode,
25
+ appType,
26
+ scripts: options.scripts,
27
+ styles: options.styles,
28
+ templates: {
29
+ type: templatesType,
30
+ entry: templatesEntry
31
+ ? path_1.default.resolve(process.cwd(), templatesEntry)
32
+ : undefined,
33
+ },
34
+ resolve: {
35
+ alias: (_h = (_g = options.resolve) === null || _g === void 0 ? void 0 : _g.alias) !== null && _h !== void 0 ? _h : {},
36
+ },
37
+ };
38
+ }
@@ -0,0 +1,3 @@
1
+ import { ConfigOptionType } from '../types';
2
+ import { NormalizedCoreOptions } from './normalize-options';
3
+ export declare function resolveOptions(options: ConfigOptionType): NormalizedCoreOptions;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveOptions = resolveOptions;
4
+ const validate_options_1 = require("./validate-options");
5
+ const normalize_options_1 = require("./normalize-options");
6
+ function resolveOptions(options) {
7
+ (0, validate_options_1.validateOptions)(options);
8
+ return (0, normalize_options_1.normalizeOptions)(options);
9
+ }
@@ -0,0 +1,2 @@
1
+ import { ConfigOptionType } from '../types';
2
+ export declare function validateOptions(options: ConfigOptionType): void;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateOptions = validateOptions;
4
+ function validateOptions(options) {
5
+ var _a, _b, _c, _d, _e;
6
+ if (!options)
7
+ throw new Error('[build] Options are required.');
8
+ const { mode, scripts, styles, appType = 'spa' } = options;
9
+ const templateType = (_b = (_a = options.templates) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : 'pug';
10
+ if (mode && !['development', 'production'].includes(mode)) {
11
+ throw new Error(`[build] Invalid mode "${mode}". Expected "development" or "production".`);
12
+ }
13
+ if (scripts && !['js', 'ts'].includes(scripts)) {
14
+ throw new Error(`[build] Invalid scripts option "${scripts}". Expected "js" or "ts".`);
15
+ }
16
+ if (styles && !['scss', 'less'].includes(styles)) {
17
+ throw new Error(`[build] Invalid styles option "${styles}". Expected "scss" or "less".`);
18
+ }
19
+ if (appType && !['spa', 'mpa'].includes(appType)) {
20
+ throw new Error(`[build] Invalid appType "${appType}". Expected "spa" or "mpa".`);
21
+ }
22
+ if (((_c = options.templates) === null || _c === void 0 ? void 0 : _c.type) === 'none' && ((_d = options.templates) === null || _d === void 0 ? void 0 : _d.entry)) {
23
+ throw new Error('[build] templates.entry should not be provided when templates.type is "none"');
24
+ }
25
+ if (appType === 'mpa' && templateType !== 'none' && !((_e = options.templates) === null || _e === void 0 ? void 0 : _e.entry)) {
26
+ throw new Error('[build] templates.entry is required for MPA when templates are enabled');
27
+ }
28
+ }
@@ -0,0 +1,12 @@
1
+ import { Compiler } from 'webpack';
2
+ import { AppType } from '../types';
3
+ type HostingRoutingPluginOptions = {
4
+ appType: AppType;
5
+ };
6
+ export declare class HostingRoutingPlugin {
7
+ private appType;
8
+ private hosting;
9
+ constructor(options: HostingRoutingPluginOptions);
10
+ apply(compiler: Compiler): void;
11
+ }
12
+ export {};
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HostingRoutingPlugin = void 0;
4
+ const webpack_1 = require("webpack");
5
+ const detect_hosting_1 = require("../hosting/detect-hosting");
6
+ const get_redirects_1 = require("../hosting/get-redirects");
7
+ const get_vercel_config_1 = require("../hosting/get-vercel-config");
8
+ const utils_1 = require("../utils");
9
+ class HostingRoutingPlugin {
10
+ constructor(options) {
11
+ this.appType = options.appType;
12
+ this.hosting = (0, detect_hosting_1.detectHosting)();
13
+ }
14
+ apply(compiler) {
15
+ const logger = compiler.getInfrastructureLogger('@razerspine/build');
16
+ compiler.hooks.thisCompilation.tap('RoutingPlugin', (compilation) => {
17
+ compilation.hooks.processAssets.tap({
18
+ name: 'RoutingPlugin',
19
+ stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS,
20
+ }, () => {
21
+ const { appType, hosting } = this;
22
+ /**
23
+ * Netlify / Cloudflare
24
+ */
25
+ if (hosting === 'netlify' || hosting === 'cloudflare') {
26
+ logger.info(`📦 ${(0, utils_1.textCapitalize)(hosting)} detected. Generating _redirects for ${appType.toUpperCase()}...`);
27
+ compilation.emitAsset('_redirects', new webpack_1.sources.RawSource((0, get_redirects_1.getRedirects)(appType)));
28
+ }
29
+ /**
30
+ * Vercel
31
+ */
32
+ if (hosting === 'vercel') {
33
+ logger.info(`📦 Vercel detected. Generating vercel.json for ${appType.toUpperCase()}...`);
34
+ compilation.emitAsset('vercel.json', new webpack_1.sources.RawSource((0, get_vercel_config_1.getVercelConfig)(appType)));
35
+ }
36
+ /**
37
+ * SPA fallback
38
+ * Generates 404.html as a fallback for static hostings
39
+ */
40
+ if (appType === 'spa') {
41
+ const indexAsset = compilation.getAsset('index.html');
42
+ if (indexAsset) {
43
+ const source = indexAsset.source.source().toString();
44
+ // Always emit 404.html for SPA to ensure
45
+ // it's available for any static hosting
46
+ logger.info(`📦 SPA detected. Creating 404.html fallback...`);
47
+ compilation.emitAsset('404.html', new webpack_1.sources.RawSource(source));
48
+ }
49
+ }
50
+ });
51
+ });
52
+ }
53
+ }
54
+ exports.HostingRoutingPlugin = HostingRoutingPlugin;
@@ -0,0 +1,16 @@
1
+ import { Compiler } from 'webpack';
2
+ import { ModeType, AppType } from '../types';
3
+ type HtmlTemplatesPluginOptions = {
4
+ entry: string;
5
+ mode: ModeType;
6
+ appType: AppType;
7
+ };
8
+ export declare class HtmlTemplatesPlugin {
9
+ private readonly entry;
10
+ private readonly mode;
11
+ private readonly appType;
12
+ constructor(options: HtmlTemplatesPluginOptions);
13
+ private validate;
14
+ apply(compiler: Compiler): void;
15
+ }
16
+ export {};
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.HtmlTemplatesPlugin = void 0;
40
+ const html_webpack_plugin_1 = __importDefault(require("html-webpack-plugin"));
41
+ const fs = __importStar(require("node:fs"));
42
+ const path_1 = __importDefault(require("path"));
43
+ class HtmlTemplatesPlugin {
44
+ constructor(options) {
45
+ this.entry = path_1.default.resolve(options.entry);
46
+ this.mode = options.mode;
47
+ this.appType = options.appType;
48
+ this.validate();
49
+ }
50
+ validate() {
51
+ if (!fs.existsSync(this.entry)) {
52
+ throw new Error(`[build] HTML templates entry not found: ${this.entry}`);
53
+ }
54
+ const stats = fs.statSync(this.entry);
55
+ if (this.appType === 'spa' && !stats.isFile()) {
56
+ throw new Error(`[build] SPA requires a single HTML file as templates.entry`);
57
+ }
58
+ if (this.appType === 'mpa' && !stats.isDirectory()) {
59
+ throw new Error(`[build] MPA requires templates.entry to be a directory`);
60
+ }
61
+ }
62
+ apply(compiler) {
63
+ if (this.appType === 'spa') {
64
+ new html_webpack_plugin_1.default({
65
+ template: this.entry,
66
+ filename: 'index.html',
67
+ minify: this.mode === 'production'
68
+ }).apply(compiler);
69
+ return;
70
+ }
71
+ const files = fs.readdirSync(this.entry).filter(f => f.endsWith('.html'));
72
+ files.forEach(file => {
73
+ const name = path_1.default.basename(file, '.html');
74
+ new html_webpack_plugin_1.default({
75
+ template: path_1.default.join(this.entry, file),
76
+ filename: `${name}.html`,
77
+ minify: this.mode === 'production'
78
+ }).apply(compiler);
79
+ });
80
+ }
81
+ }
82
+ exports.HtmlTemplatesPlugin = HtmlTemplatesPlugin;
@@ -0,0 +1,16 @@
1
+ import { Compiler } from 'webpack';
2
+ import { ModeType, AppType } from '../types';
3
+ type PugTemplatesPluginOptions = {
4
+ entry: string;
5
+ mode: ModeType;
6
+ appType: AppType;
7
+ };
8
+ export declare class PugTemplatesPlugin {
9
+ private readonly entry;
10
+ private readonly mode;
11
+ private readonly appType;
12
+ constructor(options: PugTemplatesPluginOptions);
13
+ private validate;
14
+ apply(compiler: Compiler): void;
15
+ }
16
+ export {};