Skip to content

Commit dd79cee

Browse files
committed
Document Node package exports and config object
1 parent fe40fde commit dd79cee

2 files changed

Lines changed: 72 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ At its core, Shakapacker's essential function is to:
316316
### Configuration and Code
317317

318318
**📖 For a comprehensive guide to all configuration options, see the [Configuration Guide](./docs/configuration.md)**
319+
**📦 For Node package exports and config object docs, see the [Node Package API Guide](./docs/node_package_api.md)**
319320

320321
This includes documentation for:
321322

docs/node_package_api.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Node Package API
2+
3+
Shakapacker ships a Node package that exposes configuration and helper utilities
4+
for both webpack and rspack.
5+
6+
## Import Paths
7+
8+
```js
9+
// Webpack entrypoint
10+
const shakapacker = require("shakapacker")
11+
12+
// Rspack entrypoint
13+
const rspack = require("shakapacker/rspack")
14+
```
15+
16+
## Webpack Exports (`shakapacker`)
17+
18+
| Export | Type | Description |
19+
|--------|------|-------------|
20+
| `config` | object | Parsed `config/shakapacker.yml` plus computed fields |
21+
| `devServer` | object | Dev server configuration |
22+
| `generateWebpackConfig(extraConfig?)` | function | Generates final webpack config and merges optional overrides |
23+
| `baseConfig` | object | Base config object from `package/environments/base` |
24+
| `env` | object | Environment metadata (`railsEnv`, `nodeEnv`, booleans) |
25+
| `rules` | array | Loader rules for current bundler |
26+
| `moduleExists(name)` | function | Returns whether module can be resolved |
27+
| `canProcess(rule, fn)` | function | Runs callback only if loader dependency is available |
28+
| `inliningCss` | boolean | Whether CSS should be inlined in current dev-server mode |
29+
| `merge`, `mergeWithCustomize`, `mergeWithRules`, `unique` | functions | Re-exported from `webpack-merge` |
30+
31+
## Rspack Exports (`shakapacker/rspack`)
32+
33+
| Export | Type | Description |
34+
|--------|------|-------------|
35+
| `config` | object | Parsed `config/shakapacker.yml` plus computed fields |
36+
| `devServer` | object | Dev server configuration |
37+
| `generateRspackConfig(extraConfig?)` | function | Generates final rspack config and merges optional overrides |
38+
| `baseConfig` | object | Base config object |
39+
| `env` | object | Environment metadata (`railsEnv`, `nodeEnv`, booleans) |
40+
| `rules` | array | Rspack loader rules |
41+
| `moduleExists(name)` | function | Returns whether module can be resolved |
42+
| `canProcess(rule, fn)` | function | Runs callback only if loader dependency is available |
43+
| `inliningCss` | boolean | Whether CSS should be inlined in current dev-server mode |
44+
| `merge`, `mergeWithCustomize`, `mergeWithRules`, `unique` | functions | Re-exported from `webpack-merge` |
45+
46+
## `config` Object
47+
48+
`config` includes:
49+
50+
- Raw values from `config/shakapacker.yml` (`source_path`, `public_output_path`, `javascript_transpiler`, etc.)
51+
- Computed absolute paths (`outputPath`, `publicPath`, `manifestPath`, `publicPathWithoutCDN`)
52+
- Optional sections like `dev_server` and `integrity`
53+
54+
For the full key list and types, see:
55+
56+
- [`package/types.ts`](../package/types.ts)
57+
- [Configuration Guide](./configuration.md)
58+
59+
## Built-in Third-Party Support
60+
61+
Installer defaults include support for:
62+
63+
- Bundlers: webpack, rspack
64+
- JavaScript transpilers: SWC (default), Babel, esbuild
65+
- Common style/tooling loaders: css, sass, less, stylus, file/raw rules
66+
- Common optimization/plugins for webpack/rspack production builds
67+
68+
Dependency presets used by the installer are defined in:
69+
70+
- [`lib/install/package.json`](../lib/install/package.json)
71+

0 commit comments

Comments
 (0)