Skip to content
This repository has been archived by the owner on Mar 5, 2020. It is now read-only.

Commit

Permalink
minify js/css when NODE_ENV is production. fixes #140.
Browse files Browse the repository at this point in the history
  • Loading branch information
toolness committed Mar 26, 2015
1 parent e6c5ad9 commit 71ee7e4
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ string), the boolean is true; otherwise, it's false.
Name | Description
------------------|---------------------------------------------
`NODE_ENV` | set this to `production` to automatically minify code and remove various development-only affordances.
`WEBPACK_DEVTOOL` | determines the setting for the [`devtool`][] Webpack option. It defaults to `source-map`; if you're on Firefox, though, you may want to set it to `eval` so that console logging statements originate from useful line numbers. For re details on the trade-offs between different options for development, see our [conversation on sourcemaps][sourcemaps-wtf].
`WEBPACK_DEVTOOL` | determines the setting for the [`devtool`][] Webpack option. In development, it defaults to `eval`, while in production it defaults to `source-map`. For more details on the trade-offs between different options, see our [conversation on sourcemaps][sourcemaps-wtf].
`LESS_AUTOPREFIXER` | set this to `off` to disable the LESS autoprefixer and enable useful CSS source maps, which is a workaround for [#413][].
`AWS_ACCESS_KEY` | is the Amazon Web Services access key used when uploading to s3 via `npm run s3`.
`AWS_SECRET_KEY` | is the Amazon Web Services secret key used when uploading to s3 via `npm run s3`.
Expand Down
2 changes: 2 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var gutil = require('gulp-util');
var s3 = require('gulp-s3');
var gzip = require('gulp-gzip');
var less = require('gulp-less');
var cssmin = require('gulp-minify-css');
var prettify = require('gulp-prettify');
var webpack = require('gulp-webpack');
var plumber = require('gulp-plumber');
Expand Down Expand Up @@ -107,6 +108,7 @@ gulp.task('less', function() {
cascade: false,
remove: true
})))
.pipe(gulpif(process.env.NODE_ENV === 'production', cssmin()))
.pipe(rename('styles.css'))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./dist'));
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"gulp-jscs": "^1.4.0",
"gulp-jshint": "^1.9.2",
"gulp-less": "^3.0.1",
"gulp-minify-css": "^1.0.0",
"gulp-plumber": "^0.6.6",
"gulp-prettify": "^0.3.0",
"gulp-rename": "^1.2.0",
Expand Down
35 changes: 24 additions & 11 deletions test/browser/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,27 @@ console.warn = function(msg) {
}
};

require('./config.test.js');
require('./page.test.jsx');
require('./sidebar.test.jsx');
require('./imagetag.test.jsx');
require('./teach-api.test.js');
require('./teach-api-client.test.jsx');
require('./login.test.jsx');
require('./modal.test.jsx');
require('./modal-manager.test.js');
require('./clubs-page.test.jsx');
require('./map.test.jsx');
if (process.env.NODE_ENV === 'production') {
describe("automated test suite", function() {
it("does not run when NODE_ENV is 'production'", function() {
console.log(
"React's TestUtils aren't available when NODE_ENV is set " +
"to production, so there's not really any point in running " +
"the tests. For more information, see:\n\n" +
"https://facebook.github.io/react/downloads.html#npm"
);
});
});
} else {
require('./config.test.js');
require('./page.test.jsx');
require('./sidebar.test.jsx');
require('./imagetag.test.jsx');
require('./teach-api.test.js');
require('./teach-api-client.test.jsx');
require('./login.test.jsx');
require('./modal.test.jsx');
require('./modal-manager.test.js');
require('./clubs-page.test.jsx');
require('./map.test.jsx');
}
17 changes: 15 additions & 2 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var webpack = require('webpack');

var production = process.env.NODE_ENV === 'production';
var IMPORT_ES5_SHIM = 'imports?shim=es5-shim/es5-shim&' +
'sham=es5-shim/es5-sham';

Expand All @@ -21,7 +22,9 @@ module.exports = {
manualTests: './test/browser/manual-main.jsx',
tests: './test/browser/main.js'
},
devtool: process.env.WEBPACK_DEVTOOL || 'source-map',
devtool: production
? process.env.WEBPACK_DEVTOOL || 'source-map'
: process.env.WEBPACK_DEVTOOL || 'eval',
output: {
path: __dirname + '/dist',
filename: '[name].bundle.js'
Expand All @@ -45,5 +48,15 @@ module.exports = {
])),
new webpack.optimize.CommonsChunkPlugin('commons',
'commons.bundle.js')
]
].concat(
production
? [
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
}
})
]
: []
)
};

0 comments on commit 71ee7e4

Please sign in to comment.