Coder Social home page Coder Social logo

angular2-universal-starter's Introduction

Angular2 Universal Starter Kit

Build Status Dependency Status devDependency Status Issue Stats Issue Stats Join the chat at https://gitter.im/alexpods/angular2-universal-starter

#What we've got here

  • Server Side rendering for instant page loading
  • Entire Angular2 application is running in a Web Worker (UI always will be smooth)
  • Preboot to catch browser events before Angular2 is ready to work (you can experiment with its options here)
  • Webpack and its awesome Code Splitting feature which allows us to lazy load parts of an application.
  • Live Reloading, a browser will be reloaded on any change in server or browser code. It works well for both a main thread and web workers.
  • Typescript with Typings
  • PostCSS with CSSNext
  • Linting with TSLint
  • Express - de facto standard for Node.js web apps.
  • PM2 - most advanced Node.js process manager
  • Unit testing with Karma
  • End-to-End testing with Protractor

##Requirements

  • node >= 4.2.0
  • npm >= 3.0.0

#Quick start

# clone the repo without git history
git clone --depth 1 https://github.com/alexpods/angular2-universal-starter.git

# change current directory to angular2-universal-starter
cd angular2-universal-starter

# install dependencies
npm install

# run the production server
npm start

Go to http://localhost:3000 in your browser.

You may want to stop or restart the production server:

# stop the production server
npm stop

# restart the production server
npm restart

Development with Live Reloading

# make sure that the production server is not running
npm stop

# run the development server with live reloading support
npm run dev

The development server will watch for any changes, make rebuilds and reload a browser. All built code will be kept in memory, so dist folder will not be generated (all means code for both client and server sides).

##Turning server side rendering and web workers on/off You can optionally turn server side rendering or web workers suport on/off. You just need to change HAS_SS and HAS_WW in constants.js here:

// ...

// Server side rendering. Set it to `false` to turn it of.
exports.HAS_SS = 'NG2_SS' in process.env ? process.env.NG2_SS === 'true' : true;
// For example:
// exports.HAS_SS = false;

// Web workers support. Set it to `false` to turn it of.
exports.HAS_WW = 'NG2_WW' in process.env ? process.env.NG2_WW === 'true' : true;
// For example:
// exports.HAS_WW = 'NG2_WW' in process.env ? process.env.NG2_WW === 'true' : false;

//...

Then you need to restart the server to apply the changes:

# for production server
npm restart

# for development server - stop its process and run it again
npm run dev

#Building

# build the project
npm run build

# build the project and start watching for its changes
npm run build:watch

#Linting

# check the project (source files)
npm run lint

# check the project and start watching for its changes
npm run lint:watch

If you're not agree with the default rules (tslint.json), feel free to tell me about it.

#Testing The next command will run both unit and end-to-end tests.

For end-to-end tests you need to start Selenium Server first (see End-to-End Testing).

# run all tests (single run)
npm test

##Unit Testing

# run unit tests (single run)
npm run unit

# run unit tests and start watch for changes
npm run unit:watch

# run unit tests for specified directory (path must be relative to root directory)
# currently you can specify paths only for "src" directory
npm run unit src/app

# run unit tests for specified file and start watch for changes
npm run unit:watch src/app/home.spec.ts

##End-to-End Testing For end-to-end tests you nedd to start Selenium Server (webdriver) first.

# start Selenium Server (webdriver)
npm run webdriver:start

# run end-to-end test (single run)
npm run e2e

#Cleaning

# remove "dist" and "logs" folders
npm run clean

# remove "dist" folder
npm run clean:dist

# remove "logs" folder
npm run clean:logs

#License The MIT License (MIT)

Copyright (c) 2016 Aleksey Podskrebyshev

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

angular2-universal-starter's People

Contributors

bjwyse avatar bkinsey808 avatar gitter-badger avatar vaseker avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

angular2-universal-starter's Issues

live reload is slow

Seems like bundling is slow and unnecessary in dev mode. Any way to bypass webpack bunding in the dev mode, and just serve the files unbundled?

Static pre-render documentation?

I need to pre-render certain routes for SEO purposes and host my universal app in a static host (no node.js server will be running). I have been looking all over and can't find any info that can point me in the right direction.

How can this be achieved?

Thanks

pm2 errors

Hi, I can run this directly and it works great with

node dist/private/app.js

but when i try to run it with

npm start

The app doesn't start, and the error log fills up with errors:

