aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStas Vilchik <vilchiks@gmail.com>2015-12-28 13:01:19 +0100
committerStas Vilchik <vilchiks@gmail.com>2015-12-28 13:01:19 +0100
commitd7ea0a8b14b8649144f7bfbff055f207d954d6c9 (patch)
tree239e0e3d4f385e4399a6c606050ba0f992b10124
parent593c11c6de3a82245d2ff5b8d9b79872fe607d6f (diff)
downloadsonarqube-d7ea0a8b14b8649144f7bfbff055f207d954d6c9.tar.gz
sonarqube-d7ea0a8b14b8649144f7bfbff055f207d954d6c9.zip
improve web build scripts (fixes issue with NODE_ENV on windows)5.4-M2
-rw-r--r--server/sonar-web/gulp/styles.js7
-rw-r--r--server/sonar-web/gulpfile.js64
-rw-r--r--server/sonar-web/package.json6
3 files changed, 56 insertions, 21 deletions
diff --git a/server/sonar-web/gulp/styles.js b/server/sonar-web/gulp/styles.js
index 26194a5f1c5..f97360b89db 100644
--- a/server/sonar-web/gulp/styles.js
+++ b/server/sonar-web/gulp/styles.js
@@ -5,12 +5,10 @@ var concat = require('gulp-concat');
var gulpif = require('gulp-if');
var less = require('gulp-less');
var nano = require('gulp-cssnano');
-var sourcemaps = require('gulp-sourcemaps');
var autoprefixer = require('gulp-autoprefixer');
-var plumber = require('gulp-plumber');
-module.exports.styles = function (output, production, dev) {
+module.exports.styles = function (output, production) {
return gulp.src([
'src/main/less/jquery-ui.less',
'src/main/less/select2.less',
@@ -24,8 +22,6 @@ module.exports.styles = function (output, production, dev) {
'src/main/less/*.less'
])
- .pipe(plumber())
- .pipe(gulpif(dev, sourcemaps.init()))
.pipe(less())
.pipe(autoprefixer({
browsers: [
@@ -38,6 +34,5 @@ module.exports.styles = function (output, production, dev) {
}))
.pipe(gulpif(production, nano()))
.pipe(concat('sonar.css'))
- .pipe(gulpif(dev, sourcemaps.write({ includeContent: true })))
.pipe(gulp.dest(path.join(output, 'css')));
};
diff --git a/server/sonar-web/gulpfile.js b/server/sonar-web/gulpfile.js
index 79e44933752..517f94c6fd6 100644
--- a/server/sonar-web/gulpfile.js
+++ b/server/sonar-web/gulpfile.js
@@ -1,20 +1,19 @@
var path = require('path');
var del = require('del');
-
var gulp = require('gulp');
var gutil = require('gulp-util');
+var webpack = require('webpack');
var argv = require('yargs').argv;
-var production = !argv.dev && !argv.fast;
-var dev = !!argv.dev && !argv.fast;
-var output = argv.output || './src/main/webapp';
+var output = argv.output || path.join(__dirname, 'src/main/webapp');
var styles = require('./gulp/styles').styles;
+var webpackConfig = require('./webpack.config.js');
+webpackConfig.output.path = path.join(output, 'js/bundles');
-gulp.task('styles', function () {
- return styles(output, production, dev);
-});
+
+// Clean
gulp.task('clean', function (done) {
del([
@@ -23,11 +22,54 @@ gulp.task('clean', function (done) {
], done);
});
-gulp.task('build', ['clean', 'styles']);
-gulp.task('watch', [], function () {
- gulp.watch('src/main/less/**/*.less', ['styles']);
- gutil.log(gutil.colors.bgGreen('Watching for changes...'));
+// Styles
+
+gulp.task('styles:prod', function () {
+ return styles(output, true);
});
+gulp.task('styles:dev', function () {
+ return styles(output, false, true);
+});
+
+
+// Webpack
+
+gulp.task('webpack:prod', function (callback) {
+ var webpackProdConfig = Object.create(webpackConfig);
+ webpackProdConfig.plugins = webpackProdConfig.plugins.concat(
+ new webpack.DefinePlugin({
+ 'process.env': {
+ 'NODE_ENV': JSON.stringify('production'),
+ 'OUTPUT': output
+ }
+ }),
+ new webpack.optimize.DedupePlugin(),
+ new webpack.optimize.UglifyJsPlugin()
+ );
+
+ webpack(webpackProdConfig, function (err) {
+ if (err) {
+ throw new gutil.PluginError('webpack:prod', err);
+ }
+ callback();
+ });
+});
+
+gulp.task('webpack:dev', function (callback) {
+ // run webpack
+ webpack(webpackConfig, function (err) {
+ if (err) {
+ throw new gutil.PluginError('webpack:dev', err);
+ }
+ callback();
+ });
+});
+
+
+// Tasks
+
+gulp.task('build', ['clean', 'styles:prod', 'webpack:prod']);
+gulp.task('build:dev', ['clean', 'styles:dev', 'webpack:dev']);
gulp.task('default', ['build']);
diff --git a/server/sonar-web/package.json b/server/sonar-web/package.json
index f534b133727..51ce13d71d5 100644
--- a/server/sonar-web/package.json
+++ b/server/sonar-web/package.json
@@ -36,9 +36,7 @@
"gulp-cssnano": "2.0.0",
"gulp-if": "2.0.0",
"gulp-less": "3.0.3",
- "gulp-plumber": "1.0.1",
"gulp-rename": "1.2.2",
- "gulp-sourcemaps": "1.6.0",
"gulp-util": "3.0.6",
"handlebars": "2.0.0",
"handlebars-loader": "1.1.4",
@@ -71,8 +69,8 @@
"yargs": "3.27.0"
},
"scripts": {
- "build-fast": "gulp --fast && webpack",
- "build": "NODE_ENV=PRODUCTION gulp && webpack -p",
+ "build-fast": "gulp build:dev",
+ "build": "gulp build",
"test": "mocha --opts tests/mocha.opts tests",
"coverage": "babel-node node_modules/.bin/isparta cover --root 'src/main/js' --include-all-sources --excludes '**/libs/**' --dir 'target/coverage' node_modules/.bin/_mocha -- --opts tests/mocha.opts tests",
"lint": "eslint src/main/js"