Activate Angular production mode on master branch.

This commit is contained in:
Manuel Friedli 2017-03-15 03:57:59 +01:00
parent 38ff12070e
commit 5ef1848db2
4 changed files with 55 additions and 32 deletions

View File

@ -8,12 +8,28 @@ build_job:
stage: build stage: build
script: script:
- npm install - npm install
- npm run build - npm run build-dev
- npm run test - npm run test
tags: tags:
- javascript - javascript
except: except:
- tags - 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: artifacts:
paths: paths:
- dist - dist

View File

@ -4,35 +4,36 @@ var ExtractTextPlugin = require('extract-text-webpack-plugin');
var commonConfig = require('./webpack.common.js'); var commonConfig = require('./webpack.common.js');
var helpers = require('./helpers'); 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, { output: {
devtool: 'source-map', path: helpers.root('dist'),
publicPath: '',
filename: '[name].[hash].js',
chunkFilename: '[id].[hash].chunk.js'
},
output: { plugins: [
path: helpers.root('dist'), new webpack.NoEmitOnErrorsPlugin(),
publicPath: '', new webpack.optimize.UglifyJsPlugin({ // https://github.com/angular/angular/issues/10618
filename: '[name].[hash].js', mangle: {
chunkFilename: '[id].[hash].chunk.js' keep_fnames: true
}, }
}),
plugins: [ new ExtractTextPlugin('[name].[hash].css'),
new webpack.NoEmitOnErrorsPlugin(), new webpack.DefinePlugin({
new webpack.optimize.UglifyJsPlugin({ // https://github.com/angular/angular/issues/10618 'process.env': {
mangle: { 'NODE_ENV': JSON.stringify(env.NODE_ENV)
keep_fnames: true }
} }),
}), new webpack.LoaderOptionsPlugin({
new ExtractTextPlugin('[name].[hash].css'), htmlLoader: {
new webpack.DefinePlugin({ minimize: false // workaround for ng2
'process.env': { }
'ENV': JSON.stringify(ENV) })
} ]
}), });
new webpack.LoaderOptionsPlugin({ };
htmlLoader: {
minimize: false // workaround for ng2
}
})
]
});

View File

@ -66,6 +66,7 @@
"scripts": { "scripts": {
"start": "webpack-dev-server --inline --progress --port 8080", "start": "webpack-dev-server --inline --progress --port 8080",
"test": "karma start", "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"
} }
} }

View File

@ -1,4 +1,9 @@
import {platformBrowserDynamic} from "@angular/platform-browser-dynamic"; import {platformBrowserDynamic} from "@angular/platform-browser-dynamic";
import {AppModule} from "./app/app.module"; import {AppModule} from "./app/app.module";
import {enableProdMode} from "@angular/core";
if (process.env.NODE_ENV === "production") {
enableProdMode();
}
platformBrowserDynamic().bootstrapModule(AppModule); platformBrowserDynamic().bootstrapModule(AppModule);