86 lines
2.5 KiB
JavaScript
86 lines
2.5 KiB
JavaScript
import resolve from '@rollup/plugin-node-resolve';
|
|
import typescript from '@rollup/plugin-typescript';
|
|
import commonjs from '@rollup/plugin-commonjs';
|
|
import postcss from 'rollup-plugin-postcss';
|
|
import autoprefixer from 'autoprefixer';
|
|
import cssnano from 'cssnano';
|
|
import terser from '@rollup/plugin-terser';
|
|
import postcssImport from 'postcss-import';
|
|
import postcssNesting from 'postcss-nesting';
|
|
|
|
import dts from 'rollup-plugin-dts';
|
|
|
|
import glob from 'fast-glob';
|
|
import path from 'path';
|
|
const isApps = process.env.TYPE === 'apps';
|
|
const components = glob.sync('./src/components/**/index.ts');
|
|
const entrys = components.map((entry) => {
|
|
return entry;
|
|
});
|
|
console.log('entry', entrys);
|
|
const output = path.resolve('./dist');
|
|
console.log('output', output);
|
|
/**
|
|
* @type {import('rollup').RollupOptions[]}
|
|
*/
|
|
const configs = entrys
|
|
.map((entry) => {
|
|
const directory = path.dirname(entry);
|
|
const lastDirectory = directory.split('/').pop();
|
|
const input = path.resolve(entry);
|
|
const buildConfig = {
|
|
input: input, // 修改输入文件为 TypeScript 文件
|
|
output: {
|
|
file: path.join(output, `./${lastDirectory}.js`),
|
|
format: 'es', // 输出格式为 ES Module
|
|
},
|
|
plugins: [
|
|
resolve({
|
|
browser: true, // 处理浏览器版本的依赖
|
|
}),
|
|
commonjs(),
|
|
postcss({
|
|
inject: true, // 将 CSS 作为 <style> 标签插入
|
|
minimize: true, // 压缩 CSS
|
|
extract: false, // 将 CSS 写入文件
|
|
sourceMap: false, // 可选,是否生成 source map
|
|
modules: true, // 可选,启用 CSS Modules
|
|
plugins: [
|
|
postcssNesting(), //
|
|
postcssImport(),
|
|
autoprefixer(),
|
|
// cssnano(),
|
|
],
|
|
}),
|
|
typescript({
|
|
tsconfig: './tsconfig.json',
|
|
compilerOptions: {
|
|
declaration: false, // 生成声明文件
|
|
declarationDir: './dist', // 声明文件输出目录
|
|
// outDir: './types', //
|
|
},
|
|
}), // 添加 TypeScript 插件
|
|
terser(), // 压缩输出的 ES Module 文件
|
|
],
|
|
};
|
|
const tsConfig = {
|
|
input: input,
|
|
output: {
|
|
file: path.join(output, `./${lastDirectory}.d.ts`),
|
|
format: 'esm',
|
|
},
|
|
plugins: [
|
|
dts({
|
|
compilerOptions: {
|
|
skipLibCheck: true,
|
|
},
|
|
exclude: ['**/*.css'],
|
|
}),
|
|
],
|
|
};
|
|
return [buildConfig, tsConfig];
|
|
})
|
|
.flat();
|
|
|
|
export default [...configs];
|