Created
December 25, 2018 08:11
-
-
Save cssmagic/cd4de0a531dd0b71fc410cec6062121e to your computer and use it in GitHub Desktop.
旧代码存档:用 Rollup 打包 ES6 模块
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
var gulp = require('gulp') | |
gulp.task('mobile/build-es', function () { | |
var path = require('path') | |
var glob = require('glob') | |
var rollup = require('rollup').rollup | |
// var commonjs = require('rollup-plugin-commonjs') | |
// var nodeResolve = require('rollup-plugin-node-resolve') | |
var config = require('../config') | |
var entries = glob.sync('./mobile/js/*.js') | |
var tasks = entries.map(function (item) { | |
console.log('[Rollup] Bundling: ' + item) | |
return rollup({ | |
entry: item, | |
plugins: [ | |
// nodeResolve({ | |
// jsnext: true, | |
// main: true, | |
// }), | |
// commonjs(), | |
], | |
}).then(function (bundle) { | |
var dest = path.join(config.dist, 'w', path.basename(item)) | |
console.log('[Rollup] Bundled to: ' + dest) | |
return bundle.write({ | |
format: 'iife', | |
dest: dest, | |
}) | |
}, function (err) { | |
console.error('[Rollup] Error: ' + err.message) | |
}) | |
}) | |
return Promise.all(tasks) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment