injection-js-transformer
v0.0.3
Published
injection-js typescript transformer
Downloads
4
Maintainers
Readme
TypeScript Transformer for injection-js
TypeScript Transformer for injection-js, inspired by angular-cli.
Why need this
- No more
emitDecoratorMetadata
needed. - No more
reflection
,reflect-metadata
orcore-js
needed. - Make your code tree-shakeable.
How it works
The transformer would convert the following code:
import { Injectable, Optional, SkipSelf } from "injection-js";
@Injectable()
export class DependencyService {}
@Injectable()
export class DIService {
constructor(
@SkipSelf()
@Optional()
private dependencyService: DependencyService
) {}
}
into
import { Injectable, Optional, SkipSelf, Inject } from "injection-js";
export class DependencyService {
}
export class DIService {
constructor(private dependencyService: DependencyService) { }
static parameters = [[new Optional(), new SkipSelf(), new Inject(DependencyService)]];
}
How to use it with webpack
npm install injection-js-transformer
import { resolve } from "path";
import { Program } from "typescript";
import injectionTransformer from "injection-js-transformer";
const config = {
module: {
rules: [
{
test: /.ts$/,
use: [
{
loader: "ts-loader",
options: {
configFile: resolve(__dirname, "./tsconfig.json"),
getCustomTransformers: (program: Program) => {
return {
before: [injectionTransformer(program)],
};
},
},
},
],
},
],
},
};
export default config;
License
MIT