NG6 uses NPM scripts, Gulp, and Webpack together for its build system. Yes, you don't need Gulp if you're using Webpack. This is true if your build system is only responsible for file manipulation. However, ours is not.
Webpack
handles all file-related concerns:
- Transpiling from ES6 to ES5 with
Babel
- Loading HTML files as modules
- Transpiling stylesheets and appending them to the DOM
- Refreshing the browser and rebuilding on file changes
- Hot module replacement for transpiled stylesheets
- Bundling the app
- Loading all modules
Gulp
is the orchestrator:
- Starting and calling Webpack
- Starting a development server (yes, Webpack can do this too)
- Generating boilerplate for the Angular app
We use a componentized approach with NG6. This will be the eventual standard (and particularly helpful, if using Angular's new router) as well as a great way to ensure a tasteful transition to Angular 2, when the time is ripe. Everything--or mostly everything, as we'll explore (below)--is a component. A component is a self-contained concern--may it be a feature or strictly-defined, ever-present element of the UI (such as a header, sidebar, or footer). Also characteristic of a component is that it harnesses its own stylesheets, templates, controllers, routes, services, and specs. This encapsulation allows us the comfort of isolation and structural locality. Here's how it looks:
client
⋅⋅app/
⋅⋅⋅⋅app.js * app entry file
⋅⋅⋅⋅app.html * app template
⋅⋅⋅⋅common/ * functionality pertinent to several components propagate into this directory
⋅⋅⋅⋅components/ * where components live
⋅⋅⋅⋅⋅⋅components.js * components entry file
⋅⋅⋅⋅⋅⋅home/ * home component
⋅⋅⋅⋅⋅⋅⋅⋅home.js * home entry file (routes, configurations, and declarations occur here)
⋅⋅⋅⋅⋅⋅⋅⋅home.component.js * home "directive"
⋅⋅⋅⋅⋅⋅⋅⋅home.controller.js * home controller
⋅⋅⋅⋅⋅⋅⋅⋅home.scss * home styles
⋅⋅⋅⋅⋅⋅⋅⋅home.html * home template
⋅⋅⋅⋅⋅⋅⋅⋅home.spec.js * home specs (for entry, component, and controller)
Tools needed to run this app:
node
andnpm
fork
this repoclone
your forknpm install
to install dependencies
NG6 uses Gulp to build and launch the development environment. After you have installed all dependencies, you may run the app. Running npm start
will bundle the app with webpack
, launch a development server, and watch all files. The port will be displayed in the terminal.
Here's a list of available tasks:
npm run build
- runs Webpack, which will transpile, concatenate, and compress (collectively, "bundle") all assets and modules into
dist/bundle.js
. It also preparesindex.html
to be used as application entry point, links assets and created dist version of our application.
- runs Webpack, which will transpile, concatenate, and compress (collectively, "bundle") all assets and modules into
npm run serve
- starts a dev server via
webpack-dev-server
, serving the client folder.
- starts a dev server via
npm run watch
- alias of
serve
- alias of
npm start
(which is the default task that runs when typinggulp
without providing an argument)- runs
serve
.
- runs