leonardfactory / babel-plugin-transform-typescript-metadata

Babel plugin to emit decorator metadata like typescript compiler

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Example usage with babel standalone

ChristopherHButler opened this issue · comments

Is there an example of how to use your plugin with babel standalone? Is it just the same as with babelrc? I get the following error if I try to use it:

Error: Invalid plugin specified in Babel options: "babel-plugin-transform-typescript-metadata"

I am creating an online code editor that and I wanted to use your plugin with babel to transpile (Angular) TypeScript but I can't seem to get Angular services working using @Injectable. Any help would be greatly appreciated

Ok I was able to get this working with babel standalone by installing your plugin into my project and writing my babel config options like this (in case anyone else is interested):

const TS_OPTIONS = {
  presets: [
    ['typescript', { allExtensions: true }],
    ['es2017', { 'modules': false }],
  ],
  plugins: [
    [require('babel-plugin-transform-typescript-metadata').default],
    ["proposal-decorators", { "legacy": true }],
    ["proposal-class-properties", { "loose": true }],
    'transform-modules-commonjs',
  ],
};

and this should be added to webpack:

  node: {
    fs: 'empty',
  },