1
0
espelhamento de https://github.com/SonarSource/sonarqube.git sincronizado 2024-08-11 14:10:17 +02:00

improve web build scripts (fixes issue with NODE_ENV on windows)

Esse commit está contido em:
Stas Vilchik 2015-12-28 13:01:19 +01:00
commit d7ea0a8b14
3 arquivos alterados com 56 adições e 21 exclusões

Ver arquivo

@ -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')));
};

Ver arquivo

@ -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']);

Ver arquivo

@ -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"