Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement] Support TS for indexTransform #689

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
c00ba0e
Register TS compiler lazily
vixnguyen Feb 24, 2020
7b227a8
update README.md about a new supported extension for index transform
vixnguyen Feb 24, 2020
33ded94
write tsNodeRegister and use in different files
vixnguyen Feb 25, 2020
00bd992
write example for index-transform.ts
vixnguyen Feb 25, 2020
7b44543
adding test case: using indextransform without custom webpack
vixnguyen Feb 25, 2020
5c3f101
adding config for e2e test
vixnguyen Feb 25, 2020
d10a595
change test config
vixnguyen Feb 25, 2020
e10a5ea
remove customWebpackConfig
vixnguyen Feb 25, 2020
7cea4dd
adding file replacement
vixnguyen Feb 25, 2020
496a503
change itwcw protractor
vixnguyen Feb 25, 2020
b4f5ca4
using configuration instead of shorthand
vixnguyen Feb 25, 2020
3f2d0ed
adding text to debug
vixnguyen Feb 25, 2020
8299fa6
remove itwcw test
vixnguyen Feb 25, 2020
42cd272
remove prod test add itwcw
vixnguyen Feb 25, 2020
433c1b1
change to index-transform.js for debug
vixnguyen Feb 25, 2020
4803719
adding customWebpackConfig with null value
vixnguyen Feb 25, 2020
5f3dea8
change to index-html.transform.ts to debug
vixnguyen Feb 25, 2020
81be7c2
mark to debug where the error from
vixnguyen Feb 25, 2020
131c2b0
change content of index-html.transform.ts
vixnguyen Feb 25, 2020
bdb6a74
Revert "change content of index-html.transform.ts"
vixnguyen Feb 25, 2020
1bf4ef8
Revert "mark to debug where the error from"
vixnguyen Feb 25, 2020
b372c54
Revert "change to index-html.transform.ts to debug"
vixnguyen Feb 25, 2020
b406161
Revert "adding customWebpackConfig with null value"
vixnguyen Feb 25, 2020
40926cc
Revert "change to index-transform.js for debug"
vixnguyen Feb 25, 2020
de833d6
Revert "remove prod test add itwcw"
vixnguyen Feb 25, 2020
48b9b29
Revert "remove itwcw test"
vixnguyen Feb 25, 2020
1c51a69
Revert "adding text to debug"
vixnguyen Feb 25, 2020
c347875
Revert "using configuration instead of shorthand"
vixnguyen Feb 25, 2020
0ef806c
fix issue can not load module default
vixnguyen Feb 25, 2020
aacdbd0
only test itwcw
vixnguyen Feb 25, 2020
e15108a
fit specs for itwcw
vixnguyen Feb 25, 2020
05b03a6
create utility file and put tsNodeRegister into it
vixnguyen Feb 26, 2020
c555a4f
use type for index
vixnguyen Feb 26, 2020
fa491a4
define targer options & export to use as external
vixnguyen Feb 27, 2020
a370421
apply to example & update doc
vixnguyen Feb 27, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion packages/custom-webpack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ module.exports = async config => {
**_Requires `@angular-devkit/[email protected]` and `@angular-builders/[email protected]`._**

Since Angular 8 `index.html` is not generated as part of the Webpack build. If you want to modify your `index.html` you should use `indexTransform` option.
`indexTransform` is a path (relative to workspace root) to a `.js` file that exports transformation function for `index.html`.
`indexTransform` is a path (relative to workspace root) to a `.js` or `.ts` file that exports transformation function for `index.html`.
vixnguyen marked this conversation as resolved.
Show resolved Hide resolved
Function signature is as following:

```typescript
Expand Down Expand Up @@ -409,6 +409,20 @@ module.exports = (targetOptions, indexHtml) => {
};
```

Alternatively, using TypeScript:

```ts
import { TargetOptions } from '@angular-builders/custom-webpack';

export default (targetOptions: TargetOptions, indexHtml: string) => {
const i = indexHtml.indexOf('</body>');
const config = `<p>Configuration: ${targetOptions.configuration}</p>`;
return `${indexHtml.slice(0, i)}
${config}
${indexHtml.slice(i)}`;
};
```

In the example we add a paragraph with build configuration to your `index.html`. It is a very simple example without any asynchronous code but you can also return a `Promise` from this function.

Full example [here](https://github.com/just-jeb/angular-builders/tree/master/packages/custom-webpack/examples/full-cycle-app).
Expand Down
10 changes: 10 additions & 0 deletions packages/custom-webpack/examples/full-cycle-app/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@
"maximumError": "10kb"
}
]
},
"itwcw": {
"customWebpackConfig": null,
"indexTransform": "./index-html.transform.ts"
}
}
},
Expand All @@ -79,6 +83,9 @@
"configurations": {
"production": {
"browserTarget": "full-cycle-app:build:production"
},
"itwcw": {
"browserTarget": "full-cycle-app:build:itwcw"
}
}
},
Expand Down Expand Up @@ -128,6 +135,9 @@
"configurations": {
"production": {
"devServerTarget": "full-cycle-app:serve:production"
},
"itwcw": {
"devServerTarget": "full-cycle-app:serve:itwcw"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const config = require('./protractor-ci.conf').config;

config.specs = ['./src/**/*.e2e-spec-itwcw.ts'];

exports.config = config;
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { AppPage } from './app.po';

describe('workspace-project App', () => {
let page: AppPage;

beforeEach(() => {
page = new AppPage();
});

it('should display paragraph coming from transform function', async () => {
await page.navigateTo();
expect(await page.getParagraphText()).toEqual('Configuration: itwcw');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { TargetOptions } from '@angular-builders/custom-webpack';

export default (targetOptions: TargetOptions, indexHtml: string) => {
const i = indexHtml.indexOf('</body>');
const config = `<p>Configuration: ${targetOptions.configuration}</p>`;
return `${indexHtml.slice(0, i)}
${config}
${indexHtml.slice(i)}`;
};
Loading