Error: Cannot find module '/home/bkinsey/opt/alexpods/angular2-universal-starter/dist/private/app.js'
    at Function.Module._resolveFilename (module.js:337:15)
    at Function.Module._load (module.js:287:25)
    at Function._load (/home/bkinsey/opt/alexpods/angular2-universal-starter/node_modules/pmx/lib/transaction.js:62:21)
    at Object.<anonymous> (/home/bkinsey/opt/alexpods/angular2-universal-starter/node_modules/pm2/lib/ProcessContainerFork.js:28:21)
    at Module._compile (module.js:425:26)
    at Object.Module._extensions..js (module.js:432:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:311:12)
    at Function.Module.runMain (module.js:457:10)
    at startup (node.js:136:18)
Error: Cannot find module '/home/bkinsey/opt/alexpods/angular2-universal-starter/dist/private/app.js'
    at Function.Module._resolveFilename (module.js:337:15)
    at Function.Module._load (module.js:287:25)
    at Function._load (/home/bkinsey/opt/alexpods/angular2-universal-starter/node_modules/pmx/lib/transaction.js:62:21)

[...]

Serverside rendering is not working?

In constant.js both values are already set to true and therefore server side rendering should work.
However if I disable JS nothing gets rendered, and if I enable JS the screen is blank until the browser has finished loading the JS. Both behaviour suggest that server-side is not working.
I did npm install, npm run buildand then npm start however this is my error.log:

2016-05-11 21:59 +01:00: DEPRECATION WARNING: `renderToStringWithPreboot` is no longer supported and will be removed in next release.
2016-05-11 21:59 +01:00: DEPRECATION WARNING: `renderToString` is no longer supported and will be removed in next release.
2016-05-11 22:00 +01:00: DEPRECATION WARNING: `renderToStringWithPreboot` is no longer supported and will be removed in next release.
DEPRECATION WARNING: `renderToString` is no longer supported and will be removed in next release.
2016-05-11 22:00 +01:00: DEPRECATION WARNING: `renderToStringWithPreboot` is no longer supported and will be removed in next release.
2016-05-11 22:00 +01:00: DEPRECATION WARNING: `renderToString` is no longer supported and will be removed in next release.
2016-05-11 22:00 +01:00: DEPRECATION WARNING: `renderToStringWithPreboot` is no longer supported and will be removed in next release.
2016-05-11 22:00 +01:00: DEPRECATION WARNING: `renderToString` is no longer supported and will be removed in next release.
2016-05-11 22:00 +01:00: DEPRECATION WARNING: `renderToStringWithPreboot` is no longer supported and will be removed in next release.
2016-05-11 22:00 +01:00: DEPRECATION WARNING: `renderToString` is no longer supported and will be removed in next release.
2016-05-11 22:00 +01:00: DEPRECATION WARNING: `renderToStringWithPreboot` is no longer supported and will be removed in next release.
2016-05-11 22:00 +01:00: DEPRECATION WARNING: `renderToString` is no longer supported and will be removed in next release.

This is npm run-script status:
Describing process with id 0 - name angular2-universal-starter
┌───────────────────┬──────────────────────────────────────────────────────────────────────┐
│ status │ online │
│ name │ angular2-universal-starter │
│ restarts │ 0 │
│ uptime │ 37s │
│ script path │ /Users/[.......] /tools/prod.js │
│ script args │ N/A │
│ error log path │ /Users/[.......] /logs/errors-0.log │
│ out log path │ /Users/[.......] /logs/output-0.log │
│ pid path │ /Users/[.......] /.pm2/pids/angular2-universal-starter-0.pid │
│ interpreter │ node │
│ interpreter args │ N/A │
│ script id │ 0 │
│ exec cwd │ /Users/[.......] │
│ exec mode │ fork_mode │
│ node.js version │ 5.10.1 │
│ watch & reload │ ✔ │
│ unstable restarts │ 0 │
│ created at │ 2016-05-11T20:59:27.106Z │
└───────────────────┴──────────────────────────────────────────────────────────────────────┘
Revision control metadata
┌──────────────────┬────────────────────────────────────────────────────────┐
│ revision control │ git │
│ remote url │ https://github.com/alexpods/angular2-universal-starter
│ repository root │ /Users/[.......] │
│ last update │ 2016-05-11T20:59:57.000Z │
│ revision │ 813a512
│ comment │ Changed google chrome url │
│ branch │ master │
└──────────────────┴────────────────────────────────────────────────────────┘
Code metrics value
┌────────────┬────────┐
│ Loop delay │ 1.01ms │
└────────────┴────────┘
Add your own code metrics: http://bit.ly/code-metrics
Use pm2 logs angular2-universal-starter (--lines 1000) to display logs
Use pm2 monit to monitor CPU and Memory usage angular2-universal-starter

