Comments (3)
Up on further investigation, I got it to work using (in rollup config):
import typescript from '@rollup/plugin-typescript'
...
plugins: [typescript({
transformers: {
before: [ { type: 'program', factory: (program) => di({program}).before[0] } ],
after: [ { type: 'program', factory: (program) => di({program}).after[0] } ]
}
})]
This generates the correct bundle like:
container.registerSingleton(undefined, { identifier: 'HackerNewsService', implementation: HackerNewsService });
But the javascript code for all of my classes (like HackerNewsService
above) are omitted. And thus running into HackerNewsService is not defined
errors.
from di-compiler.
Hi there,
The DI-Compiler must be passed a TypeScript Program since it depends on a type checker. That's why you need to pass the program on to it.
Your example doesn't work, though, as you pass the DI Custom Transformer twice, one for the before
hook and one for the after
hook. That's not correct usage of it. The DI custom transformer must be passed a program, and it itself returns a structure of the form {before, after}.
If you experience issues with interoperability between @rollup/plugin-typescript
and Custom Transformers such as DI-Compiler, I suggest that you open an issue with a minimal repro over at the Rollup plugins monorepo. Specifically, it should be able to handle Custom Transformers that implement multiple hooks, such as DI-compiler, that does things in both the before and after hooks.
In the meantime, you can use DI-Compiler with rollup-plugin-ts
which is tested and verified to be working correctly.
from di-compiler.
Hi,
I've wrote a workaround helper for @rollup/plugin-typescript to easly apply this transformer. Here is the npm link
Usage:
import typescript from "@rollup/plugin-typescript";
import { di } from "@wessberg/di-compiler";
import { applyTransformer } from "rollup-typescript-custom-transformer-helper";
(...)
typescript({
sourceMap: true,
inlineSources: true,
transformers: {
...applyTransformer((program) => di({ program })),
},
}),
from di-compiler.
Related Issues (18)
- Issues with derived classes transpiled by Typescript HOT 1
- Jest example HOT 1
- Impossible to add in provider interfaces with generics. HOT 2
- Does not work with webpack ts-loader HOT 4
- Is there any special compiler options required? HOT 1
- Usage with Vite.js HOT 2
- Is there a way to get compilation error when the service is not registered at all?
- Extended services without constructors doesn't work. HOT 2
- Support for async service factories HOT 16
- Esbuild plugin support
- JSX support for transform() API method
- ttypescript deprecated and replaced with ts-patch
- ReferenceError: 1 argument required, but only 0 present HOT 6
- DI-compiler fails to build due to change in TypeScript and @wessberg/ts-config
- Build a graph to discover cyclic dependencies and automatically apply proxies to defeat them HOT 1
- Bindings not generated with Parcel HOT 1
- is it possible to use with babel/preset-typescript ? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from di-compiler.