代码拉取完成,页面将自动刷新
/*
* @Author: zi.yang
* @Date: 2022-12-03 20:05:58
* @LastEditors: zi.yang
* @LastEditTime: 2022-12-04 02:31:25
* @Description: rollup.config.js
* @FilePath: /promise/rollup.config.js
*/
/* eslint-disable no-console */
import path from 'path';
import { watch } from 'rollup';
import sourceMaps from 'rollup-plugin-sourcemaps';
import { terser } from 'rollup-plugin-terser';
import typescript from 'rollup-plugin-typescript2';
import commonjs from '@rollup/plugin-commonjs';
const isProd = process.env.BUILD === 'production';
const moduleName = 'ToyPromise';
const override = { compilerOptions: { module: 'ESNext' } };
const resolve = (type) => path.resolve(__dirname, `./dist/toy-promise.${type}.js`);
const options = {
input: './lib/index.ts',
plugins: [
typescript({
tsconfig: './tsconfig.json',
tsconfigOverride: override,
}),
commonjs(),
],
output: [
{
format: 'cjs',
file: resolve('cjs'),
name: moduleName,
},
{
format: 'esm',
file: resolve('esm'),
name: moduleName,
},
{
format: 'umd',
file: resolve('umd'),
name: moduleName,
},
{
format: 'iife',
file: resolve('iife'),
name: moduleName,
},
],
};
if (!isProd) {
const watchOptions = {
...options,
plugins: [
typescript({
tsconfig: './tsconfig.json',
tsconfigOverride: override,
}),
],
watchOptions: {
include: 'lib/**',
exclude: 'node_modules/**',
},
};
const watcher = watch(watchOptions);
watcher.on('event', (event) => {
switch (event.code) {
case 'START':
console.time('buildTime');
console.info('Rebuilding...');
break;
case 'END':
console.timeEnd('buildTime');
console.info('Rebuild Done!');
break;
case 'ERROR':
console.error('Rollup error: ', event);
break;
default:
break;
}
});
}
if (isProd) {
options.plugins.push(...[sourceMaps()]);
options.output = options.output.reduce((prev, cur) => {
prev.push({
...cur,
sourcemap: true,
});
// min.js
prev.push({
...cur,
file: cur.file.replace(/\.js$/, '.min.js'),
sourcemap: true,
plugins: [terser()],
});
return prev;
}, []);
}
export default options;
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。