Skip to content

Commit 3c22384

Browse files
committed
Merged chore/webpack2 into canary
2 parents 5e999b2 + 01e1054 commit 3c22384

File tree

11 files changed

+238
-220
lines changed

11 files changed

+238
-220
lines changed

templates/app/_package.json

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
},
5151
"devDependencies": {
5252
<%# CLIENT %>
53+
"@angularclass/hmr-loader": "^3.0.2",
5354
"@angularclass/match-control": "^2.0.0",
5455
"reflect-metadata": "^0.1.3",
5556
"rxjs": "5.0.0-beta.12",
@@ -62,8 +63,7 @@
6263
<%#"@angular/material": "^2.0.0-alpha.10",%>
6364
"@angular/platform-browser": "^2.3.0",
6465
"@angular/platform-browser-dynamic": "^2.3.0",
65-
<% if(filters.ngroute) { %>
66-
"@angular/router": "^3.3.0",<% } %>
66+
"@angular/router": "^3.4.7",
6767
"@angularclass/hmr": "^1.2.1",
6868
"angular2-universal": "2.1.0-rc.1",
6969
"angular2-jwt": "^0.1.24",
@@ -95,14 +95,14 @@
9595
"babel-core": "^6.6.5",
9696
"babel-eslint": "^6.0.4",
9797
"babel-register": "^6.16.0",
98-
"browser-sync": "^2.8.0",
9998
"bs-fullscreen-message": "^1.0.0",
10099
<%_ if(filters.flow) { -%>
101100
"flow-bin": "^0.31.0",
102101
"babel-plugin-syntax-flow": "^6.8.0",
103102
"babel-plugin-transform-flow-comments": "^6.8.0",<% } %>
104103
"babel-plugin-transform-class-properties": "^6.6.0",
105104
"babel-plugin-transform-runtime": "^6.6.0",
105+
"babel-plugin-istanbul": "^3.1.0",
106106
"babel-preset-es2015": "^6.6.0",
107107
"eslint": "^2.12.0",
108108
"del": "^2.0.2",
@@ -137,11 +137,10 @@
137137
"run-sequence": "^1.1.0",
138138
"lazypipe": "^1.0.1",
139139
<%# WEBPACK %>
140-
"webpack": "^1.12.14",
141-
"webpack-dev-middleware": "^1.5.1",
142-
"webpack-stream": "^3.2.0",
143-
"extract-text-webpack-plugin": "^1.0.1",
144-
"html-webpack-plugin": "^2.16.0",
140+
"webpack": "2.2.0",
141+
"webpack-dev-server": "^2.2.0",
142+
"extract-text-webpack-plugin": "2.0.0",
143+
"html-webpack-plugin": "^2.24.1",
145144
"html-webpack-harddisk-plugin": "~0.0.2",
146145
<%_ if(filters.pug) { _%>
147146
"pug-html-loader": "^1.0.8",<% } %>
@@ -167,7 +166,7 @@
167166
<%_ if(filters.stylus) { _%>
168167
"stylus": "^0.54.5",
169168
"stylus-loader": "^2.1.1",<% } %>
170-
"karma-webpack": "^1.7.0",
169+
"karma-webpack": "^1.8.1",
171170
<%# END WEBPACK %>
172171
"through2": "^2.0.1",
173172
"open": "~0.0.4",

templates/app/client/app/account(auth)/account.module.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { NgModule } from '@angular/core';
22
import { FormsModule } from '@angular/forms';
3+
import { BrowserModule } from '@angular/platform-browser';
34
<%_ if (filters.uirouter) { -%>
45
import { UIRouterModule } from 'ui-router-ng2';<% } %>
56
<%_ if (filters.ngroute) { -%><% } %>
@@ -15,6 +16,7 @@ import { SettingsComponent } from './settings/settings.component';
1516
@NgModule({
1617
imports: [
1718
FormsModule,
19+
BrowserModule,
1820
<%_ if (filters.uirouter) { -%>
1921
UIRouterModule.forChild({
2022
states: STATES,

templates/app/client/app/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import '!!style!css!sass!./app.<%= styleExt %>';
1+
import '!!style-loader!css-loader!sass-loader!./app.scss';
22

33
import './polyfills';
44

templates/app/client/app/app.module.js

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,26 @@
4444
// })<% } %>;
4545

4646

47-
import { NgModule, ErrorHandler, Injectable } from '@angular/core';
47+
import {
48+
NgModule,
49+
ErrorHandler,
50+
Injectable,
51+
ApplicationRef,
52+
} from '@angular/core';
4853
import { BrowserModule } from '@angular/platform-browser';
4954
import {
5055
HttpModule,
5156
BaseRequestOptions,
5257
RequestOptions,
5358
RequestOptionsArgs,
5459
} from '@angular/http';
60+
import {
61+
removeNgStyles,
62+
createNewHosts,
63+
disposeOldHosts,
64+
createInputTransfer,
65+
restoreInputValues,
66+
} from '@angularclass/hmr';
5567
<%_ if (filters.uirouter) { -%>
5668
import { UIRouterModule } from 'ui-router-ng2';<% } %>
5769
import { provideAuth } from 'angular2-jwt';
@@ -99,4 +111,45 @@ if(constants.env === 'development') {
99111
],
100112
bootstrap: [AppComponent]
101113
})
102-
export class AppModule {}
114+
export class AppModule {
115+
static parameters = [ApplicationRef];
116+
constructor(appRef/*: ApplicationRef*/) {
117+
this.appRef = appRef;
118+
}
119+
120+
hmrOnInit(store) {
121+
if (!store || !store.state) return;
122+
console.log('HMR store', store);
123+
console.log('store.state.data:', store.state.data)
124+
// inject AppStore here and update it
125+
// this.AppStore.update(store.state)
126+
if ('restoreInputValues' in store) {
127+
store.restoreInputValues();
128+
}
129+
// change detection
130+
this.appRef.tick();
131+
delete store.state;
132+
delete store.restoreInputValues;
133+
}
134+
135+
hmrOnDestroy(store) {
136+
var cmpLocation = this.appRef.components.map(cmp => cmp.location.nativeElement);
137+
// recreate elements
138+
store.disposeOldHosts = createNewHosts(cmpLocation)
139+
// inject your AppStore and grab state then set it on store
140+
// var appState = this.AppStore.get()
141+
store.state = {data: 'yolo'};
142+
// store.state = Object.assign({}, appState)
143+
// save input values
144+
store.restoreInputValues = createInputTransfer();
145+
// remove styles
146+
removeNgStyles();
147+
}
148+
149+
hmrAfterDestroy(store) {
150+
// display new elements
151+
store.disposeOldHosts()
152+
delete store.disposeOldHosts;
153+
// anything you need done the component is removed
154+
}
155+
}

templates/app/client/app/main/main.module.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { UIRouterModule } from 'ui-router-ng2';<% } %>
66
<%_ if(filters.ngroute) { %>
77
import { RouterModule, Routes } from '@angular/router';<% } %>
88
<%_ if(filters.uibootstrap) { %>
9-
import { TooltipModule } from 'ng2-bootstrap/ng2-bootstrap';<% } %>
9+
import { TooltipModule } from 'ng2-bootstrap';<% } %>
1010

1111
import { MainComponent } from './main.component';
1212
<%_ if(filters.socketio) { -%>
@@ -32,7 +32,7 @@ export const STATES = [
3232
states: STATES,
3333
}),<% } %>
3434
<%_ if(filters.uibootstrap) { %>
35-
TooltipModule,<% } %>
35+
TooltipModule.forRoot(),<% } %>
3636
],
3737
declarations: [
3838
MainComponent,

templates/app/client/components/directives.module.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { NgModule } from '@angular/core';
22
import { CommonModule } from '@angular/common';
33
import { UIRouterModule } from 'ui-router-ng2';
4-
import { CollapseModule } from 'ng2-bootstrap/ng2-bootstrap';
4+
import { CollapseModule } from 'ng2-bootstrap';
55

66
import { AuthModule } from './auth/auth.module';
77

templates/app/gulpfile.babel.js

Lines changed: 21 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {Server as KarmaServer} from 'karma';
1616
import runSequence from 'run-sequence';
1717
import {protractor, webdriver_update} from 'gulp-protractor';
1818
import {Instrumenter} from 'isparta';
19-
import webpack from 'webpack-stream';
19+
import webpack from 'webpack';
2020
import makeWebpackConfig from './webpack.make';
2121

2222
var plugins = gulpLoadPlugins();
@@ -223,37 +223,25 @@ gulp.task('inject:<%= styleExt %>', () => {
223223
.pipe(gulp.dest(`${clientPath}/app`));
224224
});
225225

226-
gulp.task('webpack:dev', function() {
227-
const webpackDevConfig = makeWebpackConfig({ DEV: true });
228-
return gulp.src(webpackDevConfig.entry.app)
229-
.pipe(plugins.plumber())
230-
.pipe(webpack(webpackDevConfig))
231-
.pipe(gulp.dest('.tmp'));
232-
});
226+
function webpackCompile(options, cb) {
227+
let compiler = webpack(makeWebpackConfig(options));
233228

234-
gulp.task('webpack:dist', function() {
235-
const webpackDistConfig = makeWebpackConfig({ BUILD: true });
236-
return gulp.src(webpackDistConfig.entry.app)
237-
.pipe(webpack(webpackDistConfig))
238-
.on('error', (err) => {
239-
this.emit('end'); // Recover from errors
240-
})
241-
.pipe(gulp.dest(`${paths.dist}/client`));
242-
});
229+
compiler.run((err, stats) => {
230+
if(err) return cb(err);
243231

244-
gulp.task('webpack:test', function() {
245-
const webpackTestConfig = makeWebpackConfig({ TEST: true });
246-
return gulp.src(webpackTestConfig.entry.app)
247-
.pipe(webpack(webpackTestConfig))
248-
.pipe(gulp.dest('.tmp'));
249-
});
232+
plugins.util.log(stats.toString({
233+
colors: true,
234+
timings: true,
235+
chunks: options.BUILD
236+
}));
237+
cb();
238+
});
239+
}
250240

251-
gulp.task('webpack:e2e', function() {
252-
const webpackE2eConfig = makeWebpackConfig({ E2E: true });
253-
return gulp.src(webpackE2eConfig.entry.app)
254-
.pipe(webpack(webpackE2eConfig))
255-
.pipe(gulp.dest('.tmp'));
256-
});<% if(filters.ts) { %>
241+
gulp.task('webpack:dev', cb => webpackCompile({ DEV: true }, cb));
242+
gulp.task('webpack:dist', cb => webpackCompile({ BUILD: true }, cb));
243+
gulp.task('webpack:test', cb => webpackCompile({ TEST: true }, cb));
244+
<%_ if(filters.ts) { -%>
257245

258246
// Install DefinitelyTyped TypeScript definition files
259247
gulp.task('typings', () => {
@@ -282,7 +270,7 @@ gulp.task('lint:scripts', cb => runSequence(['lint:scripts:client', 'lint:script
282270
gulp.task('lint:scripts:client', () => {
283271
return gulp.src(_.union(
284272
paths.client.scripts,
285-
_.map(paths.client.test, blob => '!' + blob)
273+
_.map(paths.client.test, blob => `!${blob}`)
286274
))
287275
.pipe(lintClientScripts());
288276
});
@@ -311,8 +299,8 @@ gulp.task('jscs', () => {
311299
gulp.task('clean:tmp', () => del(['.tmp/**/*'], {dot: true}));
312300

313301
gulp.task('start:client', cb => {
314-
whenServerReady(() => {
315-
open('http://localhost:' + config.browserSyncPort);
302+
return require('./webpack.server').start(config.clientPort).then(() => {
303+
open(`http://localhost:${config.clientPort}`);
316304
cb();
317305
});
318306
});
@@ -461,7 +449,7 @@ gulp.task('coverage:integration', () => {
461449
// Downloads the selenium webdriver
462450
gulp.task('webdriver_update', webdriver_update);
463451

464-
gulp.task('test:e2e', ['webpack:e2e', 'env:all', 'env:test', 'start:server', 'webdriver_update'], cb => {
452+
gulp.task('test:e2e', ['webpack:dist', 'env:all', 'env:test', 'start:server', 'webdriver_update'], cb => {
465453
gulp.src(paths.client.e2e)
466454
.pipe(protractor({
467455
configFile: 'protractor.conf.js',

templates/app/server/config/environment/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ var all = {
1919
// Root path of server
2020
root: path.normalize(`${__dirname}/../../..`),
2121

22-
// Browser-sync port
23-
browserSyncPort: process.env.BROWSER_SYNC_PORT || 3000,
22+
// dev client port
23+
clientPort: process.env.CLIENT_PORT || 3000,
2424

2525
// Server port
2626
port: process.env.PORT || <%= devPort %>,

templates/app/server/config/express.js

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -86,64 +86,6 @@ export default function(app) {
8686
}));
8787
}<% } %>
8888

89-
if(env === 'development') {
90-
const webpackDevMiddleware = require('webpack-dev-middleware');
91-
const stripAnsi = require('strip-ansi');
92-
const webpack = require('webpack');
93-
const makeWebpackConfig = require('../../webpack.make');
94-
const webpackConfig = makeWebpackConfig({ DEV: true });
95-
const compiler = webpack(webpackConfig);
96-
const browserSync = require('browser-sync').create();
97-
98-
app.use(cors({
99-
origin: true,
100-
credentials: true,
101-
}));
102-
103-
app.use(function(req, res, next) {
104-
res.setHeader('Access-Control-Allow-Origin', `http://localhost:${config.browserSyncPort}`);
105-
next();
106-
});
107-
108-
/**
109-
* Run Browsersync and use middleware for Hot Module Replacement
110-
*/
111-
browserSync.init({
112-
open: false,
113-
logFileChanges: false,
114-
proxy: `localhost:${config.port}`,
115-
ws: true,
116-
middleware: [
117-
webpackDevMiddleware(compiler, {
118-
noInfo: false,
119-
stats: {
120-
colors: true,
121-
timings: true,
122-
chunks: false
123-
}
124-
})
125-
],
126-
port: config.browserSyncPort,
127-
plugins: ['bs-fullscreen-message']
128-
});
129-
130-
/**
131-
* Reload all devices when bundle is complete
132-
* or send a fullscreen error message to the browser instead
133-
*/
134-
compiler.plugin('done', function(stats) {
135-
console.log('webpack done hook');
136-
if(stats.hasErrors() || stats.hasWarnings()) {
137-
return browserSync.sockets.emit('fullscreen:message', {
138-
title: "Webpack Error:",
139-
body: stripAnsi(stats.toString()),
140-
timeout: 100000
141-
});
142-
}
143-
browserSync.reload();
144-
});
145-
}
146-
14789
if(env === 'development' || env === 'test') {
14890
app.use(errorHandler()); // Error handler - has to be last
14991
}

0 commit comments

Comments
 (0)