Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
angular2-rollup
Advanced tools
[![Join the chat at https://gitter.im/angular2-rollup/Lobby](https://badges.gitter.im/angular2-rollup/Lobby.svg)](https://gitter.im/angular2-rollup/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
A complete, yet simple, starter for Angular 2 using AOT Compile and Rollup. Now supports 4.0.0+ and Library Builds!
This repo serves as an Angular 2 starter for anyone looking to get up and running fast with Angular 2 and TypeScript and Ahead Of Time (AOT) compilation. We're using ngc for compiling AOT and Rollup for bundling our files for production. The development server compiles just in time (JIT) using Typescript and SystemJS for fast and efficient development.
node
scripts written with ShellJS allow for cross platform support for the dev environment. A boilerplate Express server is also included with support for livereload.
We're also using Protractor for our end-to-end story and Karma for our unit tests.
$ git clone https://github.com/steveblue/angular2-rollup my-app
$ cd my-app
$ npm install
$ npm install -g angular2-rollup
Change the host and/or port in /conf/config.local.js
if needed. This config is used for the Express Server.
{
origin: 'localhost',
port: 4200
};
$ ngr --build dev
$ ngr --build prod
$ ngr --serve
$ ngr --build dev --serve
What you need to run this app:
node
and npm
(Use NVM)v6.5.x
+)fork
this repoclone
your forknpm i -g webdriver-manager
npm install
Server configuration happens per environment. Currently two environments are supported: dev
and prod
. Create config files for each environment in the conf/
directory called config.local.js
and config.prod.js
.
The configuration file only takes two arguments for now: origin
and port
. server.js
uses this configuration to initialize an Express Server either for development or production. A basic config looks like this:
const config = {
origin: 'localhost',
port: 4200
};
module.exports = config;
When everything is setup correctly, you should be able to visit http://localhost:4200 in your browser.
After you have installed all dependencies you can now build the project:
$ ngr --build dev --serve
build.env.js
will build the application for development for the appropriate environment. server.js
will start a local server using Express and liveserver
will watch for changes in the /build
directory. The development environment bootstraps Angular with JIT Compiler for fast and efficient development compared to AOT.
NOTE: If you find issues scaling the test environment, please submit a Pull Request with bug fixes and feature requests.
npm test
ngr --build dev --serve
npm run webdriver:start
npm run e2e
npm run e2e:live
The production build is quite different than development. While the development server uses Angular Just In Time (JIT) compilation in conjunction with tsc
, the production build uses ngc to compile the Angular 2 application Ahead of Time (AOT).
ngc
compiles the files in /src
to /tmp
,
Rollup bundles the files and their dependencies into build/bundle.es2015.js
.
Closure Compiler optimizes the bundle and outputs ES5 for the browser.
Since the bundle is still ES2015, we need to transpile the bundle into ES5. For this purpose, we tested multiple solutions and found the best option to be Closure Compiler.
In order to build for production, you need to install Closure Compiler. Closure Compiler is the only tool that we found would transpile the ES2015 Rollup Bundle to ES5 with 100% reliability after it was processed with ngc
. Closure Compiler is also a great solution because it optimizes the bundle and does code checking after Rollup tree shakes the application. Google uses Closure Compiler internally to optimize JavaScript files for production.
To run Closure Compiler, you need to install the Java SDK and the application file found at the bottom of this page. Rename the .jar file (ex: closure-compiler-v20160822.jar ) to compiler.jar
and copy it into the project root directory (./compiler.jar
). This file is in the .gitignore
, which is why you have to manually install it. We tested the JavaScript version of Closure Compiler and found it resulted in out of process memory
issues with multiple versions of node
, which is why the Java application is necessary.
To build an application for production, run the following command.
$ ngr --build prod
You can now deploy the /build
folder to your server!
This starter code includes a CLI that allows you to build and start up an Express Server without npm run
. The CLI also includes commands for generating new code snippets similar to Angular CLI.
To use the CLI install the npm package globally. webdriver-manager
should also be installed globally if it isn't already.
npm i -g webdriver-manager
npm i -g angular2-rollup
##CLI Commands
Displays the help documentation for using the ngr
CLI.
ngr --build dev --watch
Builds development environment, runs watcherngr --build prod
Builds production environmentngr --generate component --name todo-list --spec
Generate a TodoListComponent
in the current directory with a spec filengr --generate directive --name todo-list --dir path/to/folder
Generate a TodoListDirective
in a folderngr -g module -n todo-list -r
Generate a TodoListModule
in a folder with a routes.ts fileYou can pass the following types to --generate
:
Configure prefixes for Classes, Component and Directive selector in build.config.js
.
Omit the properties from the config to operate without prefixes.
ngr --build dev --watch --serve
Builds development environment, runs watcher and starts up Express ServerYes, as of right now this starter package will not handle this for you. The typical Angular 2 dependencies have been added already. Configure more dependencies to be included in your web app in build.config.js
. A script runs that copies each dependency from node_modules
into /build/lib
(or wherever you specify in the config). You can then reference the library in src/public/index.html
like so:
<script src="/lib/zone.js/dist/zone.js"></script>
<script src="/lib/reflect-metadata/Reflect.js"></script>
or with SystemJS like so:
<script>
Promise.all([
System.import('firebase'),
System.import('app')
]);
</script>
npm i -g rimraf
npm run clean:install
It's simple, just install the library via npm, add the library to the build in build.config.js
and inject the library via SystemJS in src/public/system.config.js
and in some cases index.html
for development. For Production, a different, minimal configuration for the bundle is required in src/public/system.config.prod.js
and system.import.js
.
You can bundle external dependencies with Rollup. Out of the box there is support for projects that use ES2015 modules in rollup.config.js
. For instance, we alias the ES2015 version of rxjs when bundling like so:
plugins: [
replace({ 'ENVIRONMENT': JSON.stringify( 'production' ) }),
resolve({ module: true }),
cleanup()
]
A Rollup plugin does exist that will transform commonjs modules to ES2015 for the bundle called rollup-plugin-commonjs
and it is included in package.json by default.
Livereload is still available in this mode, however you have to go an extra step to unlock this feature for the prod build. We recommend usingnpm run build:dev
for development, since JIT compile allows for a faster workflow. In cases where you want to test the production build on a local machine with the watcher you can use the following command: npm run build:prod watch=true
Then, start up the production server
NODE_ENV=prod npm run dev:server watch=true
For livereload to work in the browser for the production build you currently you have to edit src/public/index.html
.
Copy the livereload script
to the build:remove:dev
comment near the end of the file. It should look like the example below.
<script>
document.write('<script src="http://' + (location.host || 'localhost').split(':')[0] +
':35729/livereload.js?snipver=1"></' + 'script>')
</script>
<!-- /build -->
<!-- build:remove:dev -->
<script src="system.import.js"></script>
<script>
document.write('<script src="http://' + (location.host || 'localhost').split(':')[0] +
':35729/livereload.js?snipver=1"></' + 'script>')
</script>
<!-- /build -->
It is not recommended that you deploy the livereload script to production. If anyone has a clever workaround for this please submit a Pull Request with the change.
ngr --build lib
With Angular 4.0, there is an established contract between the Angular team, library authors, and application developers that describes a format for Angular Component libraries.
This project includes a build that produces a library based on the recommendation found here Angular Package Format 4.0. npm run build:lib
supports AOT compile, treeshaking, and multiple bundlers. More more information, watch @jasonaden at ng-conf 2017 where presented a talk called Packaging Angular.
Boilerplate library files are found in src/lib/
.
To take full advantage of TypeScript with autocomplete you would have to use an editor with the correct TypeScript plugins.
We have good experience using these editors:
FAQs
[![Join the chat at https://gitter.im/angular2-rollup/Lobby](https://badges.gitter.im/angular2-rollup/Lobby.svg)](https://gitter.im/angular2-rollup/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
The npm package angular2-rollup receives a total of 4 weekly downloads. As such, angular2-rollup popularity was classified as not popular.
We found that angular2-rollup demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.