Skip to content

Instantly share code, notes, and snippets.

@mirkonasato
Created October 24, 2016 12:06
Show Gist options
  • Save mirkonasato/9d30279274fbaf20e7e5f9cfa2c10b33 to your computer and use it in GitHub Desktop.
Save mirkonasato/9d30279274fbaf20e7e5f9cfa2c10b33 to your computer and use it in GitHub Desktop.
diff --git a/package.json b/package.json
index 7f9f117..293b4eb 100644
--- a/package.json
+++ b/package.json
@@ -15,25 +15,29 @@
"dependencies": {
"@angular/common": "2.1.1",
"@angular/compiler": "2.1.1",
+ "@angular/compiler-cli": "2.1.1",
"@angular/core": "2.1.1",
"@angular/forms": "2.1.1",
"@angular/http": "2.1.1",
"@angular/platform-browser": "2.1.1",
"@angular/platform-browser-dynamic": "2.1.1",
+ "@angular/platform-server": "2.1.1",
"@angular/router": "3.1.1",
"core-js": "2.4.1",
"rxjs": "5.0.0-beta.12",
"zone.js": "0.6.26"
},
"devDependencies": {
+ "@ngtools/webpack": "1.1.2",
"angular2-template-loader": "0.5.0",
"cross-env": "3.1.3",
"html-webpack-plugin": "2.24.0",
"raw-loader": "0.5.1",
+ "rimraf": "2.5.4",
"ts-loader": "0.9.5",
"typescript": "2.0.3",
"typings": "1.4.0",
- "webpack": "1.13.2",
- "webpack-dev-server": "1.16.2"
+ "webpack": "2.1.0-beta.25",
+ "webpack-dev-server": "2.1.0-beta.9"
}
}
diff --git a/tsconfig.json b/tsconfig.json
index d754c43..38ebbfd 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -1,8 +1,14 @@
{
"compilerOptions": {
"target": "es5",
+ "module": "es2015",
+ "moduleResolution": "node",
"experimentalDecorators": true,
- "emitDecoratorMetadata": true
+ "emitDecoratorMetadata": true,
+ "sourceMap": true
},
- "compileOnSave": false
+ "compileOnSave": false,
+ "angularCompilerOptions": {
+ "skipMetadataEmit": true
+ }
}
diff --git a/webpack.config.js b/webpack.config.js
index c6d770e..045b5ac 100644
--- a/webpack.config.js
+++ b/webpack.config.js
@@ -1,7 +1,11 @@
var webpack = require('webpack');
+var ngToolsWebpack = require('@ngtools/webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
-module.exports = {
+var appEnvironment = process.env.APP_ENVIRONMENT || 'development';
+var isProduction = appEnvironment === 'production';
+
+var webpackConfig = {
entry: {
'app': './src/main.ts',
@@ -12,21 +16,25 @@ module.exports = {
]
},
output: {
- path: './dist',
+ path: __dirname + '/dist',
filename: '[name].[hash].js'
},
module: {
loaders: [
- {test: /\.component.ts$/, loader: 'ts!angular2-template'},
- {test: /\.ts$/, exclude: /\.component.ts$/, loader: 'ts'},
- {test: /\.html$/, loader: 'raw'},
- {test: /\.css$/, loader: 'raw'}
+ { test: /\.ts$/, loader: isProduction ? '@ngtools/webpack' : 'ts!angular2-template' },
+ { test: /\.html$/, loader: 'raw' },
+ { test: /\.css$/, loader: 'raw' }
]
},
resolve: {
- extensions: ['', '.js', '.ts', '.html', '.css']
+ extensions: [ '.js', '.ts', '.html', '.css' ]
},
plugins: [
+ // see https://github.com/angular/angular/issues/11580
+ new webpack.ContextReplacementPlugin(
+ /angular(\\|\/)core(\\|\/)(esm(\\|\/)src|src)(\\|\/)linker/,
+ './src'
+ ),
new webpack.optimize.CommonsChunkPlugin({
name: 'polyfills'
}),
@@ -35,9 +43,18 @@ module.exports = {
}),
new webpack.DefinePlugin({
app: {
- environment: JSON.stringify(process.env.APP_ENVIRONMENT || 'development')
+ environment: JSON.stringify(appEnvironment)
}
})
]
};
+
+if (isProduction) {
+ webpackConfig.plugins.push(new ngToolsWebpack.AotPlugin({
+ tsConfigPath: './tsconfig.json',
+ entryModule: './src/app/app.module#AppModule'
+ }));
+}
+
+module.exports = webpackConfig;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment