From 5ef1848db239058017bf5930699dd9bf84eead8e Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Wed, 15 Mar 2017 03:57:59 +0100 Subject: [PATCH] Activate Angular production mode on master branch. --- .gitlab-ci.yml | 18 ++++++++++++- config/webpack.prod.js | 61 +++++++++++++++++++++--------------------- package.json | 3 ++- src/main.ts | 5 ++++ 4 files changed, 55 insertions(+), 32 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6536522..555ade9 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -8,12 +8,28 @@ build_job: stage: build script: - npm install - - npm run build + - npm run build-dev - npm run test tags: - javascript except: - tags + - master + artifacts: + paths: + - dist + expire_in: 30 min + +build_job_production: + stage: build + script: + - npm install + - npm run build + - npm run test + tags: + - javascript + only: + - master artifacts: paths: - dist diff --git a/config/webpack.prod.js b/config/webpack.prod.js index a5fb526..9569ac3 100644 --- a/config/webpack.prod.js +++ b/config/webpack.prod.js @@ -4,35 +4,36 @@ var ExtractTextPlugin = require('extract-text-webpack-plugin'); var commonConfig = require('./webpack.common.js'); var helpers = require('./helpers'); -const ENV = process.env.NODE_ENV = process.env.ENV = 'production'; +module.exports = function (env) { + console.log("env:", env); + return webpackMerge(commonConfig, { + devtool: 'source-map', -module.exports = webpackMerge(commonConfig, { - devtool: 'source-map', + output: { + path: helpers.root('dist'), + publicPath: '', + filename: '[name].[hash].js', + chunkFilename: '[id].[hash].chunk.js' + }, - output: { - path: helpers.root('dist'), - publicPath: '', - filename: '[name].[hash].js', - chunkFilename: '[id].[hash].chunk.js' - }, - - plugins: [ - new webpack.NoEmitOnErrorsPlugin(), - new webpack.optimize.UglifyJsPlugin({ // https://github.com/angular/angular/issues/10618 - mangle: { - keep_fnames: true - } - }), - new ExtractTextPlugin('[name].[hash].css'), - new webpack.DefinePlugin({ - 'process.env': { - 'ENV': JSON.stringify(ENV) - } - }), - new webpack.LoaderOptionsPlugin({ - htmlLoader: { - minimize: false // workaround for ng2 - } - }) - ] -}); + plugins: [ + new webpack.NoEmitOnErrorsPlugin(), + new webpack.optimize.UglifyJsPlugin({ // https://github.com/angular/angular/issues/10618 + mangle: { + keep_fnames: true + } + }), + new ExtractTextPlugin('[name].[hash].css'), + new webpack.DefinePlugin({ + 'process.env': { + 'NODE_ENV': JSON.stringify(env.NODE_ENV) + } + }), + new webpack.LoaderOptionsPlugin({ + htmlLoader: { + minimize: false // workaround for ng2 + } + }) + ] + }); +}; diff --git a/package.json b/package.json index b87e1f1..d1b4d13 100644 --- a/package.json +++ b/package.json @@ -66,6 +66,7 @@ "scripts": { "start": "webpack-dev-server --inline --progress --port 8080", "test": "karma start", - "build": "rimraf dist && webpack --config config/webpack.prod.js --progress --profile --bail" + "build-dev": "rimraf dist && webpack --config config/webpack.prod.js --progress --profile --bail --env.NODE_ENV=development", + "build": "rimraf dist && webpack --config config/webpack.prod.js --progress --profile --bail --env.NODE_ENV=production" } } diff --git a/src/main.ts b/src/main.ts index 1a7052b..2a03f0b 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,4 +1,9 @@ import {platformBrowserDynamic} from "@angular/platform-browser-dynamic"; import {AppModule} from "./app/app.module"; +import {enableProdMode} from "@angular/core"; + +if (process.env.NODE_ENV === "production") { + enableProdMode(); +} platformBrowserDynamic().bootstrapModule(AppModule);