diff --git a/.gitignore b/.gitignore index c62405e..1088ef5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,8 @@ # Javascript node_modules -typings/* +typings dist npm-debug.log -!typings/tempfix-plugin-tsc-issue-6615.d.ts ## OS X .DS_Store diff --git a/README.md b/README.md index abb854b..f827688 100644 --- a/README.md +++ b/README.md @@ -26,14 +26,15 @@ This step was JUST DONE to produce the repository in the current state, so you d But it may be useful to know how to start from scratch. ``` npm init -y -npm i --save angular reflect-metadata systemjs ng-metadata -npm i --save systemjs-plugin-css system-text -npm i --save-dev typescript tslint +npm i --save angular reflect-metadata ng-metadata +npm i --save systemjs system-text systemjs-plugin-css +npm i --save-dev typescript tslint copyfiles rimraf +typings i -g typings init typings install jquery angular --save --ambient ``` -Folder structure +####Folder structure ``` \ - app <-- contains all your Typescript code | \ - components @@ -43,21 +44,22 @@ Folder structure | | - styles.css <-- sample css styles loaded by plugin | \ - startup.ts <-- entry point boostrap angular app | -| - dist <-- output directory for transpiled code TS->JS +| - dist <-- output directory for transpiled code TS->JS + copied assets css/html | - index.html <-- initial page that load ambient dependency: SystemJS, Reflect-metadata -| - system.config.js <-- SystemJS configuration for loading module starting from 'app/startup' entrypoint -\ - tsconfig.json <-- configure compiler (tsc) to build Typescript code +| - system.conf.js <-- SystemJS configuration for loading module starting from 'app/startup' entrypoint +\ - tsconfig.json <-- configure compiler (tsc) to build Typescript code ``` -Configure [tsconfig.json](tsconfig.json) to build **Typescipt** app files and output js to `dist` folder, -and setup [SystemJS](https://github.com/systemjs/systemjs/blob/master/docs/config-api.md) into [systemjs.config.js](systemjs.config.js) +Configure [tsconfig.json](tsconfig.json) to build **Typescipt** app files and output corresponding (commonjs) JS files to `dist` folder, +and setup [SystemJS](https://github.com/systemjs/systemjs/blob/master/docs/config-api.md) into [systemjs.conf.js](systemjs.conf.js) to load the **Angular** `app` module bootstrapping it with ngMetadata from `app/startup` . -And finally setup some scripts in [package.json](package.json) to automate `build` and `serve` +And finally setup some scripts in [package.json](package.json) to automate `build` , `serve` and copy assets (html/css) to `dist` ###BRANCH `plugins` -This branch use SystemJS [plugins](package.json#L35-L36) to load external resources: [*.html!](app/components/my-app.component.ts#L2) for component and [*.css!](app/startup.ts#L6) style, -see changes in [systemjs.conf.js](systemjs.conf.js#L15-L16) to handle the configuration neccessary. +This branch use SystemJS [plugins](package.json#L38-L39) to load external resources: [require(*.html)](app/components/my-app.component.ts#L2) for component and [import *.css!](app/startup.ts#L6) style, +see [changes][systemjs.conf.js](systemjs.conf.js#L21-L25) in [systemjs.conf.js](systemjs.conf.js#L32-L36) to handle the configuration neccessary. +**NOTE:** To avoid compile error for require, include global ambient definition in [typings-manual-fix.d.ts](typings-manual-fix.d.ts#L2) ###OTHER SETUP AND SAMPLE This repo contains other SystemJS config and TS sample, to test different setup checkout branches: diff --git a/app/components/my-app.component.ts b/app/components/my-app.component.ts index 7e01ed3..1fa4979 100644 --- a/app/components/my-app.component.ts +++ b/app/components/my-app.component.ts @@ -1,14 +1,9 @@ import {Component} from "ng-metadata/core"; -import html from "app/components/my-app.html!"; // LOADING TEMPLATE HTML FROM EXTERNAL FILE WITH .html! SYSTEMJS PLAGIN -// TO AVOID TS2307 ERROR YOU MUST USE ABSOLUTE PATH AND DECLARE MODULE IN typings/tempfix-plugin-tsc-issue-6615.d.ts - -// WIP uncomment this section to load tpl or try this code but it's NOT working and give TS compile error: import tpl from "./my-app.html"; -// declare const require: (moduleOrPath: string) => any; -// const tpl = require("./my-app.html"); +const html = require("./my-app.html"); // require external HTML - relative path is based on .js loaded so need to copy assets in ./dist @Component({ selector: "my-app", - template: html // WIP replate with tpl here + template: html }) export class AppCmp { constructor() {} diff --git a/app/startup.ts b/app/startup.ts index 7545487..ffb7acb 100644 --- a/app/startup.ts +++ b/app/startup.ts @@ -4,6 +4,7 @@ import {AppModule} from "./app.module"; // import CSS (SystemJS will inject it into the document) import "./styles.css!"; // IMPORTING DIRECTLY CSS USING SYSTEMJS PLUGIN css! INCLUDE IT IN HEAD +// ALTERNATIVE: require("./styles.css"); // require external CSS - relative path is based on .js loaded so need to copy assets in ./dist // that boostrap the app.module bootstrap(AppModule); diff --git a/index.html b/index.html index 29cf6bf..df3cfea 100644 --- a/index.html +++ b/index.html @@ -9,7 +9,6 @@ - diff --git a/my-app.html b/my-app.html new file mode 100644 index 0000000..d0aa55a --- /dev/null +++ b/my-app.html @@ -0,0 +1,6 @@ +