Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
{
file: 'dist/hotkeys.common.js',
name: 'hotkeys',
banner: banner.multibanner(),
format: 'cjs',
},
{
file: 'dist/hotkeys.js',
name: 'hotkeys',
banner: banner.multibanner(),
format: 'umd',
},
{
file: 'dist/hotkeys.esm.js',
name: 'hotkeys',
banner: banner.multibanner(),
format: 'es',
},
],
};
const watcher = rollup.watch(watchOptions);
watcher.on('event', (event) => {
if (event.code === 'FATAL') {
console.log('FATAL:', event.error.codeFrame);
}
// event.code can be one of:
// START — the watcher is (re)starting
// BUNDLE_START — building an individual bundle
// BUNDLE_END — finished building a bundle
// END — finished building all bundles
// ERROR — encountered an error while bundling
rollup(rollup_option).then( bundle => {
// console.log("test",bundle);
return write('dist/JSLite.js', bundle.generate({
// output format - 'amd', 'cjs', 'es6', 'iife', 'umd'
// amd – 使用像requirejs一样的银木块定义
// cjs – CommonJS,适用于node和browserify / Webpack
// es6 (default) – 保持ES6的格式
// iife – 使用于
// console.log(bundle.imports); // an array of external dependencies
// console.log(bundle.exports); // an array of names exported by the entry point
// console.log(bundle.modules); // an array of module objects
const umd = await bundle.generate({
format: 'umd',
name: 'hotkeys',
banner: banner.multibanner(),
});
const umdMinified = `${banner.onebanner()}\n${uglify.minify(umd.output[0].code, uglifyOption).code}`;
const common = await bundle.generate({
format: 'cjs',
name: 'hotkeys',
banner: banner.multibanner(),
});
const commonMinified = `${banner.onebanner()}\n${uglify.minify(common.output[0].code, uglifyOption).code}`;
const es = await bundle.generate({
format: 'es',
name: 'hotkeys',
banner: banner.multibanner(),
});
write('dist/hotkeys.js', umd.output[0].code)
.then(() => write('dist/hotkeys.min.js', umdMinified, true))
.then(() => write('dist/hotkeys.common.js', common.output[0].code))
.then(() => write('dist/hotkeys.common.min.js', commonMinified, true))
.then(() => write('dist/hotkeys.esm.js', es.output[0].code));
}
// console.log(bundle.modules); // an array of module objects
const umd = await bundle.generate({
format: 'umd',
name: 'hotkeys',
banner: banner.multibanner(),
});
const umdMinified = `${banner.onebanner()}\n${uglify.minify(umd.output[0].code, uglifyOption).code}`;
const common = await bundle.generate({
format: 'cjs',
name: 'hotkeys',
banner: banner.multibanner(),
});
const commonMinified = `${banner.onebanner()}\n${uglify.minify(common.output[0].code, uglifyOption).code}`;
const es = await bundle.generate({
format: 'es',
name: 'hotkeys',
banner: banner.multibanner(),
});
write('dist/hotkeys.js', umd.output[0].code)
.then(() => write('dist/hotkeys.min.js', umdMinified, true))
.then(() => write('dist/hotkeys.common.js', common.output[0].code))
.then(() => write('dist/hotkeys.common.min.js', commonMinified, true))
.then(() => write('dist/hotkeys.esm.js', es.output[0].code));
}
const path = require('path');
const rollup = require('rollup');
const babel = require('rollup-plugin-babel');
const nodeResolve = require('@rollup/plugin-node-resolve');
const commonjs = require('@rollup/plugin-commonjs');
const { terser } = require('rollup-plugin-terser');
const banner = require('bannerjs');
require('colors-cli/toxic');
const watchOptions = {
input: 'lib/main.js',
output: [
{ file: 'dist/store.common.js', name: 'store', format: 'cjs', banner: banner.multibanner() },
{ file: 'dist/store.js', name: 'store', format: 'umd', banner: banner.multibanner() },
{ file: 'dist/store.esm.js', name: 'store', format: 'es', banner: banner.multibanner() },
{
file: 'dist/store.min.js',
name: 'store',
banner: banner.onebanner(),
format: 'iife',
plugins: [terser()]
},
],
plugins: [
nodeResolve(), // so Rollup can find `ms`
commonjs(), // so Rollup can convert `ms` to an ES module
babel({
exclude: 'node_modules/**', // 只编译我们的源代码
}),
],
};
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import banner from 'bannerjs';
import pkg from './package.json';
export default [
// browser-friendly UMD build
{
input: 'src/main.js',
output: {
name: 'copyTextToClipboard',
file: pkg.browser,
format: 'umd',
banner: banner.multibanner(),
},
plugins: [
resolve(), // so Rollup can find `ms`
commonjs() // so Rollup can convert `ms` to an ES module
]
},
// CommonJS (for Node) and ES module (for bundlers) build.
// (We could have three entries in the configuration array
// instead of two, but it's quicker to generate multiple
// builds from a single configuration where possible, using
// an array for the `output` option, where we can specify
// `file` and `format` for each target)
{
input: 'src/main.js',
external: ['ms'],
const nodeResolve = require('@rollup/plugin-node-resolve');
const commonjs = require('@rollup/plugin-commonjs');
const { terser } = require('rollup-plugin-terser');
const banner = require('bannerjs');
require('colors-cli/toxic');
const watchOptions = {
input: 'src/main.js',
output: [
{ file: 'dist/cookie.cjs.js', name: 'cookie', format: 'cjs' },
{ file: 'dist/cookie.js', name: 'cookie', format: 'umd', banner: banner.multibanner() },
{ file: 'dist/cookie.esm.js', name: 'cookie', format: 'es', banner: banner.multibanner() },
{
file: 'dist/cookie.min.js',
name: 'cookie',
banner: banner.onebanner(),
format: 'iife',
plugins: [terser()]
},
],
plugins: [
nodeResolve(), // so Rollup can find `ms`
commonjs(), // so Rollup can convert `ms` to an ES module
babel({
exclude: 'node_modules/**', // 只编译我们的源代码
}),
],
};
const watcher = rollup.watch(watchOptions);
watcher.on('event', (event) => {
// event.code can be one of:
const nodeResolve = require('@rollup/plugin-node-resolve');
const commonjs = require('@rollup/plugin-commonjs');
const { terser } = require('rollup-plugin-terser');
const banner = require('bannerjs');
require('colors-cli/toxic');
const watchOptions = {
input: 'lib/main.js',
output: [
{ file: 'dist/store.common.js', name: 'store', format: 'cjs', banner: banner.multibanner() },
{ file: 'dist/store.js', name: 'store', format: 'umd', banner: banner.multibanner() },
{ file: 'dist/store.esm.js', name: 'store', format: 'es', banner: banner.multibanner() },
{
file: 'dist/store.min.js',
name: 'store',
banner: banner.onebanner(),
format: 'iife',
plugins: [terser()]
},
],
plugins: [
nodeResolve(), // so Rollup can find `ms`
commonjs(), // so Rollup can convert `ms` to an ES module
babel({
exclude: 'node_modules/**', // 只编译我们的源代码
}),
],
};
const watcher = rollup.watch(watchOptions);
watcher.on('event', (event) => {
// event.code can be one of:
gulp.task('min', function (cb) {
gulp.src('dist/hotkeys.js')
.pipe(uglify({
mangle: true,
output:{
// comments:true
}
}))
.pipe(rename({
suffix:".min"
}))
.pipe(banner(bannerjs.onebanner()))
.pipe(gulp.dest('./dist/'));
})
gulp.task('build', function (cb) {
gulp.src('src/hotkeys.js')
.pipe(umd({
exports: function(file) {
return 'hotkeys';
},
namespace: function(file) {
return 'hotkeys';
}
}))
.pipe(banner(bannerjs.multibanner()))
.pipe(gulp.dest('./dist/'));
})