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 {terser} from 'rollup-plugin-terser';
|
|
|
|
import license from 'rollup-plugin-license';
|
2022-06-02 19:05:30 +08:00
|
|
|
import {name, version, main, author, dependencies} from './package.json';
|
2022-06-01 15:06:00 +08:00
|
|
|
|
2022-08-16 12:46:28 +08:00
|
|
|
const isForLib = process.env.IS_LIB || false;
|
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-06-01 15:06:00 +08:00
|
|
|
export default {
|
|
|
|
input: isForLib ? './scripts/lib.ts' : './src/index.ts',
|
|
|
|
output: [
|
|
|
|
{
|
2022-06-07 15:36:22 +08:00
|
|
|
file: isForLib ? 'lib/formula.js' : main,
|
2022-06-01 15:06:00 +08:00
|
|
|
name: isForLib ? 'formula' : main,
|
|
|
|
...settings,
|
|
|
|
format: isForLib ? 'iife' : 'cjs',
|
2022-06-02 19:05:30 +08:00
|
|
|
plugins: [isForLib && terser()],
|
2022-06-01 15:06:00 +08:00
|
|
|
strict: !isForLib,
|
2022-06-02 19:05:30 +08:00
|
|
|
footer: isForLib
|
|
|
|
? `var evaluate = formula.evaluate;
|
2022-06-01 15:06:00 +08:00
|
|
|
var momentFormat = formula.momentFormat;
|
2022-06-02 19:05:30 +08:00
|
|
|
var parse = formula.parse;`
|
|
|
|
: ''
|
2022-06-01 15:06:00 +08:00
|
|
|
}
|
|
|
|
],
|
2022-06-02 19:05:30 +08:00
|
|
|
external: isForLib ? [] : external,
|
2022-06-01 15:06:00 +08:00
|
|
|
|
|
|
|
plugins: [
|
|
|
|
json(),
|
|
|
|
resolve({
|
|
|
|
jsnext: true,
|
|
|
|
main: true,
|
|
|
|
browser: true
|
|
|
|
}),
|
|
|
|
typescript({
|
2022-06-02 19:05:30 +08:00
|
|
|
typescript: require('typescript'),
|
|
|
|
sourceMap: false,
|
|
|
|
outputToFilesystem: true
|
2022-06-01 15:06:00 +08:00
|
|
|
}),
|
2022-08-16 12:46:28 +08:00
|
|
|
commonjs(
|
|
|
|
isForLib
|
|
|
|
? {}
|
|
|
|
: {
|
|
|
|
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}
|
|
|
|
`
|
|
|
|
})
|
|
|
|
]
|
|
|
|
};
|