@elenajs/bundler 0.6.0 → 0.8.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/README.md +200 -0
- package/package.json +12 -10
- package/src/cem-analyze.js +23 -8
- package/src/cli.js +17 -2
- package/src/index.js +14 -0
- package/src/rollup-build.js +89 -61
- /package/src/{utils → common}/color.js +0 -0
- /package/src/{utils → common}/load-config.js +0 -0
package/README.md
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<picture>
|
|
3
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://elenajs.com/img/elena-dark.png" alt="Elena" width="201" height="230">
|
|
4
|
+
</source>
|
|
5
|
+
<source media="(prefers-color-scheme: light)" srcset="https://elenajs.com/img/elena.png" alt="Elena" width="201" height="230">
|
|
6
|
+
</source>
|
|
7
|
+
<img src="https://elenajs.com/img/elena.png" alt="Elena" width="201" height="230">
|
|
8
|
+
</picture>
|
|
9
|
+
|
|
10
|
+
### Bundler for Progressive Web Component libraries built with Elena.
|
|
11
|
+
|
|
12
|
+
<br/>
|
|
13
|
+
|
|
14
|
+
<a href="https://arielsalminen.com"><img src="https://img.shields.io/badge/creator-@arielle-F95B1F" alt="Creator @arielle"/></a>
|
|
15
|
+
<a href="https://www.npmjs.com/package/@elenajs/bundler"><img src="https://img.shields.io/npm/v/@elenajs/bundler.svg" alt="Latest version on npm" /></a>
|
|
16
|
+
<a href="https://github.com/getelena/elena/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-yellow.svg" alt="Elena is released under the MIT license." /></a>
|
|
17
|
+
<a href="https://github.com/getelena/elena/actions/workflows/tests.yml"><img src="https://github.com/getelena/elena/actions/workflows/tests.yml/badge.svg" alt="Tests status" /></a>
|
|
18
|
+
|
|
19
|
+
</div>
|
|
20
|
+
|
|
21
|
+
<br/>
|
|
22
|
+
|
|
23
|
+
<p align="center"><strong>@elenajs/bundler</strong> is the build tool for <a href="https://elenajs.com">Elena</a> Progressive Web Component libraries. It bundles JavaScript and TypeScript source files, minifies CSS, generates a <a href="https://custom-elements-manifest.open-wc.org/">Custom Elements Manifest</a>, and produces TypeScript declarations for Elena components.</p>
|
|
24
|
+
|
|
25
|
+
<br/>
|
|
26
|
+
|
|
27
|
+
## Table of contents
|
|
28
|
+
|
|
29
|
+
- **[Install](#install)**
|
|
30
|
+
- **[CLI usage](#cli-usage)**
|
|
31
|
+
- **[Configuration](#configuration)**
|
|
32
|
+
- **[Options](#options)**
|
|
33
|
+
- **[Build output](#build-output)**
|
|
34
|
+
- **[Programmatic API](#programmatic-api)**
|
|
35
|
+
|
|
36
|
+
## Install
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
npm install --save-dev @elenajs/bundler
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## CLI usage
|
|
43
|
+
|
|
44
|
+
The bundler provides an `elena` CLI binary with a single `build` command:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
npx elena build
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
If no command is provided, `build` is assumed:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
npx elena
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Configuration
|
|
57
|
+
|
|
58
|
+
Create an `elena.config.mjs` (or `elena.config.js`) at the root of your package:
|
|
59
|
+
|
|
60
|
+
```js
|
|
61
|
+
/**
|
|
62
|
+
* ░ [ELENA]: Bundler configuration
|
|
63
|
+
*
|
|
64
|
+
* @type {import("@elenajs/bundler").ElenaConfig}
|
|
65
|
+
*/
|
|
66
|
+
export default {
|
|
67
|
+
// Source directory scanned for .js/.ts entry files and .css files.
|
|
68
|
+
input: "src",
|
|
69
|
+
|
|
70
|
+
// Rollup output options.
|
|
71
|
+
output: {
|
|
72
|
+
dir: "dist",
|
|
73
|
+
format: "esm",
|
|
74
|
+
sourcemap: true,
|
|
75
|
+
},
|
|
76
|
+
|
|
77
|
+
// Entry for the single-file bundle. Set to false to disable.
|
|
78
|
+
bundle: "src/index.js",
|
|
79
|
+
|
|
80
|
+
// Additional Rollup plugins appended after Elena’s built-in set.
|
|
81
|
+
// plugins: [],
|
|
82
|
+
|
|
83
|
+
// Custom Elements Manifest options.
|
|
84
|
+
// analyze: {
|
|
85
|
+
// plugins: [],
|
|
86
|
+
// },
|
|
87
|
+
};
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Options
|
|
91
|
+
|
|
92
|
+
| Option | Type | Default | Description |
|
|
93
|
+
| ------------------ | ----------------- | ---------------- | ------------------------------------------------------------------------------------------------------------------------ |
|
|
94
|
+
| `input` | `string` | `"src"` | Source directory to scan for `.js`, `.ts`, and `.css` files. |
|
|
95
|
+
| `output.dir` | `string` | `"dist"` | Output directory for compiled files. |
|
|
96
|
+
| `output.format` | `string` | `"esm"` | Rollup output format. |
|
|
97
|
+
| `output.sourcemap` | `boolean` | `true` | Whether to emit sourcemaps. |
|
|
98
|
+
| `bundle` | `string \| false` | `"src/index.js"` | Entry point for the single-file bundle. Auto-detects `src/index.ts` if no `.js` entry exists. Set to `false` to disable. |
|
|
99
|
+
| `plugins` | `Plugin[]` | `[]` | Additional Rollup plugins appended after the built-in set. |
|
|
100
|
+
| `analyze.plugins` | `Plugin[]` | `[]` | Additional CEM analyzer plugins. |
|
|
101
|
+
|
|
102
|
+
## Build output
|
|
103
|
+
|
|
104
|
+
Running `elena build` produces:
|
|
105
|
+
|
|
106
|
+
| File | Description |
|
|
107
|
+
| --------------------------- | ---------------------------------------------------------------------------------------------------- |
|
|
108
|
+
| `dist/*.js` | Individual ES modules for each source file. |
|
|
109
|
+
| `dist/*.css` | Minified individual CSS files. |
|
|
110
|
+
| `dist/bundle.js` | Single-file JavaScript bundle _(optional)_. |
|
|
111
|
+
| `dist/bundle.css` | Concatenated and minified CSS bundle. |
|
|
112
|
+
| `dist/custom-elements.json` | [Custom Elements Manifest](https://custom-elements-manifest.open-wc.org/) describing all components. |
|
|
113
|
+
| `dist/custom-elements.d.ts` | JSX integration types mapping tag names to prop types. |
|
|
114
|
+
| `dist/*.d.ts` | Per-component TypeScript declarations with typed props and events. |
|
|
115
|
+
|
|
116
|
+
## TypeScript support
|
|
117
|
+
|
|
118
|
+
The bundler supports both JavaScript and TypeScript source files. When `.ts` files are detected in the source directory, the bundler automatically transpiles them to JavaScript using `@rollup/plugin-typescript`. The output is identical to what you get from JavaScript sources.
|
|
119
|
+
|
|
120
|
+
To use TypeScript, write your components with inline type annotations instead of JSDoc:
|
|
121
|
+
|
|
122
|
+
```ts
|
|
123
|
+
import { Elena, html } from "@elenajs/core";
|
|
124
|
+
|
|
125
|
+
export default class Button extends Elena(HTMLElement, {
|
|
126
|
+
tagName: "elena-button",
|
|
127
|
+
props: ["variant"],
|
|
128
|
+
}) {
|
|
129
|
+
/**
|
|
130
|
+
* The style variant of the component.
|
|
131
|
+
* @attribute
|
|
132
|
+
*/
|
|
133
|
+
variant: "default" | "primary" | "danger" = "default";
|
|
134
|
+
|
|
135
|
+
render() {
|
|
136
|
+
return html`<button>${this.text}</button>`;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
Button.define();
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
A `tsconfig.json` is required in the project root. A minimal configuration:
|
|
143
|
+
|
|
144
|
+
```json
|
|
145
|
+
{
|
|
146
|
+
"compilerOptions": {
|
|
147
|
+
"target": "ES2020",
|
|
148
|
+
"module": "ESNext",
|
|
149
|
+
"moduleResolution": "bundler",
|
|
150
|
+
"skipLibCheck": true
|
|
151
|
+
},
|
|
152
|
+
"include": ["src"]
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
> **Note:** The bundler handles TypeScript declarations separately via the CEM analyzer, you do not need `declaration: true` in your `tsconfig.json`.
|
|
157
|
+
|
|
158
|
+
## Programmatic API
|
|
159
|
+
|
|
160
|
+
The bundler exports its internals so you can integrate it into your own build scripts:
|
|
161
|
+
|
|
162
|
+
```js
|
|
163
|
+
import {
|
|
164
|
+
createRollupConfig,
|
|
165
|
+
runRollupBuild,
|
|
166
|
+
createCemConfig,
|
|
167
|
+
runCemAnalyze,
|
|
168
|
+
} from "@elenajs/bundler";
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
Sub-path imports are also available:
|
|
172
|
+
|
|
173
|
+
```js
|
|
174
|
+
import { createRollupConfig, runRollupBuild } from "@elenajs/bundler/rollup";
|
|
175
|
+
import { createCemConfig, runCemAnalyze } from "@elenajs/bundler/cem";
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### `createRollupConfig(options?)`
|
|
179
|
+
|
|
180
|
+
Returns a Rollup configuration array. Useful if you want to wrap or extend the config in a custom `rollup.config.js`.
|
|
181
|
+
|
|
182
|
+
### `runRollupBuild(config)`
|
|
183
|
+
|
|
184
|
+
Runs both build phases (individual modules + optional single-file bundle) programmatically.
|
|
185
|
+
|
|
186
|
+
### `createCemConfig(options?)`
|
|
187
|
+
|
|
188
|
+
Returns the Custom Elements Manifest analyzer configuration object.
|
|
189
|
+
|
|
190
|
+
### `runCemAnalyze(config, cwd?)`
|
|
191
|
+
|
|
192
|
+
Runs the CEM analysis and writes `custom-elements.json`, `custom-elements.d.ts`, and per-component `.d.ts` files.
|
|
193
|
+
|
|
194
|
+
## License
|
|
195
|
+
|
|
196
|
+
MIT
|
|
197
|
+
|
|
198
|
+
## Copyright
|
|
199
|
+
|
|
200
|
+
Copyright © 2026 [Ariel Salminen](https://arielsalminen.com)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elenajs/bundler",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Bundler for Progressive Web Component libraries built with Elena.",
|
|
5
5
|
"author": "Elena <hi@elenajs.com>",
|
|
6
6
|
"homepage": "https://elenajs.com/",
|
|
@@ -24,25 +24,27 @@
|
|
|
24
24
|
"node": ">= 20"
|
|
25
25
|
},
|
|
26
26
|
"scripts": {
|
|
27
|
-
"format": "prettier --write \"src/**/*.js\" \"test/**/*.mjs\"",
|
|
28
27
|
"test": "vitest run"
|
|
29
28
|
},
|
|
30
29
|
"dependencies": {
|
|
31
30
|
"@custom-elements-manifest/analyzer": "0.11.0",
|
|
32
|
-
"@elenajs/plugin-cem-define": "^0.
|
|
33
|
-
"@elenajs/plugin-cem-tag": "^0.
|
|
34
|
-
"@elenajs/plugin-cem-typescript": "^0.
|
|
35
|
-
"@elenajs/plugin-rollup-css": "^0.
|
|
31
|
+
"@elenajs/plugin-cem-define": "^0.3.0",
|
|
32
|
+
"@elenajs/plugin-cem-tag": "^0.3.0",
|
|
33
|
+
"@elenajs/plugin-cem-typescript": "^0.4.0",
|
|
34
|
+
"@elenajs/plugin-rollup-css": "^0.5.0",
|
|
36
35
|
"@rollup/plugin-node-resolve": "16.0.3",
|
|
37
36
|
"@rollup/plugin-terser": "0.4.4",
|
|
37
|
+
"@rollup/plugin-typescript": "^12.1.0",
|
|
38
38
|
"custom-element-jsx-integration": "1.6.0",
|
|
39
|
-
"globby": "
|
|
40
|
-
"rollup": "4.
|
|
39
|
+
"globby": "16.1.1",
|
|
40
|
+
"rollup": "4.58.0",
|
|
41
41
|
"rollup-plugin-minify-html-literals-v3": "^1.3.4",
|
|
42
|
-
"rollup-plugin-summary": "3.0.1"
|
|
42
|
+
"rollup-plugin-summary": "3.0.1",
|
|
43
|
+
"tslib": "^2.8.0",
|
|
44
|
+
"typescript": "^5.8.0"
|
|
43
45
|
},
|
|
44
46
|
"devDependencies": {
|
|
45
47
|
"vitest": "4.0.18"
|
|
46
48
|
},
|
|
47
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "c181af0625f691a95a5cb1ef9adb0d7f2c796eae"
|
|
48
50
|
}
|
package/src/cem-analyze.js
CHANGED
|
@@ -1,18 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ██████████ ████
|
|
3
|
+
* ░░███░░░░░█░░███
|
|
4
|
+
* ░███ █ ░ ███ ██████ ████████ ██████
|
|
5
|
+
* ░██████ ███ ███░░███░░███░░███ ░░░░░███
|
|
6
|
+
* ░███░░█ ███ ░███████ ░███ ░███ ███████
|
|
7
|
+
* ░███ ░ █ ███ ░███░░░ ░███ ░███ ███░░███
|
|
8
|
+
* ██████████ █████░░██████ ████ █████░░████████
|
|
9
|
+
* ░░░░░░░░░░ ░░░░░ ░░░░░░ ░░░░ ░░░░░ ░░░░░░░░
|
|
10
|
+
*
|
|
11
|
+
* Elena Bundler CEM Analyze
|
|
12
|
+
* https://elenajs.com
|
|
13
|
+
*/
|
|
14
|
+
|
|
1
15
|
import { readFileSync, writeFileSync, mkdirSync, existsSync } from "fs";
|
|
2
16
|
import { join, resolve } from "path";
|
|
3
17
|
import { create, ts } from "@custom-elements-manifest/analyzer";
|
|
4
|
-
import globby from "globby";
|
|
18
|
+
import { globby } from "globby";
|
|
5
19
|
import { customElementJsxPlugin as elenaJsxPlugin } from "custom-element-jsx-integration";
|
|
6
20
|
import { elenaDefinePlugin } from "@elenajs/plugin-cem-define";
|
|
7
21
|
import { elenaTagPlugin } from "@elenajs/plugin-cem-tag";
|
|
8
22
|
import { elenaTypeScriptPlugin } from "@elenajs/plugin-cem-typescript";
|
|
9
|
-
import { color } from "./
|
|
23
|
+
import { color } from "./common/color.js";
|
|
10
24
|
|
|
11
25
|
/**
|
|
12
26
|
* Returns the CEM config object for the given Elena config. Useful for advanced
|
|
13
27
|
* users who still call the CEM CLI with a thin `elena.config.js` wrapper.
|
|
14
28
|
*
|
|
15
|
-
* @param {import("./
|
|
29
|
+
* @param {import("./common/load-config.js").ElenaConfig} [options]
|
|
16
30
|
* @returns {object} CEM config object
|
|
17
31
|
*/
|
|
18
32
|
export function createCemConfig(options = {}) {
|
|
@@ -24,8 +38,8 @@ export function createCemConfig(options = {}) {
|
|
|
24
38
|
outdir,
|
|
25
39
|
watch: false,
|
|
26
40
|
dev: false,
|
|
27
|
-
globs: [`${src}/**/*.js`],
|
|
28
|
-
exclude: [
|
|
41
|
+
globs: [`${src}/**/*.js`, `${src}/**/*.ts`],
|
|
42
|
+
exclude: ["**/*.test.js", "**/*.test.ts", "node_modules"],
|
|
29
43
|
plugins: [
|
|
30
44
|
elenaDefinePlugin(),
|
|
31
45
|
elenaTagPlugin("status"),
|
|
@@ -41,7 +55,7 @@ export function createCemConfig(options = {}) {
|
|
|
41
55
|
* Runs the CEM analyzer programmatically using `create()` from
|
|
42
56
|
* `@custom-elements-manifest/analyzer`, writes the manifest to disk.
|
|
43
57
|
*
|
|
44
|
-
* @param {import("./
|
|
58
|
+
* @param {import("./common/load-config.js").ElenaConfig} config
|
|
45
59
|
* @param {string} [cwd]
|
|
46
60
|
* @returns {Promise<void>}
|
|
47
61
|
*/
|
|
@@ -57,14 +71,15 @@ export async function runCemAnalyze(config, cwd = process.cwd()) {
|
|
|
57
71
|
console.log(` `);
|
|
58
72
|
|
|
59
73
|
const globs = await globby(
|
|
60
|
-
[`${src}/**/*.js`,
|
|
74
|
+
[`${src}/**/*.js`, `${src}/**/*.ts`, "!**/*.test.js", "!**/*.test.ts", "!node_modules"],
|
|
61
75
|
{ cwd }
|
|
62
76
|
);
|
|
63
77
|
|
|
64
78
|
const modules = globs.map(glob => {
|
|
65
79
|
const fullPath = resolve(cwd, glob);
|
|
66
80
|
const source = readFileSync(fullPath).toString();
|
|
67
|
-
|
|
81
|
+
const scriptKind = glob.endsWith(".ts") ? ts.ScriptKind.TS : ts.ScriptKind.JS;
|
|
82
|
+
return ts.createSourceFile(glob, source, ts.ScriptTarget.ES2015, true, scriptKind);
|
|
68
83
|
});
|
|
69
84
|
|
|
70
85
|
const plugins = [
|
package/src/cli.js
CHANGED
|
@@ -1,9 +1,23 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* ██████████ ████
|
|
5
|
+
* ░░███░░░░░█░░███
|
|
6
|
+
* ░███ █ ░ ███ ██████ ████████ ██████
|
|
7
|
+
* ░██████ ███ ███░░███░░███░░███ ░░░░░███
|
|
8
|
+
* ░███░░█ ███ ░███████ ░███ ░███ ███████
|
|
9
|
+
* ░███ ░ █ ███ ░███░░░ ░███ ░███ ███░░███
|
|
10
|
+
* ██████████ █████░░██████ ████ █████░░████████
|
|
11
|
+
* ░░░░░░░░░░ ░░░░░ ░░░░░░ ░░░░ ░░░░░ ░░░░░░░░
|
|
12
|
+
*
|
|
13
|
+
* Elena Bundler CLI
|
|
14
|
+
* https://elenajs.com
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { loadConfig } from "./common/load-config.js";
|
|
4
18
|
import { runRollupBuild } from "./rollup-build.js";
|
|
5
19
|
import { runCemAnalyze } from "./cem-analyze.js";
|
|
6
|
-
import { color } from "./
|
|
20
|
+
import { color } from "./common/color.js";
|
|
7
21
|
|
|
8
22
|
const BANNER = `
|
|
9
23
|
██████████ ████
|
|
@@ -18,6 +32,7 @@ const BANNER = `
|
|
|
18
32
|
|
|
19
33
|
const [, , command = "build"] = process.argv;
|
|
20
34
|
|
|
35
|
+
/** Loads the Elena config and runs the Rollup build + CEM analysis. */
|
|
21
36
|
async function main() {
|
|
22
37
|
if (command !== "build") {
|
|
23
38
|
console.error(`Unknown command: ${command}. Usage: elena [build]`);
|
package/src/index.js
CHANGED
|
@@ -1,2 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ██████████ ████
|
|
3
|
+
* ░░███░░░░░█░░███
|
|
4
|
+
* ░███ █ ░ ███ ██████ ████████ ██████
|
|
5
|
+
* ░██████ ███ ███░░███░░███░░███ ░░░░░███
|
|
6
|
+
* ░███░░█ ███ ░███████ ░███ ░███ ███████
|
|
7
|
+
* ░███ ░ █ ███ ░███░░░ ░███ ░███ ███░░███
|
|
8
|
+
* ██████████ █████░░██████ ████ █████░░████████
|
|
9
|
+
* ░░░░░░░░░░ ░░░░░ ░░░░░░ ░░░░ ░░░░░ ░░░░░░░░
|
|
10
|
+
*
|
|
11
|
+
* Elena Bundler
|
|
12
|
+
* https://elenajs.com
|
|
13
|
+
*/
|
|
14
|
+
|
|
1
15
|
export { createRollupConfig, runRollupBuild } from "./rollup-build.js";
|
|
2
16
|
export { createCemConfig, runCemAnalyze } from "./cem-analyze.js";
|
package/src/rollup-build.js
CHANGED
|
@@ -1,17 +1,38 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* ██████████ ████
|
|
3
|
+
* ░░███░░░░░█░░███
|
|
4
|
+
* ░███ █ ░ ███ ██████ ████████ ██████
|
|
5
|
+
* ░██████ ███ ███░░███░░███░░███ ░░░░░███
|
|
6
|
+
* ░███░░█ ███ ░███████ ░███ ░███ ███████
|
|
7
|
+
* ░███ ░ █ ███ ░███░░░ ░███ ░███ ███░░███
|
|
8
|
+
* ██████████ █████░░██████ ████ █████░░████████
|
|
9
|
+
* ░░░░░░░░░░ ░░░░░ ░░░░░░ ░░░░ ░░░░░ ░░░░░░░░
|
|
10
|
+
*
|
|
11
|
+
* Elena Bundler Rollup Config
|
|
12
|
+
* https://elenajs.com
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { existsSync, readdirSync } from "fs";
|
|
2
16
|
import { rollup } from "rollup";
|
|
3
17
|
import resolve from "@rollup/plugin-node-resolve";
|
|
4
18
|
import terser from "@rollup/plugin-terser";
|
|
19
|
+
import typescript from "@rollup/plugin-typescript";
|
|
5
20
|
import minifyHtmlLiterals from "rollup-plugin-minify-html-literals-v3";
|
|
6
21
|
import summary from "rollup-plugin-summary";
|
|
7
22
|
import { cssPlugin, cssBundlePlugin } from "@elenajs/plugin-rollup-css";
|
|
8
|
-
import { color } from "./
|
|
23
|
+
import { color } from "./common/color.js";
|
|
9
24
|
|
|
10
25
|
const TREESHAKE = {
|
|
11
26
|
moduleSideEffects: false,
|
|
12
27
|
propertyReadSideEffects: false,
|
|
13
28
|
};
|
|
14
29
|
|
|
30
|
+
/**
|
|
31
|
+
* Suppresses noisy Rollup warnings.
|
|
32
|
+
*
|
|
33
|
+
* @param {import("rollup").RollupWarning} warning
|
|
34
|
+
* @param {function} warn
|
|
35
|
+
*/
|
|
15
36
|
function onwarn(warning, warn) {
|
|
16
37
|
if (warning.code === "UNUSED_EXTERNAL_IMPORT") {
|
|
17
38
|
return;
|
|
@@ -22,15 +43,36 @@ function onwarn(warning, warn) {
|
|
|
22
43
|
/**
|
|
23
44
|
* Builds the plugin list for a single Rollup build target.
|
|
24
45
|
*
|
|
25
|
-
* @param {{ src: string; outdir: string; hasSummary: boolean; includeCssBundle: boolean; extraPlugins?: import("rollup").Plugin[] }} opts
|
|
46
|
+
* @param {{ src: string; outdir: string; hasSummary: boolean; includeCssBundle: boolean; extraPlugins?: import("rollup").Plugin[]; hasTs?: boolean }} opts
|
|
26
47
|
* @returns {import("rollup").Plugin[]}
|
|
27
48
|
*/
|
|
28
|
-
function buildPlugins({
|
|
29
|
-
|
|
30
|
-
|
|
49
|
+
function buildPlugins({
|
|
50
|
+
src,
|
|
51
|
+
outdir,
|
|
52
|
+
hasSummary,
|
|
53
|
+
includeCssBundle,
|
|
54
|
+
extraPlugins = [],
|
|
55
|
+
hasTs = false,
|
|
56
|
+
}) {
|
|
57
|
+
const plugins = [resolve({ extensions: [".js", ".ts", ".css"] })];
|
|
58
|
+
|
|
59
|
+
if (hasTs) {
|
|
60
|
+
plugins.push(
|
|
61
|
+
typescript({
|
|
62
|
+
sourceMap: true,
|
|
63
|
+
compilerOptions: {
|
|
64
|
+
declaration: false,
|
|
65
|
+
declarationMap: false,
|
|
66
|
+
},
|
|
67
|
+
include: ["**/*.ts"],
|
|
68
|
+
})
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
plugins.push(
|
|
31
73
|
minifyHtmlLiterals({
|
|
32
74
|
options: {
|
|
33
|
-
//
|
|
75
|
+
// Minify any template literal containing HTML, regardless of tag name
|
|
34
76
|
shouldMinify: template => template.parts.some(({ text }) => /<[a-z]/i.test(text)),
|
|
35
77
|
},
|
|
36
78
|
}),
|
|
@@ -38,8 +80,8 @@ function buildPlugins({ src, outdir, hasSummary, includeCssBundle, extraPlugins
|
|
|
38
80
|
ecma: 2020,
|
|
39
81
|
module: true,
|
|
40
82
|
}),
|
|
41
|
-
cssPlugin(src)
|
|
42
|
-
|
|
83
|
+
cssPlugin(src)
|
|
84
|
+
);
|
|
43
85
|
|
|
44
86
|
if (includeCssBundle) {
|
|
45
87
|
plugins.push(cssBundlePlugin(src, "bundle.css"));
|
|
@@ -56,7 +98,7 @@ function buildPlugins({ src, outdir, hasSummary, includeCssBundle, extraPlugins
|
|
|
56
98
|
}
|
|
57
99
|
|
|
58
100
|
/**
|
|
59
|
-
* Returns the Rollup config array for the given Elena config. Useful for
|
|
101
|
+
* Returns the Rollup config array for the given Elena config. Useful for
|
|
60
102
|
* users who want to call `rollup -c` with a thin wrapper config file.
|
|
61
103
|
*
|
|
62
104
|
* @param {import("./utils/load-config.js").ElenaConfig} [options]
|
|
@@ -67,13 +109,24 @@ export function createRollupConfig(options = {}) {
|
|
|
67
109
|
const outdir = options.output?.dir ?? "dist";
|
|
68
110
|
const format = options.output?.format ?? "esm";
|
|
69
111
|
const sourcemap = options.output?.sourcemap ?? true;
|
|
70
|
-
|
|
112
|
+
let bundle = options.bundle !== undefined ? options.bundle : "src/index.js";
|
|
71
113
|
const extraPlugins = options.plugins ?? [];
|
|
72
114
|
|
|
73
115
|
const entries = readdirSync(src, { recursive: true })
|
|
74
|
-
.filter(
|
|
116
|
+
.filter(
|
|
117
|
+
f =>
|
|
118
|
+
(f.endsWith(".js") || f.endsWith(".ts")) &&
|
|
119
|
+
!f.endsWith(".test.js") &&
|
|
120
|
+
!f.endsWith(".test.ts")
|
|
121
|
+
)
|
|
75
122
|
.map(f => `${src}/${f}`);
|
|
76
123
|
|
|
124
|
+
const hasTs = entries.some(f => f.endsWith(".ts"));
|
|
125
|
+
|
|
126
|
+
if (bundle === "src/index.js" && !existsSync(bundle) && existsSync("src/index.ts")) {
|
|
127
|
+
bundle = "src/index.ts";
|
|
128
|
+
}
|
|
129
|
+
|
|
77
130
|
const configs = [
|
|
78
131
|
{
|
|
79
132
|
input: entries,
|
|
@@ -83,8 +136,14 @@ export function createRollupConfig(options = {}) {
|
|
|
83
136
|
hasSummary: false,
|
|
84
137
|
includeCssBundle: true,
|
|
85
138
|
extraPlugins,
|
|
139
|
+
hasTs,
|
|
86
140
|
}),
|
|
87
|
-
output: {
|
|
141
|
+
output: {
|
|
142
|
+
format,
|
|
143
|
+
sourcemap,
|
|
144
|
+
dir: outdir,
|
|
145
|
+
...(hasTs && { entryFileNames: "[name].js" }),
|
|
146
|
+
},
|
|
88
147
|
preserveEntrySignatures: "strict",
|
|
89
148
|
treeshake: TREESHAKE,
|
|
90
149
|
onwarn,
|
|
@@ -100,6 +159,7 @@ export function createRollupConfig(options = {}) {
|
|
|
100
159
|
hasSummary: true,
|
|
101
160
|
includeCssBundle: false,
|
|
102
161
|
extraPlugins,
|
|
162
|
+
hasTs,
|
|
103
163
|
}),
|
|
104
164
|
output: { format, sourcemap, file: `${outdir}/bundle.js` },
|
|
105
165
|
preserveEntrySignatures: "strict",
|
|
@@ -112,62 +172,30 @@ export function createRollupConfig(options = {}) {
|
|
|
112
172
|
}
|
|
113
173
|
|
|
114
174
|
/**
|
|
115
|
-
* Runs
|
|
116
|
-
*
|
|
117
|
-
* Note: the `output` key inside `RollupOptions` is ignored by the `rollup()` API.
|
|
118
|
-
* Output options must be passed separately to `build.write()`.
|
|
175
|
+
* Runs Rollup build targets programmatically using the Rollup Node.js API.
|
|
176
|
+
* Reuses `createRollupConfig` to avoid duplicating config resolution logic.
|
|
119
177
|
*
|
|
120
178
|
* @param {import("./utils/load-config.js").ElenaConfig} config
|
|
121
179
|
* @returns {Promise<void>}
|
|
122
180
|
*/
|
|
123
181
|
export async function runRollupBuild(config) {
|
|
124
|
-
const
|
|
125
|
-
const outdir = config.output?.dir ?? "dist";
|
|
126
|
-
const format = config.output?.format ?? "esm";
|
|
127
|
-
const sourcemap = config.output?.sourcemap ?? true;
|
|
128
|
-
const bundle = config.bundle !== undefined ? config.bundle : "src/index.js";
|
|
129
|
-
const extraPlugins = config.plugins ?? [];
|
|
182
|
+
const configs = createRollupConfig(config);
|
|
130
183
|
|
|
131
|
-
const entries = readdirSync(src, { recursive: true })
|
|
132
|
-
.filter(f => f.endsWith(".js"))
|
|
133
|
-
.map(f => `${src}/${f}`);
|
|
134
|
-
|
|
135
|
-
// Build 1: individual modules + CSS bundle
|
|
136
184
|
console.log(color(`░█ [ELENA]: Building Progressive Web Components...`));
|
|
137
185
|
console.log(` `);
|
|
138
|
-
for (const entry of entries) {
|
|
139
|
-
console.log(color(`░█ [ELENA]: Generating and minifying ${entry}...`));
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
const build1 = await rollup({
|
|
143
|
-
input: entries,
|
|
144
|
-
plugins: buildPlugins({ src, outdir, hasSummary: false, includeCssBundle: true, extraPlugins }),
|
|
145
|
-
preserveEntrySignatures: "strict",
|
|
146
|
-
treeshake: TREESHAKE,
|
|
147
|
-
onwarn,
|
|
148
|
-
});
|
|
149
|
-
await build1.write({ format, sourcemap, dir: outdir });
|
|
150
|
-
await build1.close();
|
|
151
|
-
|
|
152
|
-
// Build 2: single-file JS bundle (optional)
|
|
153
|
-
if (bundle) {
|
|
154
|
-
console.log(color(`░█ [ELENA]: Generating and minifying JS bundle...`));
|
|
155
|
-
console.log(` `);
|
|
156
186
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
await build2.write({ format, sourcemap, file: `${outdir}/bundle.js` });
|
|
171
|
-
await build2.close();
|
|
187
|
+
for (const { output, ...inputOpts } of configs) {
|
|
188
|
+
if (Array.isArray(inputOpts.input)) {
|
|
189
|
+
for (const entry of inputOpts.input) {
|
|
190
|
+
console.log(color(`░█ [ELENA]: Generating and minifying ${entry}...`));
|
|
191
|
+
}
|
|
192
|
+
} else {
|
|
193
|
+
console.log(color(`░█ [ELENA]: Generating and minifying JS bundle...`));
|
|
194
|
+
console.log(` `);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const build = await rollup(inputOpts);
|
|
198
|
+
await build.write(output);
|
|
199
|
+
await build.close();
|
|
172
200
|
}
|
|
173
201
|
}
|
|
File without changes
|
|
File without changes
|