gulpfile.babel.js加入:
var gulp = require('gulp');
var rollup = require('rollup');
import resolve from '@rollup/plugin-node-resolve';
import babel from '@rollup/plugin-babel';
import commonjs from '@rollup/plugin-commonjs';
import {terser} from 'rollup-plugin-terser';
var paths = {
scripts: {
src: 'src/scripts/**/*.js',
dest: 'dist/scripts/'
}
};
/*
* Define our tasks using plain functions
*/
function scripts() {
return rollup.rollup({
input: './src/scripts/main.js',
plugins: [
resolve(),
commonjs(),
babel({ babelHelpers: 'bundled' }),
terser({
keep_fnames: true,
format: {
quote_style:1
}
})
]
}).then(bundle => {
return bundle.write({
file: './dist/scripts/main.js',
format: 'iife',
name: 'main',
sourcemap: true
});
});
}
function watch() {
gulp.watch(paths.scripts.src, scripts);
}
/*
* Specify if tasks run in series or parallel using `gulp.series` and `gulp.parallel`
*/
// var build = gulp.series(clean, gulp.parallel(styles, scripts));
var build = gulp.series(gulp.parallel(scripts,watch));
/*
* You can use CommonJS `exports` module notation to declare tasks
*/
exports.scripts = scripts;
exports.watch = watch;
exports.build = build;
/*
* Define default task that can be called by just running `gulp` from cli
*/
exports.default = build;
.babelrc.json加入:
{
"presets": [ "@babel/preset-env" ]
}