Rollup d3 bundling trough gulp

This commit is contained in:
Ruben van de Ven 2018-10-30 11:44:47 +01:00
parent 49889172a9
commit 0d2c5e9a47
3 changed files with 33 additions and 8 deletions

View file

@ -4,9 +4,12 @@ var babel = require('gulp-babel');
var concat = require('gulp-concat');
var rename = require('gulp-rename');
var uglify = require('gulp-uglify');
var rollup = require('rollup-stream');
var sourcemaps = require('gulp-sourcemaps');
var browserSync = require('browser-sync');
var jsonld = require('jsonld');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var through = require('through2')
@ -19,7 +22,9 @@ var paths = {
},
"scripts": {
"src": "./src/js/portfolio.js",
"dest": "./assets/js/"
"dest": "./assets/js/",
"d3src": "./src/js/d3.bundle.js",
"d3destDir": "./assets/js/"
},
"data": {
"src": "./rubenvandeven.jsonld",
@ -47,8 +52,19 @@ gulp.task('scripts', function() {
.pipe(gulp.dest(paths.scripts.dest)) // save .js
.pipe(uglify())
.pipe(rename({ extname: '.min.js' }))
// .pipe(sourcemaps.write('maps'))
.pipe(gulp.dest(paths.scripts.d3destDir)) // save .min.js
});
gulp.task('d3', function() {
return rollup( 'rollup.config.js' )
.pipe(source('d3.bundle.js'))
.pipe(gulp.dest(paths.scripts.d3destDir)) // save .js
.pipe(buffer())
.pipe(uglify())
.pipe(rename({ extname: '.min.js' }))
.pipe(sourcemaps.write('maps'))
.pipe(gulp.dest(paths.scripts.dest)) // save .min.js
.pipe(gulp.dest(paths.scripts.d3destDir)) // save .min.js
});
gulp.task('jsonld', function(){
@ -68,6 +84,7 @@ gulp.task('jsonld', function(){
var watchStylesAndScripts = function() {
gulp.watch(paths.styles.src,['styles']);
gulp.watch(paths.scripts.src,['scripts', browserSync.reload]);
gulp.watch(paths.scripts.d3src,['d3', browserSync.reload]);
gulp.watch([paths.data.src], ['jsonld', browserSync.reload]);
}

View file

@ -16,9 +16,13 @@
"gulp-babel": "^7.0.1",
"gulp-concat": "^2.6.1",
"gulp-rename": "^1.4.0",
"gulp-rollup": "^2.16.2",
"gulp-sass": "^4.0.1",
"gulp-sourcemaps": "^2.6.4",
"gulp-uglify": "^3.0.1"
"gulp-uglify": "^3.0.1",
"rollup-stream": "^1.24.1",
"vinyl-buffer": "^1.0.1",
"vinyl-source-stream": "^2.0.0"
},
"dependencies": {
"d3-color": "^1.2.3",

View file

@ -1,9 +1,13 @@
import npm from 'rollup-plugin-node-resolve';
export default {
entry: './src/js/d3.bundle.js',
format: 'iife', //umd or iife
moduleName: 'd3',
plugins: [npm({jsnext: true})],
dest: './assets/js/d3.bundle.js'
input: './src/js/d3.bundle.js',
format : 'iife',
name : 'd3',
plugins: [
npm(
{jsnext: true}
)
],
output : './assets/js/d3.bundle.'
};