leonardfactory / babel-plugin-transform-typescript-metadata

Babel plugin to emit decorator metadata like typescript compiler
MIT License
216 stars 17 forks source link

Example usage with babel standalone #41

Closed ChristopherHButler closed 3 years ago

ChristopherHButler commented 3 years ago

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

ChristopherHButler commented 3 years ago

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',
  },