From 316950395f8def16e123da2cacae6e47261e88b0 Mon Sep 17 00:00:00 2001 From: Wikiki Date: Sat, 10 Feb 2018 20:25:18 +0100 Subject: [PATCH 1/2] feat(rollup): Integrate Rollup transpilation --- gulpfile.js | 61 +++++++++++++++++++++++++++++----------------------- package.json | 5 +++++ 2 files changed, 39 insertions(+), 27 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index b55404e..ffb99e7 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -5,6 +5,7 @@ var gulp = require('gulp'); var autoprefixer = require('autoprefixer'); var babel = require('gulp-babel'); var bump = require('gulp-bump'); +var camelCase = require('camelcase'); var cleancss = require('gulp-clean-css'); var concat = require('gulp-concat'); var conventionalChangelog = require('gulp-conventional-changelog'); @@ -14,10 +15,12 @@ var fs = require('fs'); var git = require('gulp-git'); var gutil = require('gulp-util'); var postcss = require('gulp-postcss'); +var rollup = require('gulp-better-rollup'); var runSequence = require('run-sequence'); var sass = require('gulp-sass'); +var sourcemaps = require('gulp-sourcemaps'); var spawn = require('child_process').spawn; -var uglify = require('gulp-uglify'); +var minify = require('gulp-babel-minify'); /** * ---------------------------------------- @@ -46,9 +49,10 @@ var distJsFile = package.name + '.min.js'; // Uses Sass compiler to process styles, adds vendor prefixes, minifies, then // outputs file to the appropriate location. -gulp.task('build:styles', ['build:styles:copy'], function() { +gulp.task('build:styles', function() { return gulp.src([paths.bulma + bulmaSassFile, paths.src + mainSassFile]) .pipe(concat(globalSassFile)) + .pipe(gulp.dest(paths.dest)) .pipe(sass({ style: 'compressed', includePaths: [paths.bulma] @@ -59,13 +63,6 @@ gulp.task('build:styles', ['build:styles:copy'], function() { .pipe(gulp.dest(paths.dest)); }); -// Copy original sass file to dist -gulp.task('build:styles:copy', function() { - return gulp.src(paths.src + mainSassFile) - .pipe(concat(globalSassFile)) - .pipe(gulp.dest(paths.dest)); -}); - gulp.task('clean:styles', function(callback) { del([ paths.dest + mainSassFile, @@ -82,28 +79,38 @@ gulp.task('clean:styles', function(callback) { // Concatenates and uglifies global JS files and outputs result to the // appropriate location. -gulp.task('build:scripts', ['build:scripts:copy'], function() { +gulp.task('build:scripts', function() { return gulp .src([paths.src + paths.jsPattern]) - .pipe(concat(distJsFile)) - .pipe(babel({ - "presets": [ - ["@babel/preset-env", { - "modules": "umd", - "targets": { - "browsers": ["last 2 versions"] - } - }] - ] + .pipe(sourcemaps.init({ + loadMaps: true })) - .pipe(uglify()) - .pipe(gulp.dest(paths.dest)); -}); - -// Copy original sripts file to dist -gulp.task('build:scripts:copy', function() { - return gulp.src(paths.src + mainJsFile) + .pipe(rollup({ + plugins: [babel({ + babelrc: false, + sourceMaps: true, + exclude: 'node_modules/**', + presets: [ + ["@babel/preset-env", { + "modules": false, + "targets": { + "browsers": gutil.env.babelTarget ? gutil.env.babelTarget : ["last 2 versions"] + } + }] + ] + })] + }, { + format: gutil.env.jsFormat ? gutil.env.jsFormat : 'iife', + name: camelCase(package.name) + } + )) .pipe(concat(globalJsFile)) + .pipe(gulp.dest(paths.dest)) + .pipe(concat(distJsFile)) + .pipe(minify().on('error', function(err) { + gutil.log(gutil.colors.red('[Error]'), err.toString()) + })) + .pipe(sourcemaps.write()) .pipe(gulp.dest(paths.dest)); }); diff --git a/package.json b/package.json index 1573099..64ece62 100644 --- a/package.json +++ b/package.json @@ -31,11 +31,14 @@ "@babel/preset-env": "^7.0.0-beta.39", "babel-core": "^7.0.0-beta.3", "bulma": "^0.6.2", + "camelcase": "^4.1.0", "conventional-github-releaser": "^2.0.0", "del": "^3.0.0", "gulp": "^3.9.1", "gulp-autoprefixer": "^4.1.0", "gulp-babel": "^7.0.1", + "gulp-babel-minify": "^0.3.0", + "gulp-better-rollup": "^3.0.0", "gulp-bump": "^3.1.0", "gulp-clean-css": "^3.9.2", "gulp-concat": "^2.6.1", @@ -43,8 +46,10 @@ "gulp-git": "^2.5.1", "gulp-postcss": "^7.0.1", "gulp-sass": "^3.1.0", + "gulp-sourcemaps": "^2.6.4", "gulp-uglify": "^3.0.0", "gulp-util": "^3.0.8", + "rollup-plugin-babel": "^3.0.3", "run-sequence": "^2.2.1" }, "files": [ From b40299d45a5876951d6fc08b4f4eb3212fe3a5c3 Mon Sep 17 00:00:00 2001 From: Wikiki Date: Sat, 10 Feb 2018 20:25:49 +0100 Subject: [PATCH 2/2] New dist compilation --- dist/bulma-slider.js | 5 +++++ dist/bulma-slider.min.js | 3 ++- dist/bulma-slider.sass | 9 +++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/dist/bulma-slider.js b/dist/bulma-slider.js index 4d651ee..45577c6 100644 --- a/dist/bulma-slider.js +++ b/dist/bulma-slider.js @@ -1,3 +1,6 @@ +(function () { +'use strict'; + // Find output DOM associated to the DOM element passed as parameter function findOutputForSlider(element) { var idVal = element.id; @@ -69,3 +72,5 @@ document.addEventListener('DOMContentLoaded', function() { } }); }); + +}()); diff --git a/dist/bulma-slider.min.js b/dist/bulma-slider.min.js index 9b123b4..619ba57 100644 --- a/dist/bulma-slider.min.js +++ b/dist/bulma-slider.min.js @@ -1 +1,2 @@ -!function(t,e){if("function"==typeof define&&define.amd)define([],e);else if("undefined"!=typeof exports)e();else{e(),t.bulmaSliderMin={}}}(this,function(){"use strict";function t(t){var e,i=window.getComputedStyle(t,null);sliderWidth=parseInt(i.getPropertyValue("width"),10),e=t.getAttribute("min")?t.getAttribute("min"):0;var n=(t.value-e)/(t.getAttribute("max")-e);return{position:(n<0?0:n>1?sliderWidth:sliderWidth*n)+"px"}}document.addEventListener("DOMContentLoaded",function(){var e=document.querySelectorAll('input[type="range"].slider');[].forEach.call(e,function(e){var i=function(t){var e=t.id;outputs=document.getElementsByTagName("output");for(var i=0;ie?0:1