Skip to content

Commit

Permalink
Split build on prod and dev
Browse files Browse the repository at this point in the history
  • Loading branch information
dyuvzhenko committed Nov 13, 2017
1 parent c9ea904 commit 41df64c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 4 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
},
"license": "MIT",
"scripts": {
"build": "webpack --config webpack/config.js",
"dev-build": "webpack --config webpack/config.js",
"dev-test": "karma start test/config/karma.conf.js",
"test": "concurrently --kill-others --raw \"npm run dev-build\" \"npm run dev-test\""
Expand Down
55 changes: 51 additions & 4 deletions webpack/config.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,61 @@
var path = require('path');
var webpack = require('webpack');

var packageJSON = require('../package.json');

var getBanner = function (compressed) {
return packageJSON.name + (compressed ? ' (compressed)' : ' (uncompressed)') + '\n' +
packageJSON.homepage + '\n' +
'Version: ' + packageJSON.version + ' -- ' + (new Date()).toISOString() + '\n' +
'License: ' + packageJSON.license;
};

var ENV = '';
switch (process.env.npm_lifecycle_event) {
case 'dev-build':
ENV = 'development';
break;
case 'build':
ENV = 'production';
break;
}

var _plugins = [];
var _output = {};

if (ENV === 'development') {
_plugins = [new webpack.BannerPlugin(getBanner(false))];
_output = {
path: path.join(__dirname, '../temp'),
filename: '[name].js'
};
}

if (ENV === 'production') {
_plugins = [
new webpack.BannerPlugin(getBanner(true)),
new webpack.optimize.UglifyJsPlugin({
sourceMap: true,
compress: {
warnings: true,
},
output: {
comments: false,
},
})
];
_output = {
path: path.join(__dirname, '../temp'),
filename: '[name].min.js'
};
}

module.exports = {
entry: {
'ui-scroll': path.resolve(__dirname, '../src/ui-scroll.js'),
'ui-scroll-grid': path.resolve(__dirname, '../src/ui-scroll-grid.js')
},
output: {
path: path.join(__dirname, '../temp'),
filename: '[name].js'
},
output: _output,
cache: false,
devtool: 'source-map',
module: {
Expand All @@ -19,6 +65,7 @@ module.exports = {
loader: 'babel-loader?presets[]=es2015'
}]
},
plugins: _plugins,
watch: true,
resolve: {
extensions: ['.js'],
Expand Down

0 comments on commit 41df64c

Please sign in to comment.