Skip to content

Commit 9fbd32b

Browse files
authored
feat(custom-esbuild): add support for plugin configuration (#1683)
1 parent 02dc5ee commit 9fbd32b

File tree

17 files changed

+217
-16
lines changed

17 files changed

+217
-16
lines changed

examples/custom-esbuild/sanity-esbuild-app-esm/angular.json

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,15 @@
1717
"build": {
1818
"builder": "@angular-builders/custom-esbuild:application",
1919
"options": {
20-
"plugins": ["esbuild/define-text-plugin.js"],
20+
"plugins": [
21+
"esbuild/define-text-plugin.js",
22+
{
23+
"path": "esbuild/define-text-by-option-plugin.js",
24+
"options": {
25+
"title": "sanity-esbuild-app-esm optionTitle (compilation provided)"
26+
}
27+
}
28+
],
2129
"outputPath": "dist/sanity-esbuild-app-esm",
2230
"index": "src/index.html",
2331
"browser": "src/main.ts",
@@ -45,13 +53,37 @@
4553
"outputHashing": "all"
4654
},
4755
"esm": {
48-
"plugins": ["esbuild/define-text-plugin.js"]
56+
"plugins": [
57+
"esbuild/define-text-plugin.js",
58+
{
59+
"path": "esbuild/define-text-by-option-plugin.js",
60+
"options": {
61+
"title": "sanity-esbuild-app-esm optionTitle (compilation provided)"
62+
}
63+
}
64+
]
4965
},
5066
"cjs": {
51-
"plugins": ["esbuild/define-text-plugin.cjs"]
67+
"plugins": [
68+
"esbuild/define-text-plugin.cjs",
69+
{
70+
"path": "esbuild/define-text-by-option-plugin.cjs",
71+
"options": {
72+
"title": "sanity-esbuild-app-esm optionTitle (compilation provided)"
73+
}
74+
}
75+
]
5276
},
5377
"tsEsm": {
54-
"plugins": ["esbuild/define-text-plugin.ts"]
78+
"plugins": [
79+
"esbuild/define-text-plugin.ts",
80+
{
81+
"path": "esbuild/define-text-by-option-plugin.ts",
82+
"options": {
83+
"title": "sanity-esbuild-app-esm optionTitle (compilation provided)"
84+
}
85+
}
86+
]
5587
}
5688
},
5789
"defaultConfiguration": "production"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
function defineTitleByOptionPlugin(pluginOptions) {
2+
return {
3+
name: 'define-title',
4+
setup(build) {
5+
const options = build.initialOptions;
6+
options.define.titleByOption = JSON.stringify(pluginOptions.title);
7+
},
8+
};
9+
};
10+
11+
module.exports = defineTitleByOptionPlugin;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
function defineTitleByOptionPlugin(pluginOptions) {
2+
return {
3+
name: 'define-title',
4+
setup(build) {
5+
const options = build.initialOptions;
6+
options.define.titleByOption = JSON.stringify(pluginOptions.title);
7+
},
8+
};
9+
};
10+
11+
export default defineTitleByOptionPlugin;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import type { Plugin, PluginBuild } from 'esbuild';
2+
3+
function defineTitleByOptionPlugin(pluginOptions: {title: string}): Plugin {
4+
return {
5+
name: 'define-title',
6+
setup(build: PluginBuild) {
7+
const options = build.initialOptions;
8+
options.define!['titleByOption'] = JSON.stringify(pluginOptions.title);
9+
},
10+
};
11+
};
12+
13+
export default defineTitleByOptionPlugin;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
<h1>{{ title }}</h1>
22
<h2>{{ subtitle }}</h2>
3+
<h3>{{ titleByOption }}</h3>

examples/custom-esbuild/sanity-esbuild-app-esm/src/app/app.component.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Component } from '@angular/core';
22

33
declare const title: string;
44
declare const subtitle: string;
5+
declare const titleByOption: string;
56

67
@Component({
78
selector: 'app-root',
@@ -12,9 +13,11 @@ declare const subtitle: string;
1213
export class AppComponent {
1314
title: string;
1415
subtitle: string;
16+
titleByOption: string;
1517

1618
constructor() {
1719
this.title = typeof title !== 'undefined' ? title : 'sanity-esbuild-app-esm';
1820
this.subtitle = typeof subtitle !== 'undefined' ? subtitle : 'sanity-esbuild-app-esm subtitle';
21+
this.titleByOption = typeof titleByOption !== 'undefined' ? titleByOption : 'sanity-esbuild-app-esm optionTitle';
1922
}
2023
}

examples/custom-esbuild/sanity-esbuild-app/angular.json

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,15 @@
1717
"build": {
1818
"builder": "@angular-builders/custom-esbuild:application",
1919
"options": {
20-
"plugins": ["esbuild/define-text-plugin.js"],
20+
"plugins": [
21+
"esbuild/define-text-plugin.js",
22+
{
23+
"path": "esbuild/define-text-by-option-plugin.js",
24+
"options": {
25+
"title": "sanity-esbuild-app optionTitle (compilation provided)"
26+
}
27+
}
28+
],
2129
"outputPath": "dist/sanity-esbuild-app",
2230
"index": "src/index.html",
2331
"browser": "src/main.ts",
@@ -45,10 +53,26 @@
4553
"outputHashing": "all"
4654
},
4755
"esm": {
48-
"plugins": ["esbuild/define-text-plugin.mjs"]
56+
"plugins": [
57+
"esbuild/define-text-plugin.mjs",
58+
{
59+
"path": "esbuild/define-text-by-option-plugin.mjs",
60+
"options": {
61+
"title": "sanity-esbuild-app optionTitle (compilation provided)"
62+
}
63+
}
64+
]
4965
},
5066
"cjs": {
51-
"plugins": ["esbuild/define-text-plugin.js"]
67+
"plugins": [
68+
"esbuild/define-text-plugin.js",
69+
{
70+
"path": "esbuild/define-text-by-option-plugin.js",
71+
"options": {
72+
"title": "sanity-esbuild-app optionTitle (compilation provided)"
73+
}
74+
}
75+
]
5276
}
5377
},
5478
"defaultConfiguration": "production"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
function defineTitleByOptionPlugin(pluginOptions) {
2+
return {
3+
name: 'define-title',
4+
setup(build) {
5+
const options = build.initialOptions;
6+
options.define.titleByOption = JSON.stringify(pluginOptions.title);
7+
},
8+
};
9+
};
10+
11+
module.exports = defineTitleByOptionPlugin;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
function defineTitleByOptionPlugin(pluginOptions) {
2+
return {
3+
name: 'define-title',
4+
setup(build) {
5+
const options = build.initialOptions;
6+
options.define.titleByOption = JSON.stringify(pluginOptions.title);
7+
},
8+
};
9+
};
10+
11+
export default defineTitleByOptionPlugin;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
<h1>{{ title }}</h1>
22
<h2>{{ subtitle }}</h2>
3+
<h3>{{ titleByOption }}</h3>

0 commit comments

Comments
 (0)