
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
angular-build
Advanced tools
A Build System for Angular 2 web app development using the Gulp build system. This module forked from Modern Web Dev Build. All kudos goes to Sebastien, I have just added features I tend to use. You can see a seed project using this Build System.
This was the primary feature I felt was missing, maybe I missed something and this isn't necessary but it is how I develop, so I forked the repository. The proxy server provides stubbed API calls to the back-end server. The proxy middleware is provided by http-proxy-middleware and is configured and developed by the application project, not this package. I tend to use express, but that isn't crucial. To setup the proxy, add configuration to the options object in the project gulpfile e.g.
options.proxy = {
api: '/api',
target: 'http://localhost',
port: 8000
};
The api is the URL path to listen on e.g. /api/init, /api/login etc. The target and the port identify where
to forward requests to. So, requests to http://localhost:8000/api/login would be sent to the proxy and the
response from it returned to the application. This enables us to develop the front-end separately from the back-end
server, all we have to do is agree an API.
The proxy server itself is defined by the project using this Build System but if the above configuration exists, then the proxy task must also be implemented, see an example of of such a task
Added ability to configure where the application code exists, this was previously hard-coded to the project root but that seemed limiting. To override the location add to the gulpfile e.g.
options.folders = {};
options.folders.app = './src/main/app';
This seemed a very basic omission, I used gulp-sass-lint NPM package to provide the functionality, it is up to the application whether to override the default options or not by providing a sass-lint.yml file, the structure of which you can learn about at sass-lint.
Check out the change log
As state above, some important technology choices are clearly embedded with this project. Here's a rundown of those choices:
Check out the upgrade page
Before you install the build, you need to install some dependencies globally:
npm install --global gulpFirst configure the required dependencies in your package.json file:
npm install node-build-web-app --save-devnpm install --no-optionalYou should get warnings about missing peer dependencies. Those are dependencies that are required by the build but that you should add to your own project, install these one by one.
For now the required peer dependencies are as follows:
Next, check the minimal require file contents below!
The build tries to provide a flexible structure, but given the technical choices that are embedded, some rules must be respected and the build expects certain folders and files to be present. In the future we'll see if we can make this more configurable.
Here's an overview of the structure imposed by this Build System.
Please make sure to check the file organization section for more background about the organization and usage guidelines.
Although we want to limit this list as much as possible, for everything to build successfully, some files need specific contents:
{
"presets": ["es2015"],
"plugins": ["transform-es2015-modules-commonjs"],
"comments": false
}
With the configuration above, Babel will transpile ES2015 code to ES5 commonjs. For that configuration to work, the following devDependencies must also be added to your project:
"babel-plugin-transform-es2015-modules-commonjs": "6.3.x",
"babel-preset-es2015": "6.3.x",
In order to use this Build System, your gulpfile must at least contain the following. The code below uses ES2015 (via gulpfile.babel.js), but if you're old school you can also simply use a gulpfile.js with ES5.
Note that the build tasks provided are transpiled to ES5 before being published
"use strict";
import gulp from "gulp";
import build from "node-build-web-app";
let options = undefined; // no options are supported yet
//options.minifyHTML = false;
//...
build.registerTasks(gulp, options);
With the above, all the gulp tasks provided will be available to you. See a full example
Valid configuration
At least the following:
node_modules/**/*
jspm_packages/**/*
jspm.conf.js
dist/**/*
.tmp/**/*
The SystemJS/JSPM configuration file plays a very important role;
If you choose to use the default JSPM support, then you can add dependencies to your project using jspm install;
check the official JSPM documentation to know more about how to install packages.
With the help of this configuration file, SystemJS will be able to load your own application modules and well as third
party dependencies. In your code, you'll be able to use ES2015 style (e.g., import {x} from "y"). In order for this
to work, you'll also need to load SystemJS and the SystemJS/JSPM configuration file in your index.html (more on this
afterwards).
If you have disabled the use of JSPM by the build then you can rename that file if you wish and inform the build (see the options), BUT make sure that any reference in the various configuration files is updated (e.g., karma configuration, jshint configuration, etc). Only rename it if it is really really useful to you :)
Here's an example:
System.config({
defaultJSExtensions: true,
transpiler: false,
paths: {
"github:*": "jspm_packages/github/*",
"npm:*": "jspm_packages/npm/*",
"core/*": "./.tmp/core/*",
"pages/*": "./.tmp/pages/*"
}
});
In the above:
In addition to the dependencies listed previously, you also need to have the following in your package.json file, assuming that you want to use JSPM:
"jspm": {
"directories": {},
"configFile": "jspm.conf.js",
"dependencies": {
},
"devDependencies: {
}
}
This is where you let JSPM know where to save the information about dependencies you install. This is also where you
can easily add new dependencies; for example: "angular2": "npm:angular2@^2.0.0-beta.1",. Once a dependency is added
there, you can invoke jspm install to get the files and transitive dependencies installed and get an updated
jspm.conf.js file.
Given that TypeScript is one of the (currently) embedded choices of this project, the TypeScript configuration file is mandatory.
The tsconfig.json file contains:
Here's is the minimal required contents. Note that the outDir value is important as it tells the compiler where to
write the generated code! Make sure that you also DO have the rootDir property defined and pointing to "./app",
otherwise the build will fail (more precisely, npm run serve will fail).
The build depends on the presence of those settings.
{
"version": "1.7.3",
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"declaration": false,
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true,
"removeComments": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"noEmitOnError": false,
"preserveConstEnums": true,
"inlineSources": false,
"sourceMap": false,
"outDir": "./.tmp",
"rootDir": "./app",
"moduleResolution": "node",
"listFiles": false
},
"exclude": [
"node_modules",
"jspm_packages",
"typings/browser",
"typings/browser.d.ts"
]
}
Here's a more complete example including code style rules:
{
"version": "1.7.3",
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"declaration": false,
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true,
"removeComments": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"noEmitOnError": false,
"preserveConstEnums": true,
"inlineSources": false,
"sourceMap": false,
"outDir": "./.tmp",
"rootDir": "./app",
"moduleResolution": "node",
"listFiles": false
},
"formatCodeOptions": {
"indentSize": 2,
"tabSize": 4,
"newLineCharacter": "\r\n",
"convertTabsToSpaces": false,
"insertSpaceAfterCommaDelimiter": true,
"insertSpaceAfterSemicolonInForStatements": true,
"insertSpaceBeforeAndAfterBinaryOperators": true,
"insertSpaceAfterKeywordsInControlFlowStatements": true,
"insertSpaceAfterFunctionKeywordForAnonymousFunctions": false,
"insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis": false,
"placeOpenBraceOnNewLineForFunctions": false,
"placeOpenBraceOnNewLineForControlBlocks": false
},
"exclude": [
"node_modules",
"jspm_packages",
"typings/browser",
"typings/browser.d.ts"
]
}
Note the exclusion that we have made, all of which are relevant and there to avoid known issues (e.g., https://github.com/typings/discussions/issues/6 if you are using typings).
tslint.json is the configuration file for TSLint.
Although it is not strictly mandatory (the build will work without this file), we heavily recommend you to use it as it is very useful to ensure a minimal code quality level and can help you avoid common mistakes and unnecessary complicated code:
Here's an example:
{
"rules": {
"class-name": true,
"curly": true,
"eofline": true,
"forin": true,
"indent": [false, "tabs"],
"interface-name": false,
"label-position": true,
"label-undefined": true,
"max-line-length": false,
"no-any": false,
"no-arg": true,
"no-bitwise": true,
"no-console": [false,
"debug",
"info",
"time",
"timeEnd",
"trace"
],
"no-construct": true,
"no-debugger": true,
"no-duplicate-key": true,
"no-duplicate-variable": true,
"no-empty": true,
"no-eval": true,
"no-imports": true,
"no-string-literal": false,
"no-trailing-comma": true,
"no-unused-variable": false,
"no-unreachable": true,
"no-use-before-declare": null,
"one-line": [true,
"check-open-brace",
"check-catch",
"check-else",
"check-whitespace"
],
"quotemark": [true, "double"],
"radix": true,
"semicolon": true,
"triple-equals": [true, "allow-null-check"],
"variable-name": false,
"no-trailing-whitespace": true,
"whitespace": [false,
"check-branch",
"check-decl",
"check-operator",
"check-separator",
"check-type",
"check-typecast"
]
}
}
Karma loads his configuration from karma.conf.js. That file contains everything that Karma needs to know to execute your unit tests.
Here's an example configuration file that uses Jasmine. Note that the main Karma dependencies including PhantomJS are included in the build. You only need to add a dependency to jasmine, karma-jasmine and karma-jspm for the following to work.
If you choose not to use JSPM, then you can use karma-systemjs instead: https://www.npmjs.com/package/karma-systemjs
Example:
// Karma configuration
// reference: http://karma-runner.github.io/0.13/config/configuration-file.html
module.exports = function (config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
//basePath: ".tmp/",
plugins: [
"karma-jspm",
"karma-jasmine",
"karma-phantomjs-launcher",
"karma-chrome-launcher",
"karma-firefox-launcher",
"karma-ie-launcher",
"karma-junit-reporter",
"karma-spec-reporter"
],
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: [
"jspm",
"jasmine"
],
// list of files / patterns to load in the browser (loaded before SystemJS)
files: [],
// list of files to exclude
exclude: [],
// list of paths mappings
// can be used to map paths served by the Karma web server to /base/ content
// knowing that /base corresponds to the project root folder (i.e., where this config file is located)
proxies: {
"/.tmp": "/base/.tmp" // without this, karma-jspm can't load the files
},
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {},
// test results reporter to use
// possible values: 'dots', 'progress', 'spec', 'junit'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
// https://www.npmjs.com/package/karma-junit-reporter
// https://www.npmjs.com/package/karma-spec-reporter
reporters: ["spec"],
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: [
"PhantomJS"
//"Chrome",
//"Firefox",
//"PhantomJS",
//"IE"
],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false,
junitReporter: {
outputFile: "target/reports/tests-unit/unit.xml",
suite: "unit"
},
// doc: https://www.npmjs.com/package/karma-jspm
// reference config: https://github.com/gunnarlium/babel-jspm-karma-jasmine-istanbul
jspm: {
// Path to your SystemJS/JSPM configuration file
config: "jspm.conf.js",
// Where to find jspm packages
//packages: "jspm_packages",
// One use case for this is to only put test specs in loadFiles, and jspm will only load the src files when and if the test files require them.
loadFiles: [
// load all tests
".tmp/*.spec.js", // in case there are tests in the root folder
".tmp/**/*.spec.js"
],
// Make additional files/a file pattern available for jspm to load, but not load it right away.
serveFiles: [
".tmp/**/!(*.spec).js" // make sure that all files are available
],
// SystemJS configuration specifically for tests, added after your config file.
// Good for adding test libraries and mock modules
paths: {}
}
});
};
Dev dependencies to add for the above Karma configuration:
"jasmine": "...",
"karma-jasmine": "...",
"karma-jspm": "..."
Although we want to limit this list as much as possible, for everything to build successfully, some files need specific contents:
This should be the top element of your application. This should be loaded by core/boot.ts (see below).
"use strict";
export class App {
...
constructor(){
console.log("Hello world!");
}
}
The boot.ts file is the entrypoint of your application. Currently, it is mandatory for this file to exist (with that specific name), although that could change or be customizable later.
The contents are actually not important but here's a starting point:
"use strict";
import {App} from "core/app";
// bootstrap your app
The main.scss file is where you should load all the stylesheets scattered around in your application.
Here's an example of a main.scss:
//
// Main stylesheet.
// Should import all the other stylesheets
//
// Variables, functions, mixins and utils
@import "base/variables";
@import "base/functions";
@import "base/mixins";
@import "base/utils";
// Base/generic style rules
@import "base/reset";
@import "base/responsive";
@import "base/fonts";
@import "base/typography";
@import "base/base";
// Layout
@import "layout/layout";
@import "layout/theme";
@import "layout/print";
// Components
@import "../components/posts/posts";
// Pages
@import "../pages/home/home";
In the example above, you can see that in the main.scss file, we import many other stylesheets (sass partials).
Here's another example, this time for vendor.scss:
//
// Includes/imports all third-party stylesheets used throughout the application.
// Should be loaded before the application stylesheets
//
// Nicolas Gallagher's Normalize.css
@import '../../jspm_packages/github/necolas/normalize.css@3.0.3/normalize.css'; // the path refers to the file at BUILD time
As you can see above, a third-party stylesheet is imported.
The index.html file is the entrypoint of your application. It is not mandatory per se, but when you run npm run serve,
it'll be opened. Also, the html build task will try and replace/inject content in it.
Here's the minimal required contents for index.html (required for production builds with minification and bundling):
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
...
<!-- Stylesheets -->
<!-- build:css-vendor -->
<link rel="stylesheet" href="styles/vendor.css">
<!-- endbuild -->
<!-- build:css-bundle -->
<link rel="stylesheet" href="styles/main.css">
<!-- endbuild -->
</head>
<body>
<!-- build:js-app -->
<!-- for production, this is all replaced by a minified bundle -->
<script src="jspm_packages/system.src.js"></script>
<script src="jspm.conf.js"></script>
<script>
System.import('core/core.bootstrap').catch(console.error.bind(console));
</script>
<!-- endbuild -->
</body>
</html>
In the above, the most important parts are:
<!-- build:css-vendor --> ... <!-- endbuild --> will be replaced by the vendor bundle created by the build<!-- build:css-bundle --> ... <!-- endbuild --> will be replaced by the application's CSS bundle created by the build<!-- build:js-app --> ... <!-- endbuild --> will be replaced by the application's JS bundle created by the buildAlso, note that during development, SystemJS is loaded (system.src.js), the JSPM configuration is loaded (jspm.conf.js) and SystemJS is used to load the entrypoint of the application (core/core.bootstrap).
Once you have added this build system to your project, you can list all the available commands using gulp help.
The command will give you a description of each task. The most important to start discovering are:
gulp serve: start a Web server with live reload, watching files, transpiling, generating sourcemaps, etcgulp serve-dist: same with the production versiongulp cleangulp ts-lint: check TypeScript code quality/stylegulp check-js-quality: check JavaScript code qualitygulp check-js-style: check JavaScript code stylegulp prepare-test-unit: clean, compile and check quality/stylegulp test-unit: run unit tests using Karma (prereq: gulp prepare-test-unitYou can run the gulp -T command get an visual idea of the links between the different tasks.
To make your life easier, you can add the following scripts to your package.json file. Note that if you have used the generator to create your project, you normally have these already:
"scripts": {
"tsc": "tsc",
"typings": "typings",
"clean": "gulp clean",
"compile": "gulp",
"build": "npm run compile && npm run test",
"test": "gulp prepare-test-unit && gulp test-unit",
"start": "npm run serve",
"serve": "nodemon --watch gulpfile.js --watch gulpfile.babel.js --watch package.json --watch .jshintrc --watch .jscsrc --watch tsconfig.json --watch tslint.json --watch jspm.conf.js --exec gulp serve",
"serve-dist": "nodemon --watch gulpfile.js --watch gulpfile.babel.js --watch package.json --watch .jshintrc --watch .jscsrc --watch tsconfig.json --watch tslint.json --watch jspm.conf.js --exec gulp serve-dist",
"update": "npm install --no-optional && jspm update && jspm dl-loader && npm run typings-install",
"outdated": "npm outdated",
"help": "gulp help",
"typings-install": "typings install",
"setup": "npm install --no-optional && jspm install && jspm dl-loader && npm run typings-install"
}
The build can be customized by passing options. Defining options is done as in the following example gulpfile.babel.js:
"use strict";
import gulp from "gulp";
import build from "node-build-web-app";
let options = {};
options.distEntryPoint = "core/core.bootstrap";
Available options:
core/boot.jsinline <path to the JS file> right above the script tag that you want to have inlined; this tells the
gulp-inline-source plugin where to find the resource that should be inlinedinline attribute to the script tag itself: <script inline src="..."></script>Example:
<!-- inline ../node_modules/angular2/bundles/angular2-polyfills.js -->
<script inline src="node_modules/angular2/bundles/angular2-polyfills.js"></script>
Note that the path specified in the <!-- inline ... comment is relative to the root of your project and NOT to the html file
Check out gulp-inline-source's documentation for more details.
If you want to build from source, you need to:
npm install --global gulpnpm run setupnpm run buildTo clean, you can run npm run clean
The project includes multiple configuration files. Here's some information about these:
This project and all associated source code is licensed under the terms of the MIT License.
FAQs
Build Angular 2/JSPM with Gulp. Forked from ModernWebDevBuild.
We found that angular-build demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers 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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.