Git Product home page Git Product logo

babel-preset-angular2's Introduction

babel-preset-angular2

A Babel preset for angular2.

This preset includes the following plugins:

  • babel-plugin-angular2-annotations
  • babel-plugin-transform-decorators-legacy
  • babel-plugin-transform-class-properties
  • babel-plugin-transform-flow-strip-types

Installation

npm install -D babel-preset-angular2 babel-preset-es2015

Usage

Add the following line to your .babelrc file:

{
  "presets": ["es2015", "angular2"]
}

See babel-angular2-app for more complete example.

babel-preset-angular2's People

Contributors

douglasduteil avatar shuhei avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

douglasduteil

babel-preset-angular2's Issues

Upgraded from a2 annotations and get errors

I was using your previous projects:

"babel-core": "^6.8.0",
"babel-plugin-angular2-annotations": "^5.1.0",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-plugin-transform-flow-strip-types": "^6.8.0",

and upgraded to this project and get the following error now:

TypeError: Cannot read property 'query' of null(…) "TypeError: Cannot read property 'query' of null
    at eval (http://localhost:8080/jspm_packages/npm/@angular/[email protected]/src/provider_parser.js:360:37)
    at Array.forEach (native)
    at eval (http://localhost:8080/jspm_packages/npm/@angular/[email protected]/src/provider_parser.js:359:31)
    at Array.forEach (native)
    at _getContentQueries (http://localhost:8080/jspm_packages/npm/@angular/[email protected]/src/provider_parser.js:355:16)
    at new ProviderElementContext (http://localhost:8080/jspm_packages/npm/@angular/[email protected]/src/provider_parser.js:55:32)
    at TemplateParseVisitor.visitElement (http://localhost:8080/jspm_packages/npm/@angular/[email protected]/src/template_parser.js:282:31)
    at HtmlElementAst.visit (http://localhost:8080/jspm_packages/npm/@angular/[email protected]/src/html_ast.js:59:83)
    at eval (http://localhost:8080/jspm_packages/npm/@angular/[email protected]/src/html_ast.js:76:29)
    at Array.forEach (native)"

Is this supposed to be compatible with the above?

Unexpected value 'Module1' imported by the module 'Module2'. Please add a @NgModule annotation.

Hi,

I would like to create an exportable angular module. So I created this module :

// index.js

import { NgModule, Component } from '@angular/core';

@Component({
    selector: 'module1-component',
    template: '<h1>Module 1</h1>'
})
class Module1Component {
    constructor() {}
}

@NgModule({
    imports: [],
    declarations: [Module1Component],
    providers: [],
    exports: [Module1Component]
})
export class Module1 {}

with this package.json

{
  "name": "module1",
  "main": "index.js",
  "babel": {
    "presets": [
      "es2015",
      "angular2"
    ]
  },
  "browserify": {
    "transform": [
      ["babelify"]
    ]
  },
  "dependencies": {
    "@angular/common": "^4.4.4",
    "@angular/compiler": "^4.4.4",
    "@angular/core": "^4.4.4"
  },
  "devDependencies": {
    "babel-preset-angular2": "0.0.2",
    "babel-preset-es2015": "^6.24.1",
    "babelify": "^7.3.0",
    "browserify": "^14.4.0"
  }
}

Next I created another module which will import my first module and I linked module1 with module2 by npm link module1

import 'babel-polyfill';
import 'zone.js/dist/zone';

import { NgModule, Component } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

import { Module1 } from 'module1';

@Component({
    selector: 'module2-component',
    template: `
        <h1>Module 2</h1>
        <module1-component></module1-component>
    `
})
class Module2Component {
    constructor () {}
}

@NgModule({
    imports: [BrowserModule, Module1],
    declarations: [Module2Component],
    providers: [],
    bootstrap: [Module2Component],
})
class Module2 {}

platformBrowserDynamic().bootstrapModule(Module2);

with this package.json

{
  "name": "module2",
  "version": "0.1.0",
  "main": "index.js",
  "babel": {
    "presets": [
      "es2015",
      "angular2"
    ]
  },
  "dependencies": {
    "@angular/common": "^4.4.4",
    "@angular/compiler": "^4.4.4",
    "@angular/core": "^4.4.4",
    "@angular/platform-browser": "^4.4.4",
    "@angular/platform-browser-dynamic": "^4.4.4",
    "babel-polyfill": "^6.26.0",
    "rxjs": "^5.4.3",
    "zone.js": "^0.8.18"
  },
  "devDependencies": {
    "babel": "^6.23.0",
    "babel-preset-angular2": "0.0.2",
    "babel-preset-es2015": "^6.24.1",
    "babelify": "^7.3.0",
    "browserify": "^14.4.0"
  }
}

And when I built module2 with browserify src/app.js -o dist/app.js -t [ babelify ] and I looked the result I had this error :

Unexpected value 'Module1' imported by the module 'Module2'. Please add a @NgModule annotation.

I think the error is due to the transpilation when importing Module1 (it has no more annotation).

Have you any ideas ? Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.