Unable to start

Run into this issue on trying out the repo

npm run dev

[email protected] dev C:\Users\PhucTran\test-ng2\angular2-universal-starter
node tools/dev.js

events.js:141
throw er; // Unhandled 'error' event
^

Error: listen EADDRINUSE 127.0.0.1:3000
at Object.exports._errnoException (util.js:870:11)
at exports._exceptionWithHostPort (util.js:893:20)
at Server._listen2 (net.js:1234:14)
at listen (net.js:1270:10)
at net.js:1379:9
at GetAddrInfoReqWrap.asyncCallback as callback
at GetAddrInfoReqWrap.onlookup as oncomplete

npm ERR! Windows_NT 6.3.9600
npm ERR! argv "C:\Program Files\nodejs\node.exe" "C:\Users\PhucTran\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js" "run" "dev"
npm ERR! node v4.4.3
npm ERR! npm v3.10.7
npm ERR! code ELIFECYCLE
npm ERR! [email protected] dev: node tools/dev.js
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] dev script 'node tools/dev.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the angular2-universal-starter package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node tools/dev.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs angular2-universal-starter
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls angular2-universal-starter
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR! C:\Users\PhucTran\test-ng2\angular2-universal-starter\npm-debug.log

Route from form submit error in webworker-mode

Hello.
I have an error when submitting form using Enter key and trying to route using form input, but if event happens from input[type="submit"].click(), its okay.
In some cases submit event doesn't fire at all.
And form submits works fine in not-worker mode.

Error is

TypeError: null is not an object (evaluating 'element.events')

Code sample:

import { Component } from 'angular2/core';
import { NgForm } from 'angular2/common';
import { Router } from 'angular2/router';

@Component({
    selector: 'test-form',
    directives: [NgForm],
    template: `<form (ngSubmit)="onSubmit()">
    <input [(ngModel)]="field" placeholder="Type here smth" />
    <input type="submit" value="go" />
</form>`
})

export class ListComponent {
    field: string = '';

    constructor(private _router: Router) {};

    onSubmit() {
        this._router.navigate( ['SomeRoute', { param: this.field }] );
    }
}

Question: Do you plan to keep this project up-to-date?

Hi there,

I saw that your project using angular2-beta.15 and that issue #60 has been closed without any comment, so I'm wondering: do you plan to keep the project up-to-date?

I also saw that you use typings 0.6, and there are some breaking changes in the last version 1.0.4 (e.g. no ambient anymore, replaced by global...).

Regards

Universal setTitle

Does it and it means that there is no Universal Title service yet?

This code crashes while building server bundle.

import { Title } from 'angular2/platform/browser';

./node_modules/angular2/src/facade/browser.js:4
var win = window;
^
ReferenceError: window is not defined

Caching...

Hello there!
I was trying to configure express to use cache, but with not success. As angular2-universal is renderized on server, I believe it is always processing, for instance, /Home before delivering it to the browser.

Is there any way to configure cache? I'm sure I can deliver the first page of my website to the browser in just few miliseconds.

ng2-highcharts issue

Hello!
Im trying to use highcharts via ng2-highcharts directives, but I stuck with error (npm run dev, NO_WW, NO_SS)

ERROR in ./~/ng2-highcharts/ng2-highcharts.ts
Module parse failed: ./node_modules/ng2-highcharts/ng2-highcharts.ts Line 1: Unexpected token
You may need an appropriate loader to handle this file type.
| import {Ng2Highcharts} from './src/directives/ng2-highcharts';
| export * from './src/directives/ng2-highcharts';
|

It works well in official ng2-highcharts sample.

So Im trying to use it like this:

import HighCharts from 'ng2-highcharts/ng2-highcharts';

@Component({
    directives: [HighCharts.directives],
    template: `<div [ng2-highstocks]="chartStock" class="graph"></div>`
})

What is wrong?

Thank you.

Dev watchers stops on error

Steps to reproduce

1). run npm run dev
2). make error in the source-code

What is happening

After running npm run dev and making the error in the source code the watchers stop.

Expected behaviour

Watchers continue to watch for errors and try to build the projects after every change.

Log:

  angular2-universal-starter  npm run dev

> [email protected] dev /Users/Julia/Work/angular2/angular2-universal-starter
> node tools/dev.js

