{"__v":70,"_id":"5546245d6bea270d0047d4cb","category":{"__v":5,"_id":"5511b00e316c512300151cd3","pages":["5511b00e316c512300151cd5","5546245d6bea270d0047d4cb","554641183dca710d00464754","5586b99f867b5e0d0006c4b8","55891e38060aef190086aace"],"project":"5511b00d316c512300151ccf","version":"5511b00d316c512300151cd2","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-03-24T18:42:22.203Z","from_sync":false,"order":0,"slug":"quickstart","title":"Quickstart"},"project":"5511b00d316c512300151ccf","user":"5511afda316c512300151cce","version":{"__v":11,"_id":"5511b00d316c512300151cd2","project":"5511b00d316c512300151ccf","createdAt":"2015-03-24T18:42:21.658Z","releaseDate":"2015-03-24T18:42:21.658Z","categories":["5511b00e316c512300151cd3","55462d123dca710d0046471b","55462d1e35b2240d008389f1","55462ee63dca710d0046471c","5586aedcd23ef40d00de6e95","5586aef0f8942c0d00293dd3","5586bc28867b5e0d0006c4bc","5586bce4f8942c0d00293ddf","5586c209f8942c0d00293def","5587d09eeb5f2421003f9781","558ba534cf331f23002046cf"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-05-03T13:36:29.718Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":1,"body":"By default, Angular Express kickstarts a modern Angular 1.x application that features:\n\n- automatic compilation of ES6 with [Babel](https://babeljs.io/)\n- pre-configured package management using [jspm](http://jspm.io/)\n- dynamic module loading using the [SystemJS dynamic ES6 loader](https://github.com/systemjs/systemjs)\n- pre-configured unit testing with [karma](http://karma-runner.github.io/), [mocha](http://mochajs.org/), [chai](http://chaijs.com/) and [PhantomJS](http://phantomjs.org/)\n- powerful built-in server based on [Express 4](http://expressjs.com/) and [Harp](http://harpjs.com/) with preprocessor support for [Jade](http://jade-lang.com/), [Markdown](http://daringfireball.net/projects/markdown/), [EJS](http://www.embeddedjs.com/), [Coffeescript](http://coffeescript.org/), [Sass](http://sass-lang.com/), [LESS](http://lesscss.org/) and [Stylus](https://learnboost.github.io/stylus/).\n- compile to HTML, CSS & JavaScript and host it anywhere\n\nFirst install the Angular Express CLI tool:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"$ npm install -g ngx-cli\",\n      \"language\": \"shell\",\n      \"name\": null\n    }\n  ]\n}\n[/block]\nthen use `ngx init` to kickstart your new project:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"# Create a project directory\\n$ mkdir new-project\\n$ cd new-project\\n\\n# Initialize a new project\\n$ ngx init\\n\\n# Install project dependencies\\n$ npm install\\n$ jspm install\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\nThe default boilerplate comes with powerful pre-configured development tools so you can start working on your application immediately:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"# Start the development server that uses jspm and systemjs\\n# to dynamically load all scripts\\n$ npm run development-server\\n\\n# Run unit tests\\n$ npm test\\n\\n# Build all scripts to a minified bundle\\n$ npm build\\n\\n# Start a production server that uses a minified bundle\\n# of the scripts\\n$ npm run production-server\\n\\n# Compile a static version of your project to dist directory\\n$ npm run compile\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\n## Start the development server\n\nFrom the root of your project, run:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"# Start server in development mode\\n$ npm run development-server\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\nand navigate your browser to `http://localhost:9000`.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/77fvl2hYSvuUIaYl5n4i_ngx-boilerplate-default-running.png\",\n        \"ngx-boilerplate-default-running.png\",\n        \"834\",\n        \"720\",\n        \"#4196af\",\n        \"\"\n      ]\n    }\n  ]\n}\n[/block]\nIf you open up the console and refresh the page, you will see that jspm dynamically loads all the required scripts.\n\nSourcemaps are available to make debugging as convenient as possible.\n\n## Start the production server\n\nFrom the root of your project, run:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"# Build a minified script bundle\\n$ npm run build\\n\\n# Start server in production mode\\n$ npm run production-server\",\n      \"language\": \"text\"\n    }\n  ]\n}\n[/block]\nand navigate your browser to `http://localhost:9000`.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/SKnxmOmjQ6KvEMEFWpPQ_ngx-boilerplate-default-running.png\",\n        \"ngx-boilerplate-default-running.png\",\n        \"834\",\n        \"720\",\n        \"#4196af\",\n        \"\"\n      ]\n    }\n  ]\n}\n[/block]\nNow open up the console again and refresh the page. You will notice that all script requests have been replaced by one request to `app/build.js`.\n\n## Compile your project to a static website\n\nFrom the root of your project, run:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"$ npm run compile\",\n      \"language\": \"text\"\n    }\n  ]\n}\n[/block]\nand a static version of your project will be generated in the `dist` directory.\n\nYou can host this static version on any HTTP server.\n[block:callout]\n{\n  \"type\": \"info\",\n  \"body\": \"If you use [HTML5 mode](https://docs.angularjs.org/guide/$location) in Angular, you will need to configure your server to rewrite URL's.\"\n}\n[/block]\n## But wait, there is more!\n\nAfter kickstarting your project you can easily add small Angular Express components on top of it:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"# Add a component to handle ui-router state-not-found events\\n$ ngx install angular-ui-router-state-not-found-handler\\n\\n# Add a component to handle ui-router state-change errors\\n$ ngx install angular-ui-router-state-change-error-handler\\n\\n# Add a component to customize Bootstrap 3 using LESS\\n$ ngx install less-custom-bootstrap3\\n\\n# Add some components that contain boilerplate to create ui-router states\\n$ ngx install angular-ui-router-component src/components/homepage\\n$ ngx install angular-ui-router-component src/components/about\\n$ ngx install angular-ui-router-component src/components/contact\\n\\n$ ...\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\nand import them in your Angular application as ES6 modules:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"import angular from 'angular';\\n\\nimport errorHandler from 'components/angular-ui-router-state-change-error-handler/_build/index';\\nimport homepage from 'components/hompage/_build/index';\\nimport about from 'components/about/_build/index';\\nimport contact from 'components/contact/_build/index';\\n\\n/**************************************************************************\\n * Define Angular application\\n *************************************************************************/\\n\\nvar ngModule = angular.module('app', []);\\n\\nngModule.run(function () {\\n  console.log('Angular bootstrapped!');\\n});\\n\\n/**************************************************************************\\n * Initialize components and pass component specific options\\n *************************************************************************/\\n\\nerrorHandler(ngModule, { baseUrl: '/components/angular-ui-router-state-change-error-handler' });\\nhomepage(ngModule, { baseUrl: '/components/homepage' });\\nabout(ngModule, { baseUrl: '/components/about' });\\ncontact(ngModule, { baseUrl: '/components/contact' });\\n\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n\nto scaffold entire applications in just seconds!\n\nEach component can accept component specific options making them highly reusable and flexible. In the example above, components are passed a `baseUrl` to prepend to links in the view templates.\n[block:callout]\n{\n  \"type\": \"info\",\n  \"body\": \"Once your application has been scaffolded, you can start adding your own code without having to worry about Angular Express.\\n\\nAngular Express is not tied to your project or does not create hidden files in your repository. There are no dependencies either. It scaffolds the code for you and then backs off. No strings attached.\\n\\nIf, at any stage in your project, you want to add an additional existing component, you can run `ngx install` from the root of your project to install as many additional components as you like.\"\n}\n[/block]\n\n\n## In short\n\nAngular Express allows you to kickstart Angular applications by:\n\n- initializing a **boilerplate** using `ngx init`\n- adding components to your application using `ngx install`\n\nSimple. Fast. Clean.\n\n## What's next?\n\n- [Why Angular Express?](doc:why-angular-express) \n- [Why not use Yeoman?](doc:why-not-use-yeoman)\n\n## Popular\n\n- [Learn more about the default Angular 1.x web application boilerplate](https://github.com/ngx-boilerplates/default)","excerpt":"","slug":"quick-example","type":"basic","title":"Quick example"}
By default, Angular Express kickstarts a modern Angular 1.x application that features: - automatic compilation of ES6 with [Babel](https://babeljs.io/) - pre-configured package management using [jspm](http://jspm.io/) - dynamic module loading using the [SystemJS dynamic ES6 loader](https://github.com/systemjs/systemjs) - pre-configured unit testing with [karma](http://karma-runner.github.io/), [mocha](http://mochajs.org/), [chai](http://chaijs.com/) and [PhantomJS](http://phantomjs.org/) - powerful built-in server based on [Express 4](http://expressjs.com/) and [Harp](http://harpjs.com/) with preprocessor support for [Jade](http://jade-lang.com/), [Markdown](http://daringfireball.net/projects/markdown/), [EJS](http://www.embeddedjs.com/), [Coffeescript](http://coffeescript.org/), [Sass](http://sass-lang.com/), [LESS](http://lesscss.org/) and [Stylus](https://learnboost.github.io/stylus/). - compile to HTML, CSS & JavaScript and host it anywhere First install the Angular Express CLI tool: [block:code] { "codes": [ { "code": "$ npm install -g ngx-cli", "language": "shell", "name": null } ] } [/block] then use `ngx init` to kickstart your new project: [block:code] { "codes": [ { "code": "# Create a project directory\n$ mkdir new-project\n$ cd new-project\n\n# Initialize a new project\n$ ngx init\n\n# Install project dependencies\n$ npm install\n$ jspm install", "language": "shell" } ] } [/block] The default boilerplate comes with powerful pre-configured development tools so you can start working on your application immediately: [block:code] { "codes": [ { "code": "# Start the development server that uses jspm and systemjs\n# to dynamically load all scripts\n$ npm run development-server\n\n# Run unit tests\n$ npm test\n\n# Build all scripts to a minified bundle\n$ npm build\n\n# Start a production server that uses a minified bundle\n# of the scripts\n$ npm run production-server\n\n# Compile a static version of your project to dist directory\n$ npm run compile", "language": "shell" } ] } [/block] ## Start the development server From the root of your project, run: [block:code] { "codes": [ { "code": "# Start server in development mode\n$ npm run development-server", "language": "shell" } ] } [/block] and navigate your browser to `http://localhost:9000`. [block:image] { "images": [ { "image": [ "https://files.readme.io/77fvl2hYSvuUIaYl5n4i_ngx-boilerplate-default-running.png", "ngx-boilerplate-default-running.png", "834", "720", "#4196af", "" ] } ] } [/block] If you open up the console and refresh the page, you will see that jspm dynamically loads all the required scripts. Sourcemaps are available to make debugging as convenient as possible. ## Start the production server From the root of your project, run: [block:code] { "codes": [ { "code": "# Build a minified script bundle\n$ npm run build\n\n# Start server in production mode\n$ npm run production-server", "language": "text" } ] } [/block] and navigate your browser to `http://localhost:9000`. [block:image] { "images": [ { "image": [ "https://files.readme.io/SKnxmOmjQ6KvEMEFWpPQ_ngx-boilerplate-default-running.png", "ngx-boilerplate-default-running.png", "834", "720", "#4196af", "" ] } ] } [/block] Now open up the console again and refresh the page. You will notice that all script requests have been replaced by one request to `app/build.js`. ## Compile your project to a static website From the root of your project, run: [block:code] { "codes": [ { "code": "$ npm run compile", "language": "text" } ] } [/block] and a static version of your project will be generated in the `dist` directory. You can host this static version on any HTTP server. [block:callout] { "type": "info", "body": "If you use [HTML5 mode](https://docs.angularjs.org/guide/$location) in Angular, you will need to configure your server to rewrite URL's." } [/block] ## But wait, there is more! After kickstarting your project you can easily add small Angular Express components on top of it: [block:code] { "codes": [ { "code": "# Add a component to handle ui-router state-not-found events\n$ ngx install angular-ui-router-state-not-found-handler\n\n# Add a component to handle ui-router state-change errors\n$ ngx install angular-ui-router-state-change-error-handler\n\n# Add a component to customize Bootstrap 3 using LESS\n$ ngx install less-custom-bootstrap3\n\n# Add some components that contain boilerplate to create ui-router states\n$ ngx install angular-ui-router-component src/components/homepage\n$ ngx install angular-ui-router-component src/components/about\n$ ngx install angular-ui-router-component src/components/contact\n\n$ ...", "language": "shell" } ] } [/block] and import them in your Angular application as ES6 modules: [block:code] { "codes": [ { "code": "import angular from 'angular';\n\nimport errorHandler from 'components/angular-ui-router-state-change-error-handler/_build/index';\nimport homepage from 'components/hompage/_build/index';\nimport about from 'components/about/_build/index';\nimport contact from 'components/contact/_build/index';\n\n/**************************************************************************\n * Define Angular application\n *************************************************************************/\n\nvar ngModule = angular.module('app', []);\n\nngModule.run(function () {\n console.log('Angular bootstrapped!');\n});\n\n/**************************************************************************\n * Initialize components and pass component specific options\n *************************************************************************/\n\nerrorHandler(ngModule, { baseUrl: '/components/angular-ui-router-state-change-error-handler' });\nhomepage(ngModule, { baseUrl: '/components/homepage' });\nabout(ngModule, { baseUrl: '/components/about' });\ncontact(ngModule, { baseUrl: '/components/contact' });\n", "language": "javascript" } ] } [/block] to scaffold entire applications in just seconds! Each component can accept component specific options making them highly reusable and flexible. In the example above, components are passed a `baseUrl` to prepend to links in the view templates. [block:callout] { "type": "info", "body": "Once your application has been scaffolded, you can start adding your own code without having to worry about Angular Express.\n\nAngular Express is not tied to your project or does not create hidden files in your repository. There are no dependencies either. It scaffolds the code for you and then backs off. No strings attached.\n\nIf, at any stage in your project, you want to add an additional existing component, you can run `ngx install` from the root of your project to install as many additional components as you like." } [/block] ## In short Angular Express allows you to kickstart Angular applications by: - initializing a **boilerplate** using `ngx init` - adding components to your application using `ngx install` Simple. Fast. Clean. ## What's next? - [Why Angular Express?](doc:why-angular-express) - [Why not use Yeoman?](doc:why-not-use-yeoman) ## Popular - [Learn more about the default Angular 1.x web application boilerplate](https://github.com/ngx-boilerplates/default)