Skip to content

Commit 08c3bde

Browse files
authored
feat(custom-esbuild): allow exporting list of plugins (#1658)
1 parent 1e1e8c8 commit 08c3bde

File tree

18 files changed

+171
-96
lines changed

18 files changed

+171
-96
lines changed

examples/custom-esbuild/sanity-esbuild-app-esm/e2e/src/app.e2e-spec.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,10 @@ describe('workspace-project App', () => {
99

1010
it('should display welcome message', () => {
1111
page.navigateTo();
12+
page.getTitle().should('have.text', 'sanity-esbuild-app-esm (compilation provided)');
1213
page
13-
.getTitle()
14-
.should(
15-
'have.text',
16-
'Welcome to sanity-esbuild-app-esm: This text is provided during the compilation!'
17-
);
14+
.getSubtitle()
15+
.should('have.text', 'sanity-esbuild-app-esm subtitle (compilation provided)');
1816
});
1917

2018
it('should display text from custom middleware', () => {

examples/custom-esbuild/sanity-esbuild-app-esm/e2e/src/app.po.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,8 @@ export class AppPage {
66
getTitle() {
77
return cy.get('app-root h1');
88
}
9+
10+
getSubtitle() {
11+
return cy.get('app-root h2');
12+
}
913
}
Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
1-
const defineTextPlugin = {
2-
name: 'define-text',
1+
const defineTitlePlugin = {
2+
name: 'define-title',
33
setup(build) {
44
const options = build.initialOptions;
5-
options.define.buildText = JSON.stringify('This text is provided during the compilation');
5+
options.define.title = JSON.stringify('sanity-esbuild-app-esm (compilation provided)');
66
},
77
};
88

9-
module.exports = defineTextPlugin;
9+
const defineSubtitlePlugin = {
10+
name: 'define-subtitle',
11+
setup(build) {
12+
const options = build.initialOptions;
13+
options.define.subtitle = JSON.stringify(
14+
'sanity-esbuild-app-esm subtitle (compilation provided)'
15+
);
16+
},
17+
};
18+
19+
module.exports = [defineTitlePlugin, defineSubtitlePlugin];
Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
1-
const defineTextPlugin = {
2-
name: 'define-text',
1+
const defineTitlePlugin = {
2+
name: 'define-title',
33
setup(build) {
44
const options = build.initialOptions;
5-
options.define.buildText = JSON.stringify('This text is provided during the compilation');
5+
options.define.title = JSON.stringify('sanity-esbuild-app-esm (compilation provided)');
66
},
77
};
88

9-
export default defineTextPlugin;
9+
const defineSubtitlePlugin = {
10+
name: 'define-subtitle',
11+
setup(build) {
12+
const options = build.initialOptions;
13+
options.define.subtitle = JSON.stringify(
14+
'sanity-esbuild-app-esm subtitle (compilation provided)'
15+
);
16+
},
17+
};
18+
19+
export default [defineTitlePlugin, defineSubtitlePlugin];
Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
import type { Plugin, PluginBuild } from 'esbuild';
22

3-
const defineTextPlugin: Plugin = {
4-
name: 'define-text',
3+
const defineTitlePlugin: Plugin = {
4+
name: 'define-title',
55
setup(build: PluginBuild) {
66
const options = build.initialOptions;
7-
options.define!['buildText'] = JSON.stringify('This text is provided during the compilation');
7+
options.define!['title'] = JSON.stringify('sanity-esbuild-app-esm (compilation provided)');
88
},
99
};
1010

11-
export default defineTextPlugin;
11+
const defineSubtitlePlugin: Plugin = {
12+
name: 'define-subtitle',
13+
setup(build: PluginBuild) {
14+
const options = build.initialOptions;
15+
options.define!['subtitle'] = JSON.stringify(
16+
'sanity-esbuild-app-esm subtitle (compilation provided)'
17+
);
18+
},
19+
};
20+
21+
export default [defineTitlePlugin, defineSubtitlePlugin];
Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,2 @@
1-
<!--The content below is only a placeholder and can be replaced.-->
2-
<div style="text-align: center">
3-
<h1>Welcome to {{ title }}!</h1>
4-
<img
5-
width="300"
6-
alt="Angular Logo"
7-
src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNTAgMjUwIj4KICAgIDxwYXRoIGZpbGw9IiNERDAwMzEiIGQ9Ik0xMjUgMzBMMzEuOSA2My4ybDE0LjIgMTIzLjFMMTI1IDIzMGw3OC45LTQzLjcgMTQuMi0xMjMuMXoiIC8+CiAgICA8cGF0aCBmaWxsPSIjQzMwMDJGIiBkPSJNMTI1IDMwdjIyLjItLjFWMjMwbDc4LjktNDMuNyAxNC4yLTEyMy4xTDEyNSAzMHoiIC8+CiAgICA8cGF0aCAgZmlsbD0iI0ZGRkZGRiIgZD0iTTEyNSA1Mi4xTDY2LjggMTgyLjZoMjEuN2wxMS43LTI5LjJoNDkuNGwxMS43IDI5LjJIMTgzTDEyNSA1Mi4xem0xNyA4My4zaC0zNGwxNy00MC45IDE3IDQwLjl6IiAvPgogIDwvc3ZnPg=="
8-
/>
9-
</div>
10-
<h2>Here are some links to help you start:</h2>
11-
<ul>
12-
<li>
13-
<h2><a target="_blank" rel="noopener" href="https://angular.io/tutorial">Tour of Heroes</a></h2>
14-
</li>
15-
<li>
16-
<h2><a target="_blank" rel="noopener" href="https://angular.io/cli">CLI Documentation</a></h2>
17-
</li>
18-
<li>
19-
<h2><a target="_blank" rel="noopener" href="https://blog.angular.io/">Angular blog</a></h2>
20-
</li>
21-
</ul>
1+
<h1>{{ title }}</h1>
2+
<h2>{{ subtitle }}</h2>
Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1-
import { CommonModule } from '@angular/common';
21
import { Component } from '@angular/core';
32

4-
declare const buildText: string;
3+
declare const title: string;
4+
declare const subtitle: string;
55

66
@Component({
77
selector: 'app-root',
88
templateUrl: './app.component.html',
99
styleUrls: ['./app.component.scss'],
1010
standalone: true,
11-
imports: [CommonModule],
1211
})
1312
export class AppComponent {
14-
buildText = typeof buildText !== 'undefined' ? buildText : '';
13+
title: string;
14+
subtitle: string;
1515

16-
title = this.buildText ? `sanity-esbuild-app-esm: ${this.buildText}` : 'sanity-esbuild-app-esm';
16+
constructor() {
17+
this.title = typeof title !== 'undefined' ? title : 'sanity-esbuild-app-esm';
18+
this.subtitle = typeof subtitle !== 'undefined' ? subtitle : 'sanity-esbuild-app-esm subtitle';
19+
}
1720
}

examples/custom-esbuild/sanity-esbuild-app/e2e/src/app.e2e-spec.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,8 @@ describe('workspace-project App', () => {
99

1010
it('should display welcome message', () => {
1111
page.navigateTo();
12-
page
13-
.getTitle()
14-
.should(
15-
'have.text',
16-
'Welcome to sanity-esbuild-app: This text is provided during the compilation!'
17-
);
12+
page.getTitle().should('have.text', 'sanity-esbuild-app (compilation provided)');
13+
page.getSubtitle().should('have.text', 'sanity-esbuild-app subtitle (compilation provided)');
1814
});
1915

2016
it('should display text from custom middleware', () => {

examples/custom-esbuild/sanity-esbuild-app/e2e/src/app.po.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,8 @@ export class AppPage {
66
getTitle() {
77
return cy.get('app-root h1');
88
}
9+
10+
getSubtitle() {
11+
return cy.get('app-root h2');
12+
}
913
}
Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1-
const defineTextPlugin = {
2-
name: 'define-text',
1+
const defineTitlePlugin = {
2+
name: 'define-title',
33
setup(build) {
44
const options = build.initialOptions;
5-
options.define.buildText = JSON.stringify('This text is provided during the compilation');
5+
options.define.title = JSON.stringify('sanity-esbuild-app (compilation provided)');
66
},
77
};
88

9-
module.exports = defineTextPlugin;
9+
const defineSubtitlePlugin = {
10+
name: 'define-subtitle',
11+
setup(build) {
12+
const options = build.initialOptions;
13+
options.define.subtitle = JSON.stringify('sanity-esbuild-app subtitle (compilation provided)');
14+
},
15+
};
16+
17+
module.exports = [defineTitlePlugin, defineSubtitlePlugin];

0 commit comments

Comments
 (0)