ts-loader: Using [email protected] and /Users/Julia/Work/angular2/angular2-universal-starter/tsconfig.json
ts-loader: Using [email protected] and /Users/Julia/Work/angular2/angular2-universal-starter/tsconfig.json
ts-loader: Using [email protected] and /Users/Julia/Work/angular2/angular2-universal-starter/tsconfig.json
Hash: c1c43125aa3c80a4e4d508cc80c1ba06c0f19b105620da56d03235c52baa
Version: webpack 1.12.13
Child
    Hash: c1c43125aa3c80a4e4d5
    Version: webpack 1.12.13
    Time: 11822ms
        Asset    Size  Chunks             Chunk Names
    server.js  100 kB       0  [emitted]  server
       [0] multi server 28 bytes {0} [built]
        + 58 hidden modules
Child
    Hash: 08cc80c1ba06c0f19b10
    Version: webpack 1.12.13
    Time: 9949ms
        Asset     Size  Chunks             Chunk Names
    worker.js  1.69 MB       0  [emitted]  worker
       [0] multi worker 40 bytes {0} [built]
        + 188 hidden modules
Child
    Hash: 5620da56d03235c52baa
    Version: webpack 1.12.13
    Time: 12750ms
            Asset     Size  Chunks             Chunk Names
    worker_app.js  2.59 MB       0  [emitted]  worker_app
       [0] multi worker_app 28 bytes {0} [built]
        + 234 hidden modules
webpack: bundle is now VALID.
webpack: bundle is now INVALID.
undefined:1479
        return map[req] || (function() { throw new Error("Cannot find module '" + req + "'.") }());
                                         ^

Error: Cannot find module 'undefined'.
    at eval (eval at recompileApp (/Users/Julia/Work/angular2/angular2-universal-starter/tools/dev.js:62:3), <anonymous>:1479:42)
    at webpackContextResolve (eval at recompileApp (/Users/Julia/Work/angular2/angular2-universal-starter/tools/dev.js:62:3), <anonymous>:1479:90)
    at webpackContext (eval at recompileApp (/Users/Julia/Work/angular2/angular2-universal-starter/tools/dev.js:62:3), <anonymous>:1476:30)
    at Object.eval (eval at recompileApp (/Users/Julia/Work/angular2/angular2-universal-starter/tools/dev.js:62:3), <anonymous>:178:40)
    at __webpack_require__ (eval at recompileApp (/Users/Julia/Work/angular2/angular2-universal-starter/tools/dev.js:62:3), <anonymous>:23:30)
    at Object.eval (eval at recompileApp (/Users/Julia/Work/angular2/angular2-universal-starter/tools/dev.js:62:3), <anonymous>:104:14)
    at __webpack_require__ (eval at recompileApp (/Users/Julia/Work/angular2/angular2-universal-starter/tools/dev.js:62:3), <anonymous>:23:30)
    at Object.eval (eval at recompileApp (/Users/Julia/Work/angular2/angular2-universal-starter/tools/dev.js:62:3), <anonymous>:59:13)
    at __webpack_require__ (eval at recompileApp (/Users/Julia/Work/angular2/angular2-universal-starter/tools/dev.js:62:3), <anonymous>:23:30)
    at Object.eval (eval at recompileApp (/Users/Julia/Work/angular2/angular2-universal-starter/tools/dev.js:62:3), <anonymous>:50:19)

npm ERR! Darwin 14.5.0
npm ERR! argv "/usr/local/Cellar/node/5.4.1_1/bin/node" "/usr/local/bin/npm" "run" "dev"
npm ERR! node v5.4.1
npm ERR! npm  v3.5.3
npm ERR! code ELIFECYCLE
npm ERR! [email protected] dev: `node tools/dev.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] dev script 'node tools/dev.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the angular2-universal-starter package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node tools/dev.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs angular2-universal-starter
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls angular2-universal-starter
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/Julia/Work/angular2/angular2-universal-starter/npm-debug.log
➜  angular2-universal-starter

Auto restart and rebuild angular universal on save

I turned my application to angular universal. It's great but I have a problem with developing mode. I need to see my editing result real-time. I need to restart my app on each atrl+s (save) like build --watch and nodmeon.

My server is Eexpressjs and I'm using the command "npm run build:ssr" after each edit. It takes lots of time!!
How can I do that?

DLL error on npm start

I found a reason why i have added es6-shim, es6-promise and reflect-metadata into my previous PR to package.json file.

When i'm run npm start i've got the following DLL error:

ERROR in dll vendor
Module not found: Error: Cannot resolve module 'es6-shim'
Module not found: Error: Cannot resolve module 'es6-promise'
Module not found: Error: Cannot resolve module 'reflect-metadata'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.