2022-06-01 15:06:00 +08:00
|
|
|
// rollup.config.js
|
2022-06-02 19:05:30 +08:00
|
|
|
import commonjs from '@rollup/plugin-commonjs';
|
|
|
|
import json from '@rollup/plugin-json';
|
|
|
|
import resolve from '@rollup/plugin-node-resolve';
|
|
|
|
import typescript from '@rollup/plugin-typescript';
|
2022-06-01 15:06:00 +08:00
|
|
|
import license from 'rollup-plugin-license';
|
2022-11-02 22:45:12 +08:00
|
|
|
import {
|
|
|
|
name,
|
|
|
|
version,
|
|
|
|
main,
|
|
|
|
module,
|
|
|
|
author,
|
|
|
|
dependencies
|
|
|
|
} from './package.json';
|
|
|
|
import path from 'path';
|
2022-06-01 15:06:00 +08:00
|
|
|
|
|
|
|
const settings = {
|
2022-06-02 19:05:30 +08:00
|
|
|
globals: {}
|
2022-06-01 15:06:00 +08:00
|
|
|
};
|
|
|
|
|
2022-06-02 19:05:30 +08:00
|
|
|
const external = id =>
|
|
|
|
new RegExp(
|
|
|
|
`^(?:${Object.keys(dependencies)
|
|
|
|
.concat([])
|
|
|
|
.map(value =>
|
|
|
|
value.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&').replace(/-/g, '\\x2d')
|
|
|
|
)
|
|
|
|
.join('|')})`
|
|
|
|
).test(id);
|
|
|
|
|
2022-11-02 22:45:12 +08:00
|
|
|
export default [
|
|
|
|
{
|
|
|
|
input: ['./src/index.ts', './src/doc.ts'],
|
|
|
|
output: [
|
|
|
|
{
|
|
|
|
...settings,
|
|
|
|
dir: path.dirname(main),
|
|
|
|
format: 'cjs',
|
|
|
|
exports: 'named',
|
|
|
|
preserveModulesRoot: './src',
|
|
|
|
preserveModules: true // Keep directory structure and files
|
|
|
|
}
|
|
|
|
],
|
|
|
|
external: external,
|
|
|
|
plugins: getPlugins('cjs')
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: ['./src/index.ts', './src/doc.ts'],
|
|
|
|
output: [
|
|
|
|
{
|
|
|
|
...settings,
|
|
|
|
dir: path.dirname(module),
|
|
|
|
format: 'esm',
|
|
|
|
exports: 'named',
|
|
|
|
preserveModulesRoot: './src',
|
|
|
|
preserveModules: true // Keep directory structure and files
|
|
|
|
}
|
|
|
|
],
|
|
|
|
external: external,
|
|
|
|
plugins: getPlugins('esm')
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
function getPlugins(format = 'esm') {
|
|
|
|
const typeScriptOptions = {
|
|
|
|
typescript: require('typescript'),
|
|
|
|
sourceMap: false,
|
|
|
|
outputToFilesystem: true,
|
2022-06-01 15:06:00 +08:00
|
|
|
|
2022-11-02 22:45:12 +08:00
|
|
|
...(format === 'esm'
|
|
|
|
? {
|
|
|
|
compilerOptions: {
|
|
|
|
rootDir: './src',
|
|
|
|
outDir: path.dirname(module)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
: {
|
|
|
|
compilerOptions: {
|
|
|
|
rootDir: './src',
|
|
|
|
outDir: path.dirname(main)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
};
|
|
|
|
|
|
|
|
return [
|
2022-06-01 15:06:00 +08:00
|
|
|
json(),
|
|
|
|
resolve({
|
|
|
|
jsnext: true,
|
|
|
|
main: true,
|
|
|
|
browser: true
|
|
|
|
}),
|
2022-11-02 22:45:12 +08:00
|
|
|
typescript(typeScriptOptions),
|
|
|
|
commonjs({
|
|
|
|
include: 'node_modules/**',
|
|
|
|
extensions: ['.js'],
|
|
|
|
ignoreGlobal: false,
|
|
|
|
sourceMap: false
|
2022-06-01 15:06:00 +08:00
|
|
|
}),
|
|
|
|
license({
|
|
|
|
banner: `
|
|
|
|
${name} v${version}
|
|
|
|
Copyright 2021<%= moment().format('YYYY') > 2021 ? '-' + moment().format('YYYY') : null %> ${author}
|
|
|
|
`
|
|
|
|
})
|
2022-11-02 22:45:12 +08:00
|
|
|
];
|
|
|
|
}
|