1 Star 8 Fork 0

zi.Yang/toy-promise

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
rollup.config.js 2.30 KB
一键复制 编辑 原始数据 按行查看 历史
zi.Yang 提交于 2022-12-04 02:33 +08:00 . feat: 引入 rollup 打包工具
/*
* @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;
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
TypeScript
1
https://gitee.com/Alessandro-pang/toy-promise.git
git@gitee.com:Alessandro-pang/toy-promise.git
Alessandro-pang
toy-promise
toy-promise
master

搜索帮助