@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.
- package/CHANGELOG.md +750 -0
- package/LICENSE +15 -0
- package/README.md +232 -0
- package/dist/core/config-meta.d.ts +33 -0
- package/dist/core/config-meta.js +27 -0
- package/dist/core/create-base-config.d.ts +52 -0
- package/dist/core/create-base-config.js +180 -0
- package/dist/core/create-dev-config.d.ts +18 -0
- package/dist/core/create-dev-config.js +68 -0
- package/dist/core/create-prod-config.d.ts +12 -0
- package/dist/core/create-prod-config.js +56 -0
- package/dist/core/define-config.d.ts +67 -0
- package/dist/core/define-config.js +81 -0
- package/dist/core/index.d.ts +5 -0
- package/dist/core/index.js +14 -0
- package/dist/hosting/detect-hosting.d.ts +2 -0
- package/dist/hosting/detect-hosting.js +14 -0
- package/dist/hosting/get-redirects.d.ts +2 -0
- package/dist/hosting/get-redirects.js +8 -0
- package/dist/hosting/get-vercel-config.d.ts +2 -0
- package/dist/hosting/get-vercel-config.js +22 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +27 -0
- package/dist/options/index.d.ts +2 -0
- package/dist/options/index.js +5 -0
- package/dist/options/normalize-options.d.ts +14 -0
- package/dist/options/normalize-options.js +38 -0
- package/dist/options/resolve-options.d.ts +3 -0
- package/dist/options/resolve-options.js +9 -0
- package/dist/options/validate-options.d.ts +2 -0
- package/dist/options/validate-options.js +28 -0
- package/dist/plugins/hosting-routing-plugin.d.ts +12 -0
- package/dist/plugins/hosting-routing-plugin.js +54 -0
- package/dist/plugins/html-templates-plugin.d.ts +16 -0
- package/dist/plugins/html-templates-plugin.js +82 -0
- package/dist/plugins/pug-templates-plugin.d.ts +16 -0
- package/dist/plugins/pug-templates-plugin.js +90 -0
- package/dist/presets/react/index.d.ts +1 -0
- package/dist/presets/react/index.js +5 -0
- package/dist/presets/react/react-preset.d.ts +66 -0
- package/dist/presets/react/react-preset.js +198 -0
- package/dist/rules/assets-rule.d.ts +27 -0
- package/dist/rules/assets-rule.js +32 -0
- package/dist/rules/index.d.ts +4 -0
- package/dist/rules/index.js +11 -0
- package/dist/rules/pug-rule.d.ts +16 -0
- package/dist/rules/pug-rule.js +27 -0
- package/dist/rules/scripts-rule.d.ts +15 -0
- package/dist/rules/scripts-rule.js +22 -0
- package/dist/rules/styles-rule.d.ts +21 -0
- package/dist/rules/styles-rule.js +28 -0
- package/dist/types/app-type.d.ts +1 -0
- package/dist/types/app-type.js +2 -0
- package/dist/types/base-webpack-config-type.d.ts +2 -0
- package/dist/types/base-webpack-config-type.js +2 -0
- package/dist/types/build-plugin-type.d.ts +24 -0
- package/dist/types/build-plugin-type.js +2 -0
- package/dist/types/config-option-type.d.ts +120 -0
- package/dist/types/config-option-type.js +2 -0
- package/dist/types/hosting-type.d.ts +1 -0
- package/dist/types/hosting-type.js +2 -0
- package/dist/types/index.d.ts +9 -0
- package/dist/types/index.js +2 -0
- package/dist/types/mode-type.d.ts +1 -0
- package/dist/types/mode-type.js +2 -0
- package/dist/types/script-type.d.ts +1 -0
- package/dist/types/script-type.js +2 -0
- package/dist/types/style-type.d.ts +1 -0
- package/dist/types/style-type.js +2 -0
- package/dist/types/templates-type.d.ts +1 -0
- package/dist/types/templates-type.js +2 -0
- package/dist/utils/dedupe-plugins.d.ts +5 -0
- package/dist/utils/dedupe-plugins.js +20 -0
- package/dist/utils/dedupe-rules.d.ts +9 -0
- package/dist/utils/dedupe-rules.js +27 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.js +9 -0
- package/dist/utils/text-capitalize.d.ts +1 -0
- package/dist/utils/text-capitalize.js +6 -0
- package/package.json +91 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
ISC License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026, Razerspine
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
copyright notice and this permission notice appear in all copies.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
10
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
11
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
12
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
13
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
14
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
15
|
+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
# @razerspine/build
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@razerspine/build)
|
|
4
|
+
[](#)
|
|
5
|
+
[](./CHANGELOG.md)
|
|
6
|
+
[](./LICENSE)
|
|
7
|
+
|
|
8
|
+
A scalable, modular, and highly extensible Webpack build system. Whether you are building template-driven MPA websites (
|
|
9
|
+
Pug/HTML) or modern SPA applications (React), `@razerspine/build` provides a zero-hassle, production-ready foundation
|
|
10
|
+
with smart auto-hosting capabilities.
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## Table of Contents
|
|
15
|
+
|
|
16
|
+
- [Key Features](#-key-features)
|
|
17
|
+
- [Installation](#-installation)
|
|
18
|
+
- [Usage (`defineConfig`)](#-usage)
|
|
19
|
+
- [React Preset (Beta)](#-react-preset-beta)
|
|
20
|
+
- [Application Modes (SPA/MPA)](#-application-modes)
|
|
21
|
+
- [Template Engines](#-template-engines)
|
|
22
|
+
- [Extensibility (Hooks & Plugins)](#-extensibility)
|
|
23
|
+
- [Smart Hosting Adapter](#-smart-hosting-adapter)
|
|
24
|
+
- [Architecture Principles](#-architecture-principles)
|
|
25
|
+
- [Requirements](#-requirements)
|
|
26
|
+
- [License](#-license)
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## 🚀 Key Features
|
|
31
|
+
|
|
32
|
+
- **New `defineConfig` API**: Single entry point for configuration with automatic mode-based resolution.
|
|
33
|
+
- **Multi-Engine Templates**: Built-in support for `pug`, `html`, or `none`.
|
|
34
|
+
- **React Support (Beta)**: DX with Fast Refresh and Babel pipeline via `reactPreset`.
|
|
35
|
+
- **Hybrid Architectures**: Seamlessly switch between Multi-page (MPA) and Single-page (SPA) modes.
|
|
36
|
+
- **Smart Auto-Hosting**: Automatically detects **Vercel, Netlify, Cloudflare**, and **GitHub Pages** to generate
|
|
37
|
+
required routing configs.
|
|
38
|
+
- **Enhanced DX**: Recursive file watching (`src/**/*`), automatic browser opening, and detailed infrastructure logging.
|
|
39
|
+
- **Build Plugins Lifecycle**: Extend the build process safely using `setup`, `applyBase`, `applyDev`, and `applyProd`
|
|
40
|
+
hooks.
|
|
41
|
+
- **Rock Solid**: Covered by 90+ Unit, Integration, E2E, and Snapshot tests.
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## 📦 Installation
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
npm install -D @razerspine/build
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## 📖 Usage
|
|
54
|
+
|
|
55
|
+
Creating a Webpack config is now incredibly simple thanks to the `defineConfig` helper.
|
|
56
|
+
It automatically handles `development` and `production` modes.
|
|
57
|
+
|
|
58
|
+
### Basic Setup (Static)
|
|
59
|
+
|
|
60
|
+
Create a `webpack.config.js`:
|
|
61
|
+
|
|
62
|
+
```js
|
|
63
|
+
const {defineConfig} = require('@razerspine/build');
|
|
64
|
+
|
|
65
|
+
module.exports = defineConfig({
|
|
66
|
+
appType: 'spa', // 'spa' or 'mpa'
|
|
67
|
+
scripts: 'ts', // 'ts' or 'js'
|
|
68
|
+
styles: 'scss', // 'scss' or 'less'
|
|
69
|
+
templates: {
|
|
70
|
+
type: 'pug',
|
|
71
|
+
entry: 'src/app/app.pug',
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Dynamic & Async Configuration
|
|
77
|
+
|
|
78
|
+
You can pass a function to `defineConfig` to access the current mode or fetch async data:
|
|
79
|
+
|
|
80
|
+
```js
|
|
81
|
+
const {defineConfig} = require('@razerspine/build');
|
|
82
|
+
|
|
83
|
+
module.exports = defineConfig(async ({mode}) => {
|
|
84
|
+
return {
|
|
85
|
+
mode,
|
|
86
|
+
scripts: 'ts',
|
|
87
|
+
styles: 'scss',
|
|
88
|
+
// Options...
|
|
89
|
+
};
|
|
90
|
+
});
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
## ⚛️ React Preset (Beta)
|
|
96
|
+
|
|
97
|
+
We've introduced a powerful React preset built on top of the new Build Plugins system.
|
|
98
|
+
It provides a modern developer experience out of the box.
|
|
99
|
+
|
|
100
|
+
**Features**: Babel pipeline, React Fast Refresh, automatic JSX runtime, and safe deduplication.
|
|
101
|
+
|
|
102
|
+
### 1. Install Peer Dependencies
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
npm install -D babel-loader @babel/core @babel/preset-env @babel/preset-react @babel/preset-typescript @pmmmwh/react-refresh-webpack-plugin react-refresh
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### 2. Update Configuration
|
|
109
|
+
|
|
110
|
+
```js
|
|
111
|
+
const {defineConfig, reactPreset} = require('@razerspine/build');
|
|
112
|
+
|
|
113
|
+
module.exports = defineConfig({
|
|
114
|
+
scripts: 'ts',
|
|
115
|
+
styles: 'scss',
|
|
116
|
+
templates: {
|
|
117
|
+
type: 'none', // Handle templates manually or disable for raw React builds
|
|
118
|
+
},
|
|
119
|
+
presets: [
|
|
120
|
+
reactPreset()
|
|
121
|
+
]
|
|
122
|
+
});
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
## 🛠 Application Modes
|
|
128
|
+
|
|
129
|
+
Configure how your application structure is processed using the `appType` option.
|
|
130
|
+
|
|
131
|
+
### MPA (Default)
|
|
132
|
+
|
|
133
|
+
`appType: 'mpa'`
|
|
134
|
+
|
|
135
|
+
- `templates.entry` must be a directory (e.g., `src/views/pages`).
|
|
136
|
+
- Each file in the directory generates its own HTML file.
|
|
137
|
+
|
|
138
|
+
### SPA
|
|
139
|
+
|
|
140
|
+
`appType: 'spa'`
|
|
141
|
+
|
|
142
|
+
- `templates.entry` must be a single file (e.g., `src/app/app.pug` or `index.html`).
|
|
143
|
+
- Always outputs `index.html`.
|
|
144
|
+
- Enables automatic SPA fallback routing (`404.html`) for static hosts.
|
|
145
|
+
|
|
146
|
+
---
|
|
147
|
+
|
|
148
|
+
## 📄 Template Engines
|
|
149
|
+
|
|
150
|
+
You can now explicitly control template processing via `templates.type`:
|
|
151
|
+
|
|
152
|
+
- `pug` (Default): Uses `PugTemplatesPlugin`. Dual-mode support (compiles components for JS imports, renders static HTML
|
|
153
|
+
for entries).
|
|
154
|
+
- `html`: Uses `HtmlTemplatesPlugin` (wrapper around `html-webpack-plugin`).
|
|
155
|
+
- `none`: Disables template handling entirely (useful for custom setups or pure JS/React builds).
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
## 🔌 Extensibility
|
|
160
|
+
|
|
161
|
+
### Extending Rules & Plugins
|
|
162
|
+
|
|
163
|
+
You can safely extend or override internal Webpack rules and plugins without breaking the core:
|
|
164
|
+
|
|
165
|
+
```js
|
|
166
|
+
module.exports = defineConfig({
|
|
167
|
+
// ...
|
|
168
|
+
rules: {
|
|
169
|
+
extend: [ /* your custom RuleSetRule */],
|
|
170
|
+
},
|
|
171
|
+
plugins: {
|
|
172
|
+
extend: [ /* your custom WebpackPluginInstance */],
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### Build Plugins System (Lifecycle Hooks)
|
|
178
|
+
|
|
179
|
+
For advanced use cases or framework integrations, use the new internal plugin system:
|
|
180
|
+
|
|
181
|
+
```js
|
|
182
|
+
module.exports = defineConfig({
|
|
183
|
+
buildPlugins: [
|
|
184
|
+
{
|
|
185
|
+
setup(ctx) { /* run before config creation */
|
|
186
|
+
},
|
|
187
|
+
applyBase(config) { /* mutate base config object safely */
|
|
188
|
+
},
|
|
189
|
+
applyDev(config) { /* dev-only overrides */
|
|
190
|
+
},
|
|
191
|
+
applyProd(config) { /* prod-only overrides */
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
]
|
|
195
|
+
});
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
---
|
|
199
|
+
|
|
200
|
+
## 🌍 Smart Hosting Adapter
|
|
201
|
+
|
|
202
|
+
The core automatically detects your CI/CD environment during the production build and emits necessary routing
|
|
203
|
+
configurations in-memory.
|
|
204
|
+
|
|
205
|
+
| Platform | Generated File | Purpose |
|
|
206
|
+
|:-------------------------|:---------------|:-------------------------------------------------------------------------|
|
|
207
|
+
| **Netlify / Cloudflare** | `_redirects` | Handles SPA rewrites and MPA fallbacks. |
|
|
208
|
+
| **Vercel** | `vercel.json` | Configures Vercel Edge Network routing based on `appType`. |
|
|
209
|
+
| **GitHub Pages** | `404.html` | Duplicates `index.html` to prevent 404 errors on deep links in SPA mode. |
|
|
210
|
+
| **Static / Others** | `404.html` | Generic fallback for SPA mode. |
|
|
211
|
+
|
|
212
|
+
---
|
|
213
|
+
|
|
214
|
+
## 🏗 Architecture Principles
|
|
215
|
+
|
|
216
|
+
- **Template-First**: While Webpack handles assets, templates (Pug/HTML) drive the entry points.
|
|
217
|
+
- **Stability-First**: Aggressive optimizations (like `splitChunks`) are carefully tuned or disabled by default to
|
|
218
|
+
ensure reliable asset resolution within templates.
|
|
219
|
+
- **Type Safety**: Built with TypeScript for excellent IDE support and internal build reliability.
|
|
220
|
+
|
|
221
|
+
---
|
|
222
|
+
|
|
223
|
+
## ⚠️ Requirements
|
|
224
|
+
|
|
225
|
+
- **Node.js**: v20.0.0 or higher
|
|
226
|
+
- **Webpack**: v5.0.0 or higher
|
|
227
|
+
|
|
228
|
+
---
|
|
229
|
+
|
|
230
|
+
## 📄 License
|
|
231
|
+
|
|
232
|
+
This project is licensed under the ISC License.
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module config-meta
|
|
3
|
+
* @description Utilities for managing Webpack configuration metadata.
|
|
4
|
+
* Uses a WeakMap to associate extra properties with a configuration object
|
|
5
|
+
* without causing memory leaks.
|
|
6
|
+
*/
|
|
7
|
+
import { Configuration } from 'webpack';
|
|
8
|
+
import { AppType, BuildPluginType } from '../types';
|
|
9
|
+
/**
|
|
10
|
+
* Metadata structure for the Webpack configuration.
|
|
11
|
+
*/
|
|
12
|
+
type ConfigMeta = {
|
|
13
|
+
/** The application architecture: 'spa' (Single Page Application) or 'mpa' (Multi Page Application) */
|
|
14
|
+
appType: AppType;
|
|
15
|
+
/**
|
|
16
|
+
* Internal build plugins (framework-level extensions)
|
|
17
|
+
* Used for lifecycle hooks across base/dev/prod configs.
|
|
18
|
+
*/
|
|
19
|
+
buildPlugins?: BuildPluginType[];
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Associates metadata with a specific Webpack configuration object.
|
|
23
|
+
* @param {Configuration} config - The Webpack configuration object to tag.
|
|
24
|
+
* @param {ConfigMeta} meta - The metadata to store.
|
|
25
|
+
*/
|
|
26
|
+
export declare function setConfigMeta(config: Configuration, meta: ConfigMeta): void;
|
|
27
|
+
/**
|
|
28
|
+
* Retrieves metadata associated with a Webpack configuration object.
|
|
29
|
+
* @param {Configuration} config - The Webpack configuration object.
|
|
30
|
+
* @returns {ConfigMeta | undefined} The stored metadata or undefined if not found.
|
|
31
|
+
*/
|
|
32
|
+
export declare function getConfigMeta(config: Configuration): ConfigMeta | undefined;
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module config-meta
|
|
4
|
+
* @description Utilities for managing Webpack configuration metadata.
|
|
5
|
+
* Uses a WeakMap to associate extra properties with a configuration object
|
|
6
|
+
* without causing memory leaks.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.setConfigMeta = setConfigMeta;
|
|
10
|
+
exports.getConfigMeta = getConfigMeta;
|
|
11
|
+
const configMeta = new WeakMap();
|
|
12
|
+
/**
|
|
13
|
+
* Associates metadata with a specific Webpack configuration object.
|
|
14
|
+
* @param {Configuration} config - The Webpack configuration object to tag.
|
|
15
|
+
* @param {ConfigMeta} meta - The metadata to store.
|
|
16
|
+
*/
|
|
17
|
+
function setConfigMeta(config, meta) {
|
|
18
|
+
configMeta.set(config, meta);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Retrieves metadata associated with a Webpack configuration object.
|
|
22
|
+
* @param {Configuration} config - The Webpack configuration object.
|
|
23
|
+
* @returns {ConfigMeta | undefined} The stored metadata or undefined if not found.
|
|
24
|
+
*/
|
|
25
|
+
function getConfigMeta(config) {
|
|
26
|
+
return configMeta.get(config);
|
|
27
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module create-base-config
|
|
3
|
+
* @description Generates the base Webpack configuration shared across development and production.
|
|
4
|
+
*/
|
|
5
|
+
import { ConfigOptionType } from '../types';
|
|
6
|
+
import { Configuration } from 'webpack';
|
|
7
|
+
/**
|
|
8
|
+
* Creates a base Webpack configuration object.
|
|
9
|
+
* Also initializes internal metadata (appType) for use in dev/prod overrides.
|
|
10
|
+
*
|
|
11
|
+
* Supports controlled extension/override of internal rules and plugins.
|
|
12
|
+
*
|
|
13
|
+
* ---
|
|
14
|
+
* Template system:
|
|
15
|
+
*
|
|
16
|
+
* The build system supports multiple template engines via `templates.type`:
|
|
17
|
+
*
|
|
18
|
+
* - `pug` → uses PugTemplatesPlugin (default)
|
|
19
|
+
* - `html` → uses HtmlTemplatesPlugin
|
|
20
|
+
* - `none` → disables template handling (React/Vue/custom setups)
|
|
21
|
+
*
|
|
22
|
+
* This allows flexible integration with different rendering strategies.
|
|
23
|
+
*
|
|
24
|
+
* ---
|
|
25
|
+
* Rules system:
|
|
26
|
+
*
|
|
27
|
+
* Internal rules pipeline:
|
|
28
|
+
* - assets
|
|
29
|
+
* - scripts (js/ts)
|
|
30
|
+
* - styles (scss/less)
|
|
31
|
+
* - pug (only when enabled)
|
|
32
|
+
*
|
|
33
|
+
* Users can:
|
|
34
|
+
* - extend rules safely (`rules.extend`)
|
|
35
|
+
* - fully override rules (`rules.override`)
|
|
36
|
+
*
|
|
37
|
+
* ---
|
|
38
|
+
* 🔌 Plugins system:
|
|
39
|
+
*
|
|
40
|
+
* Internal plugins are conditionally applied based on template type.
|
|
41
|
+
*
|
|
42
|
+
* Users can:
|
|
43
|
+
* - extend plugins (`plugins.extend`)
|
|
44
|
+
* - override plugins completely (`plugins.override`)
|
|
45
|
+
*
|
|
46
|
+
* ⚠️ Override should be used with caution — it disables all internal plugins.
|
|
47
|
+
*
|
|
48
|
+
* ---
|
|
49
|
+
* @param {ConfigOptionType} options - User-provided options for the build system.
|
|
50
|
+
* @returns {Configuration} The generated base Webpack configuration.
|
|
51
|
+
*/
|
|
52
|
+
export declare function createBaseConfig(options: ConfigOptionType): Configuration;
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module create-base-config
|
|
4
|
+
* @description Generates the base Webpack configuration shared across development and production.
|
|
5
|
+
*/
|
|
6
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
7
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
|
+
};
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.createBaseConfig = createBaseConfig;
|
|
11
|
+
const config_meta_1 = require("./config-meta");
|
|
12
|
+
const options_1 = require("../options");
|
|
13
|
+
const path_1 = __importDefault(require("path"));
|
|
14
|
+
const rules_1 = require("../rules");
|
|
15
|
+
const pug_templates_plugin_1 = require("../plugins/pug-templates-plugin");
|
|
16
|
+
const html_templates_plugin_1 = require("../plugins/html-templates-plugin");
|
|
17
|
+
const utils_1 = require("../utils");
|
|
18
|
+
/**
|
|
19
|
+
* Creates a base Webpack configuration object.
|
|
20
|
+
* Also initializes internal metadata (appType) for use in dev/prod overrides.
|
|
21
|
+
*
|
|
22
|
+
* Supports controlled extension/override of internal rules and plugins.
|
|
23
|
+
*
|
|
24
|
+
* ---
|
|
25
|
+
* Template system:
|
|
26
|
+
*
|
|
27
|
+
* The build system supports multiple template engines via `templates.type`:
|
|
28
|
+
*
|
|
29
|
+
* - `pug` → uses PugTemplatesPlugin (default)
|
|
30
|
+
* - `html` → uses HtmlTemplatesPlugin
|
|
31
|
+
* - `none` → disables template handling (React/Vue/custom setups)
|
|
32
|
+
*
|
|
33
|
+
* This allows flexible integration with different rendering strategies.
|
|
34
|
+
*
|
|
35
|
+
* ---
|
|
36
|
+
* Rules system:
|
|
37
|
+
*
|
|
38
|
+
* Internal rules pipeline:
|
|
39
|
+
* - assets
|
|
40
|
+
* - scripts (js/ts)
|
|
41
|
+
* - styles (scss/less)
|
|
42
|
+
* - pug (only when enabled)
|
|
43
|
+
*
|
|
44
|
+
* Users can:
|
|
45
|
+
* - extend rules safely (`rules.extend`)
|
|
46
|
+
* - fully override rules (`rules.override`)
|
|
47
|
+
*
|
|
48
|
+
* ---
|
|
49
|
+
* 🔌 Plugins system:
|
|
50
|
+
*
|
|
51
|
+
* Internal plugins are conditionally applied based on template type.
|
|
52
|
+
*
|
|
53
|
+
* Users can:
|
|
54
|
+
* - extend plugins (`plugins.extend`)
|
|
55
|
+
* - override plugins completely (`plugins.override`)
|
|
56
|
+
*
|
|
57
|
+
* ⚠️ Override should be used with caution — it disables all internal plugins.
|
|
58
|
+
*
|
|
59
|
+
* ---
|
|
60
|
+
* @param {ConfigOptionType} options - User-provided options for the build system.
|
|
61
|
+
* @returns {Configuration} The generated base Webpack configuration.
|
|
62
|
+
*/
|
|
63
|
+
function createBaseConfig(options) {
|
|
64
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
65
|
+
const normalized = (0, options_1.resolveOptions)(options);
|
|
66
|
+
const templateType = (_b = (_a = normalized.templates) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : 'pug';
|
|
67
|
+
/**
|
|
68
|
+
* Rules (core pipeline)
|
|
69
|
+
*/
|
|
70
|
+
let rules = [
|
|
71
|
+
(0, rules_1.assetsRule)(),
|
|
72
|
+
(0, rules_1.scriptsRule)(normalized),
|
|
73
|
+
(0, rules_1.stylesRule)(normalized),
|
|
74
|
+
];
|
|
75
|
+
/**
|
|
76
|
+
* Conditionally enable pug processing
|
|
77
|
+
*/
|
|
78
|
+
if (templateType === 'pug') {
|
|
79
|
+
rules.unshift((0, rules_1.pugRule)());
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Apply user rules overrides/extensions
|
|
83
|
+
*/
|
|
84
|
+
if ((_c = options.rules) === null || _c === void 0 ? void 0 : _c.override) {
|
|
85
|
+
rules = options.rules.override;
|
|
86
|
+
}
|
|
87
|
+
else if ((_d = options.rules) === null || _d === void 0 ? void 0 : _d.extend) {
|
|
88
|
+
rules.push(...options.rules.extend);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Plugins (core pipeline)
|
|
92
|
+
*/
|
|
93
|
+
let plugins = [];
|
|
94
|
+
/**
|
|
95
|
+
* PUG templates support
|
|
96
|
+
*/
|
|
97
|
+
if (templateType === 'pug') {
|
|
98
|
+
if (!normalized.templates.entry) {
|
|
99
|
+
throw new Error('[build] templates.entry is required when templates.type is "pug"');
|
|
100
|
+
}
|
|
101
|
+
plugins.push(new pug_templates_plugin_1.PugTemplatesPlugin({
|
|
102
|
+
entry: normalized.templates.entry,
|
|
103
|
+
mode: normalized.mode,
|
|
104
|
+
appType: normalized.appType,
|
|
105
|
+
}));
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* HTML templates support (HtmlWebpackPlugin wrapper)
|
|
109
|
+
*/
|
|
110
|
+
if (templateType === 'html') {
|
|
111
|
+
if (!normalized.templates.entry) {
|
|
112
|
+
throw new Error('[build] templates.entry is required when templates.type is "html"');
|
|
113
|
+
}
|
|
114
|
+
plugins.push(new html_templates_plugin_1.HtmlTemplatesPlugin({
|
|
115
|
+
entry: normalized.templates.entry,
|
|
116
|
+
mode: normalized.mode,
|
|
117
|
+
appType: normalized.appType,
|
|
118
|
+
}));
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Apply user plugins overrides/extensions
|
|
122
|
+
*/
|
|
123
|
+
if ((_e = options.plugins) === null || _e === void 0 ? void 0 : _e.override) {
|
|
124
|
+
plugins = options.plugins.override;
|
|
125
|
+
}
|
|
126
|
+
else if ((_f = options.plugins) === null || _f === void 0 ? void 0 : _f.extend) {
|
|
127
|
+
plugins.push(...options.plugins.extend);
|
|
128
|
+
}
|
|
129
|
+
const config = {
|
|
130
|
+
mode: normalized.mode,
|
|
131
|
+
context: process.cwd(),
|
|
132
|
+
output: {
|
|
133
|
+
path: path_1.default.join(process.cwd(), 'dist'),
|
|
134
|
+
clean: true,
|
|
135
|
+
},
|
|
136
|
+
module: {
|
|
137
|
+
rules,
|
|
138
|
+
},
|
|
139
|
+
plugins: (0, utils_1.dedupePlugins)(plugins),
|
|
140
|
+
resolve: {
|
|
141
|
+
extensions: ['.ts', '.tsx', '.js', '.json'],
|
|
142
|
+
alias: normalized.resolve.alias,
|
|
143
|
+
},
|
|
144
|
+
};
|
|
145
|
+
/**
|
|
146
|
+
* Build Plugins (lifecycle)
|
|
147
|
+
*
|
|
148
|
+
* These are NOT webpack plugins.
|
|
149
|
+
* They are internal framework plugins used to extend config behavior.
|
|
150
|
+
*/
|
|
151
|
+
const buildPlugins = (_g = options.buildPlugins) !== null && _g !== void 0 ? _g : [];
|
|
152
|
+
// Run setup phase
|
|
153
|
+
for (const plugin of buildPlugins) {
|
|
154
|
+
(_h = plugin.setup) === null || _h === void 0 ? void 0 : _h.call(plugin, { options: normalized });
|
|
155
|
+
}
|
|
156
|
+
// Apply base config hooks
|
|
157
|
+
for (const plugin of buildPlugins) {
|
|
158
|
+
(_j = plugin.applyBase) === null || _j === void 0 ? void 0 : _j.call(plugin, config);
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Re-dedupe rules after buildPlugins mutations
|
|
162
|
+
*/
|
|
163
|
+
if ((_k = config.module) === null || _k === void 0 ? void 0 : _k.rules) {
|
|
164
|
+
config.module.rules = (0, utils_1.dedupeRules)(config.module.rules);
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Re-dedupe plugins after buildPlugins mutations
|
|
168
|
+
*/
|
|
169
|
+
if (config.plugins) {
|
|
170
|
+
config.plugins = (0, utils_1.dedupePlugins)(config.plugins);
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Store metadata (appType + buildPlugins)
|
|
174
|
+
*/
|
|
175
|
+
(0, config_meta_1.setConfigMeta)(config, {
|
|
176
|
+
appType: normalized.appType,
|
|
177
|
+
buildPlugins,
|
|
178
|
+
});
|
|
179
|
+
return config;
|
|
180
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module create-dev-config
|
|
3
|
+
* @description Extends the base configuration with Webpack Dev Server settings.
|
|
4
|
+
*/
|
|
5
|
+
import type { Configuration as DevServerConfiguration } from 'webpack-dev-server';
|
|
6
|
+
import { BaseWebpackConfigType } from '../types';
|
|
7
|
+
type DevConfig = BaseWebpackConfigType & {
|
|
8
|
+
devServer?: DevServerConfiguration;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Creates a development configuration by merging base settings with DevServer options.
|
|
12
|
+
* Automatically configures routing fallbacks based on whether the app is SPA or MPA.
|
|
13
|
+
* @param {BaseWebpackConfigType} baseConfig - The base configuration from createBaseConfig.
|
|
14
|
+
* @param {DevServerConfiguration} [options={}] - Optional DevServer overrides.
|
|
15
|
+
* @returns {DevConfig} The final development configuration.
|
|
16
|
+
*/
|
|
17
|
+
export declare function createDevConfig(baseConfig: BaseWebpackConfigType, options?: DevServerConfiguration): DevConfig;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module create-dev-config
|
|
4
|
+
* @description Extends the base configuration with Webpack Dev Server settings.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.createDevConfig = createDevConfig;
|
|
8
|
+
const webpack_merge_1 = require("webpack-merge");
|
|
9
|
+
const config_meta_1 = require("./config-meta");
|
|
10
|
+
const dedupe_plugins_1 = require("../utils/dedupe-plugins");
|
|
11
|
+
/**
|
|
12
|
+
* Creates a development configuration by merging base settings with DevServer options.
|
|
13
|
+
* Automatically configures routing fallbacks based on whether the app is SPA or MPA.
|
|
14
|
+
* @param {BaseWebpackConfigType} baseConfig - The base configuration from createBaseConfig.
|
|
15
|
+
* @param {DevServerConfiguration} [options={}] - Optional DevServer overrides.
|
|
16
|
+
* @returns {DevConfig} The final development configuration.
|
|
17
|
+
*/
|
|
18
|
+
function createDevConfig(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
|
+
/** Default dev server settings */
|
|
23
|
+
const baseDevServer = {
|
|
24
|
+
hot: false,
|
|
25
|
+
open: true,
|
|
26
|
+
liveReload: true,
|
|
27
|
+
compress: true,
|
|
28
|
+
port: 8080,
|
|
29
|
+
watchFiles: ['src/**/*'],
|
|
30
|
+
};
|
|
31
|
+
/** Fallback logic: SPA redirects to index, MPA redirects to 404 */
|
|
32
|
+
const defaultFallbackConfig = {
|
|
33
|
+
historyApiFallback: {
|
|
34
|
+
disableDotRule: true,
|
|
35
|
+
rewrites: [
|
|
36
|
+
{
|
|
37
|
+
from: /./,
|
|
38
|
+
to: appType === 'spa' ? '/index.html' : '/404.html',
|
|
39
|
+
}
|
|
40
|
+
]
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
// Use default fallbacks unless the user provided their own historyApiFallback config
|
|
44
|
+
const fallbackToMerge = options.historyApiFallback !== undefined
|
|
45
|
+
? {}
|
|
46
|
+
: defaultFallbackConfig;
|
|
47
|
+
const resultDevServer = (0, webpack_merge_1.merge)(baseDevServer, fallbackToMerge, options);
|
|
48
|
+
const finalConfig = (0, webpack_merge_1.merge)(baseConfig, {
|
|
49
|
+
devtool: 'source-map',
|
|
50
|
+
devServer: resultDevServer,
|
|
51
|
+
});
|
|
52
|
+
/**
|
|
53
|
+
* Build Plugins (dev lifecycle)
|
|
54
|
+
*/
|
|
55
|
+
const metaWithPlugins = (0, config_meta_1.getConfigMeta)(baseConfig);
|
|
56
|
+
if (metaWithPlugins === null || metaWithPlugins === void 0 ? void 0 : metaWithPlugins.buildPlugins) {
|
|
57
|
+
for (const plugin of metaWithPlugins.buildPlugins) {
|
|
58
|
+
(_b = plugin.applyDev) === null || _b === void 0 ? void 0 : _b.call(plugin, finalConfig);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Re-dedupe plugins after merge and buildPlugins mutations
|
|
63
|
+
*/
|
|
64
|
+
if (finalConfig.plugins) {
|
|
65
|
+
finalConfig.plugins = (0, dedupe_plugins_1.dedupePlugins)(finalConfig.plugins);
|
|
66
|
+
}
|
|
67
|
+
return finalConfig;
|
|
68
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module create-prod-config
|
|
3
|
+
* @description Finalizes the configuration for production builds with optimizations.
|
|
4
|
+
*/
|
|
5
|
+
import { Configuration } from 'webpack';
|
|
6
|
+
/**
|
|
7
|
+
* Creates a production configuration with minification and hosting-specific plugins.
|
|
8
|
+
* @param {Configuration} baseConfig - The base configuration from createBaseConfig.
|
|
9
|
+
* @param {Configuration} [options={}] - Additional Webpack overrides for production.
|
|
10
|
+
* @returns {Configuration} The optimized production configuration.
|
|
11
|
+
*/
|
|
12
|
+
export declare function createProdConfig(baseConfig: Configuration, options?: Configuration): Configuration;
|