Skip to content

Commit 8f96147

Browse files
committed
updated for cli 7'
1 parent 3987c1e commit 8f96147

File tree

8 files changed

+1668
-943
lines changed

8 files changed

+1668
-943
lines changed

lib/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Extend the Angular CLI's default build behavior without ejecting:
44

55
- 📦 Build a single bundle (e. g. for Angular Elements)
66
- 📄 Extend the default behavior by providing a **partial** config that just contains your additional settings
7+
- 📄 Alternative: Extend the default behavior by providing a custom function
78
- ☑️ Inherits from the default builder, hence you have the same options
89
- 🍰 Simple to use
910
- ⏏️ No eject needed
@@ -208,4 +209,28 @@ declare let VERSION: string;
208209
console.debug('VERSION', VERSION);
209210
```
210211

212+
## Using a custom function to modify the webpack config
211213

214+
For more advanced modifications you can provide a function that gets the webpack config passed and returns the modified one.
215+
216+
Follow the following steps to try it out:
217+
218+
1. Add a file with a config hook to your project (``hook/hook.ts``):
219+
220+
```typescript
221+
export default (cfg) => {
222+
console.debug('config', cfg);
223+
// mess around with wepback config here ...
224+
return cfg;
225+
}
226+
```
227+
228+
2. Compile your solution using ``tsc``.
229+
230+
3. Use the ``configHook`` switch to point to the compiled version of your hook:
231+
232+
```
233+
ng build --configHook ~dist/out-tsc/hook/hook
234+
```
235+
236+
The prefix ``~`` is replaced with your current directory. If you don't use it, it points to a installed ``node_module``.

lib/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ngx-build-plus",
3-
"version": "6.2.0",
3+
"version": "7.0.0",
44
"description": "Extensible Builder for the Angular CLI suitable not only for Angular Elements.",
55
"license": "MIT",
66
"repository": {
@@ -21,9 +21,9 @@
2121
"webpack-merge": "^4.1.2"
2222
},
2323
"peerDependencies": {
24-
"@angular-devkit/architect": "^0.7.1",
25-
"@angular-devkit/build-angular": "^0.7.1",
26-
"@angular-devkit/core": "^0.7.1",
24+
"@angular-devkit/architect": "~0.10.0",
25+
"@angular-devkit/build-angular": "~0.10.0",
26+
"@angular-devkit/core": "~0.10.0",
2727
"rxjs": "^6.0.0"
2828
},
2929
"devDependencies": {

lib/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@
77
*/
88

99
export * from './plus';
10-
export * from './plus-dev-server';
10+
export * from './plus-dev-server';
11+
export * from './ext/hook';

lib/src/plus/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,13 @@ export class PlusBuilder extends BrowserBuilder {
3434
}
3535

3636
if (options.configHook) {
37-
const hook = require(options.configHook).default as ConfigHookFn;
37+
let configHook = options.configHook;
38+
39+
if (configHook.startsWith('~')) {
40+
configHook = process.cwd() + '/' + configHook.substr(1);
41+
}
42+
43+
const hook = require(configHook).default as ConfigHookFn;
3844
config = hook(config);
3945
}
4046

readme.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Extend the Angular CLI's default build behavior without ejecting:
44

55
- 📦 Build a single bundle (e. g. for Angular Elements)
66
- 📄 Extend the default behavior by providing a **partial** config that just contains your additional settings
7+
- 📄 Alternative: Extend the default behavior by providing a custom function
78
- ☑️ Inherits from the default builder, hence you have the same options
89
- 🍰 Simple to use
910
- ⏏️ No eject needed
@@ -208,4 +209,28 @@ declare let VERSION: string;
208209
console.debug('VERSION', VERSION);
209210
```
210211

212+
## Using a custom function to modify the webpack config
211213

214+
For more advanced modifications you can provide a function that gets the webpack config passed and returns the modified one.
215+
216+
Follow the following steps to try it out:
217+
218+
1. Add a file with a config hook to your project (``hook/hook.ts``):
219+
220+
```typescript
221+
export default (cfg) => {
222+
console.debug('config', cfg);
223+
// mess around with wepback config here ...
224+
return cfg;
225+
}
226+
```
227+
228+
2. Compile your solution using ``tsc``.
229+
230+
3. Use the ``configHook`` switch to point to the compiled version of your hook:
231+
232+
```
233+
ng build --configHook ~dist/out-tsc/hook/hook
234+
```
235+
236+
The prefix ``~`` is replaced with your current directory. If you don't use it, it points to a installed ``node_module``.

sample/hook/hook.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export default (cfg) => {
2+
console.debug('config', cfg);
3+
return cfg;
4+
}

0 commit comments

Comments
 (0)