Skip to content

Commit

Permalink
updated for cli 7'
Browse files Browse the repository at this point in the history
  • Loading branch information
manfredsteyer committed Oct 22, 2018
1 parent 3987c1e commit 8f96147
Show file tree
Hide file tree
Showing 8 changed files with 1,668 additions and 943 deletions.
25 changes: 25 additions & 0 deletions lib/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Extend the Angular CLI's default build behavior without ejecting:

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

## Using a custom function to modify the webpack config

For more advanced modifications you can provide a function that gets the webpack config passed and returns the modified one.

Follow the following steps to try it out:

1. Add a file with a config hook to your project (``hook/hook.ts``):

```typescript
export default (cfg) => {
console.debug('config', cfg);
// mess around with wepback config here ...
return cfg;
}
```

2. Compile your solution using ``tsc``.

3. Use the ``configHook`` switch to point to the compiled version of your hook:

```
ng build --configHook ~dist/out-tsc/hook/hook
```

The prefix ``~`` is replaced with your current directory. If you don't use it, it points to a installed ``node_module``.
8 changes: 4 additions & 4 deletions lib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ngx-build-plus",
"version": "6.2.0",
"version": "7.0.0",
"description": "Extensible Builder for the Angular CLI suitable not only for Angular Elements.",
"license": "MIT",
"repository": {
Expand All @@ -21,9 +21,9 @@
"webpack-merge": "^4.1.2"
},
"peerDependencies": {
"@angular-devkit/architect": "^0.7.1",
"@angular-devkit/build-angular": "^0.7.1",
"@angular-devkit/core": "^0.7.1",
"@angular-devkit/architect": "~0.10.0",
"@angular-devkit/build-angular": "~0.10.0",
"@angular-devkit/core": "~0.10.0",
"rxjs": "^6.0.0"
},
"devDependencies": {
Expand Down
3 changes: 2 additions & 1 deletion lib/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
*/

export * from './plus';
export * from './plus-dev-server';
export * from './plus-dev-server';
export * from './ext/hook';
8 changes: 7 additions & 1 deletion lib/src/plus/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@ export class PlusBuilder extends BrowserBuilder {
}

if (options.configHook) {
const hook = require(options.configHook).default as ConfigHookFn;
let configHook = options.configHook;

if (configHook.startsWith('~')) {
configHook = process.cwd() + '/' + configHook.substr(1);
}

const hook = require(configHook).default as ConfigHookFn;
config = hook(config);
}

Expand Down
25 changes: 25 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Extend the Angular CLI's default build behavior without ejecting:

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

## Using a custom function to modify the webpack config

For more advanced modifications you can provide a function that gets the webpack config passed and returns the modified one.

Follow the following steps to try it out:

1. Add a file with a config hook to your project (``hook/hook.ts``):

```typescript
export default (cfg) => {
console.debug('config', cfg);
// mess around with wepback config here ...
return cfg;
}
```

2. Compile your solution using ``tsc``.

3. Use the ``configHook`` switch to point to the compiled version of your hook:

```
ng build --configHook ~dist/out-tsc/hook/hook
```

The prefix ``~`` is replaced with your current directory. If you don't use it, it points to a installed ``node_module``.
4 changes: 4 additions & 0 deletions sample/hook/hook.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export default (cfg) => {
console.debug('config', cfg);
return cfg;
}
Loading

0 comments on commit 8f96147

Please sign in to comment.