Skip to content

Commit

Permalink
chore(build): add build script and webpack config (#14)
Browse files Browse the repository at this point in the history
Closes #2
  • Loading branch information
elmariofredo authored and Hotell committed Aug 5, 2016
1 parent daad65f commit 85f6517
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 7 deletions.
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,10 @@ jspm_packages
.node_repl_history

# TS generated files
ts-output
ts-output

# Build files
dist

# Temporary files
tmp
8 changes: 7 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,10 @@ node_js:
install:
- npm install
script:
- npm run check-coverage
- npm run build
after_success:
- npm install deploy-to-gh-pages
- node_modules/.bin/deploy-to-gh-pages dist
env:
global:
secure: ZqPfmcWEqy0An6YjrmqBZ0hmiRIHHrK1q6qEc8jY556GCyqdDdC2vEM9Ad2H4OTNsJIccyOZK/ugJL6X5PdQ/xTnHavenQty8w81Efmx93MtI7vO1q/tYW0sul7s869lqHWxUoDoQn+Eo8wGY1Ez4wswEvvI/fL0HPqhrRADBtjGPK13eBUenygezg8OcLGG+yHkbWkt3Pl+spRJaxHhN9KlVdf6MBBoBcV/3cTyDjl7HATe9KsyXzkvJO8IgAXJSLekKFhGGR1CQR/qK6V2J6hUXZMyoXl+JOcqg6gBkxFBvzmuDaX+XNyP0LVcvnxAHbNZZegm5XDXqdVpI9oRzO6YqEh5tPC2GByR5w7ZvdydmuCeC7kG97DM3V9EQ5jTgqTIK+mMGklM8fE7Sn9WlqQyX2oJ4yGl0mYIx+eCd3vKeduL8u4HhlYiQdY4jFRyhooykgw6LkaUx5BppSE3qwl1jNn8vhNk6kFJ9HsWD6lOTBkCVF1q6jsMBO0jhy/pARMeCx2qbxRMMkjy49YjL9MEex9qPTIbmL+Dlmyf1fSmjYwYZ0D4eW+J45pPBvBhvwy2mCxgsXcSYlUEfa87XQqnM1/udKpaJ/0/jblr5dYUgJBao4s8s/9nmGKmWX8zlPJcRIQylCHkrK6klyUntEu1si7yCJ3ii+BoDC8U0Vs=
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"cover:watch": "nodemon --quiet --watch src --ext ts,tsx --exec npm run cover",
"check-coverage": "nyc --check-coverage --statements 80 --branches 80 --functions 80 --lines 80 npm test",
"lint": "tslint \"src/**/*.tsx\" \"src/**/*.ts\"",
"start": "webpack-dev-server --env.dev --hot"
"start": "webpack-dev-server --env.dev --hot",
"build": "npm run check-coverage && rimraf dist && webpack --env.prod"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -58,7 +59,9 @@
"jsdom": "9.4.1",
"nodemon": "1.10.0",
"nyc": "7.1.0",
"progress-bar-webpack-plugin": "1.9.0",
"react-addons-test-utils": "15.3.0",
"rimraf": "2.5.4",
"sinon": "1.17.5",
"tslint": "3.14.0",
"tslint-react": "0.4.0",
Expand Down
38 changes: 34 additions & 4 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const {resolve} = require('path')
const webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const {getIfUtils, removeEmpty} = require('webpack-config-utils')
const ProgressBarPlugin = require('progress-bar-webpack-plugin')

module.exports = env => {
const {ifProd, ifNotProd} = getIfUtils(env)
Expand All @@ -14,7 +15,7 @@ module.exports = env => {
filename: '[name].[hash].js',
path: resolve('dist'),
// Include comments with information about the modules.
pathinfo: ifNotProd(),
pathinfo: ifNotProd(),
},

resolve: {
Expand All @@ -23,7 +24,7 @@ module.exports = env => {
'.js',
'.ts',
'.tsx'
]
]
},

devtool: ifProd('source-map', 'cheap-module-source-map'),
Expand All @@ -34,15 +35,26 @@ module.exports = env => {
{test: /\.css$/, loaders: ['style', 'css']},
],
},

// This is required, when using Hot Code Replacement between multiple calls to the compiler.
recordsPath: resolve(__dirname, './webpack-records.json'),
recordsPath: resolve(__dirname, './tmp/webpack-records.json'),

plugins: removeEmpty([

// Add nice progress bar
new ProgressBarPlugin(),

new HtmlWebpackPlugin({
template: resolve('src','index.html')
}),

// Set NODE_ENV to enable production react version
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: ifProd('"production"', '"development"')
}
}),

ifProd(new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
})),
Expand All @@ -52,6 +64,24 @@ module.exports = env => {
name: 'inline',
})),

// Deduplicate node modules dependencies
ifProd(new webpack.optimize.DedupePlugin()),

// Default webpack build options
ifProd(new webpack.LoaderOptionsPlugin({
debug: false
})),

// Uglify bundles
ifProd(new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false,
},
output: {
comments: false
}
}))

]),
}
}
}

0 comments on commit 85f6517

Please sign in to comment.