Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add @ngx-build-plus and a dummy typescript transformer
- Add build instructions in readme
- Loading branch information
Showing
6 changed files
with
264 additions
and
645 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,9 @@ | ||
# NgTsTransformer | ||
# Typescript transformations using ngx-build-plus | ||
|
||
This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 7.3.6. | ||
## Compiling the ngx-build-plus plugin | ||
|
||
## Development server | ||
Run `tsc --skipLibCheck --module umd -w`. | ||
|
||
Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files. | ||
## NG build using the plugin | ||
|
||
## Code scaffolding | ||
|
||
Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`. | ||
|
||
## Build | ||
|
||
Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `--prod` flag for a production build. | ||
|
||
## Running unit tests | ||
|
||
Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io). | ||
|
||
## Running end-to-end tests | ||
|
||
Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/). | ||
|
||
## Further help | ||
|
||
To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md). | ||
Run `ng build --aot --plugin ~dist/out-tsc/ng-ts-register-transformer.js`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import * as ts from 'typescript'; | ||
|
||
export const dummyTransformer = <T extends ts.Node>(context: ts.TransformationContext) => { | ||
return (rootNode: ts.SourceFile) => { | ||
console.log('Transforming file: ' + rootNode.fileName); | ||
function visit(node: ts.Node): ts.Node { | ||
return ts.visitEachChild(node, visit, context); | ||
} | ||
return ts.visitNode(rootNode, visit); | ||
}; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { dummyTransformer } from './ng-ts-dummy-transformer'; | ||
import { AngularCompilerPlugin } from '@ngtools/webpack'; | ||
|
||
function findAngularCompilerPlugin(webpackCfg): AngularCompilerPlugin | null { | ||
return webpackCfg.plugins.find(plugin => plugin instanceof AngularCompilerPlugin); | ||
} | ||
|
||
// The AngularCompilerPlugin has nog public API to add transformations, user private API _transformers instead. | ||
function addTransformerToAngularCompilerPlugin(acp, transformer): void { | ||
acp._transformers = [transformer, ctx => (sf => sf) , ...acp._transformers]; | ||
} | ||
|
||
export default { | ||
pre() { | ||
// This hook is not used in our example | ||
}, | ||
|
||
// This hook is used to manipulate the webpack configuration | ||
config(cfg) { | ||
// Find the AngularCompilerPlugin in the webpack configuration | ||
const angularCompilerPlugin = findAngularCompilerPlugin(cfg); | ||
|
||
if (!angularCompilerPlugin) { | ||
console.error('Could not inject the typescript transformer: Webpack AngularCompilerPlugin not found'); | ||
return; | ||
} | ||
|
||
addTransformerToAngularCompilerPlugin(angularCompilerPlugin, dummyTransformer); | ||
return cfg; | ||
}, | ||
|
||
post() { | ||
// This hook is not used in our example | ||
} | ||
}; |
Oops, something went wrong.