You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
76 lines
2.1 KiB
JavaScript
76 lines
2.1 KiB
JavaScript
1 year ago
|
|
||
|
import { nodeResolve } from '@rollup/plugin-node-resolve';
|
||
|
import commonjs from '@rollup/plugin-commonjs';
|
||
|
import path from 'path';
|
||
|
import { watch } from 'rollup';
|
||
|
import { multibanner } from 'bannerjs';
|
||
|
import { babel } from '@rollup/plugin-babel';
|
||
|
import 'colors-cli/toxic';
|
||
7 years ago
|
|
||
|
const watchOptions = {
|
||
4 years ago
|
input: 'src/index.js',
|
||
6 years ago
|
plugins: [
|
||
1 year ago
|
nodeResolve(), // so Rollup can find `ms`
|
||
6 years ago
|
commonjs(), // so Rollup can convert `ms` to an ES module
|
||
1 year ago
|
babel({
|
||
4 years ago
|
babelHelpers: 'bundled',
|
||
6 years ago
|
exclude: 'node_modules/**', // 只编译我们的源代码
|
||
5 years ago
|
presets: [[
|
||
|
'@babel/preset-env', {
|
||
|
/**
|
||
|
* Do not transpile typeof helper with itself
|
||
|
* https://github.com/babel/babel/pull/10788/files
|
||
|
*/
|
||
|
exclude: ['@babel/plugin-transform-typeof-symbol'],
|
||
|
},
|
||
|
]],
|
||
6 years ago
|
}),
|
||
|
],
|
||
7 years ago
|
output: [
|
||
6 years ago
|
{
|
||
|
file: 'dist/hotkeys.common.js',
|
||
|
name: 'hotkeys',
|
||
3 years ago
|
exports: 'auto',
|
||
1 year ago
|
banner: multibanner(),
|
||
6 years ago
|
format: 'cjs',
|
||
|
},
|
||
|
{
|
||
|
file: 'dist/hotkeys.js',
|
||
|
name: 'hotkeys',
|
||
1 year ago
|
banner: multibanner(),
|
||
6 years ago
|
format: 'umd',
|
||
|
},
|
||
|
{
|
||
|
file: 'dist/hotkeys.esm.js',
|
||
|
name: 'hotkeys',
|
||
1 year ago
|
banner: multibanner(),
|
||
6 years ago
|
format: 'es',
|
||
|
},
|
||
7 years ago
|
],
|
||
7 years ago
|
};
|
||
1 year ago
|
const watcher = watch(watchOptions);
|
||
7 years ago
|
|
||
7 years ago
|
watcher.on('event', (event) => {
|
||
6 years ago
|
if (event.code === 'FATAL') {
|
||
|
console.log('FATAL:', event.error.codeFrame);
|
||
|
}
|
||
7 years ago
|
// 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
|
||
|
// FATAL — encountered an unrecoverable error
|
||
|
if (event.code === 'BUNDLE_END') {
|
||
7 years ago
|
event.output.forEach((item) => {
|
||
7 years ago
|
console.log('bundles '.x39 + `${event.input} → ${item.replace(process.cwd() + path.sep, '')}`.blue_bt);
|
||
7 years ago
|
});
|
||
|
console.log(`duration ${event.duration}ms\n`.green);
|
||
7 years ago
|
} else if (event.code === 'END') {
|
||
|
console.log('waiting for changes... ');
|
||
|
}
|
||
|
});
|
||
|
|
||
|
// stop watching
|
||
7 years ago
|
// watcher.close();
|