2020-07-27 11:40:32 +08:00
|
|
|
import fs from 'fs';
|
|
|
|
import path from 'path';
|
2020-08-19 12:38:26 +08:00
|
|
|
import nodeResolve from '@rollup/plugin-node-resolve';
|
2020-08-12 15:06:55 +08:00
|
|
|
import babel from '@rollup/plugin-babel';
|
|
|
|
import commonjs from '@rollup/plugin-commonjs';
|
2020-07-27 11:40:32 +08:00
|
|
|
import typescript2 from 'rollup-plugin-typescript2';
|
|
|
|
|
|
|
|
function removeDir(name) {
|
|
|
|
try {
|
|
|
|
if (fs.statSync(name).isFile()) {
|
|
|
|
fs.unlinkSync(name);
|
|
|
|
} else {
|
|
|
|
fs.readdirSync(name).forEach((dir) => removeDir(path.join(name, dir)));
|
2020-08-12 15:06:55 +08:00
|
|
|
fs.rmdirSync(name);
|
2020-07-27 11:40:32 +08:00
|
|
|
}
|
|
|
|
} catch (err) {}
|
|
|
|
}
|
|
|
|
|
2020-08-12 15:06:55 +08:00
|
|
|
export default function () {
|
2020-07-27 11:40:32 +08:00
|
|
|
removeDir('package');
|
|
|
|
removeDir('types');
|
2020-08-12 15:06:55 +08:00
|
|
|
const extensions = ['.ts'];
|
2020-08-19 12:38:26 +08:00
|
|
|
return [
|
|
|
|
{
|
|
|
|
input: 'src/index.ts',
|
|
|
|
output: {
|
|
|
|
file: 'es/index.js',
|
|
|
|
format: 'esm',
|
|
|
|
indent: false,
|
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
nodeResolve({ extensions }),
|
|
|
|
typescript2({ useTsconfigDeclarationDir: true }),
|
|
|
|
commonjs({
|
|
|
|
include: /node_modules/,
|
|
|
|
}),
|
|
|
|
babel({
|
|
|
|
extensions,
|
|
|
|
babelHelpers: 'bundled',
|
|
|
|
}),
|
|
|
|
],
|
2020-07-27 11:40:32 +08:00
|
|
|
},
|
2020-08-19 12:38:26 +08:00
|
|
|
{
|
|
|
|
input: 'src/index.ts',
|
|
|
|
output: {
|
|
|
|
file: 'lib/index.js',
|
|
|
|
format: 'cjs',
|
|
|
|
indent: false,
|
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
nodeResolve({ extensions }),
|
|
|
|
typescript2({ useTsconfigDeclarationDir: true }),
|
|
|
|
commonjs({
|
|
|
|
include: /node_modules/,
|
|
|
|
}),
|
|
|
|
babel({
|
|
|
|
extensions,
|
|
|
|
babelHelpers: 'bundled',
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
},
|
|
|
|
];
|
2020-07-27 11:40:32 +08:00
|
|
|
}
|