1 Star 4 Fork 0

LvHuaiSheng/leafer-x-ruler

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
rollup.config.js 3.74 KB
一键复制 编辑 原始数据 按行查看 历史
LvHuaiSheng 提交于 2023-12-14 17:11 . init
import typescript from '@rollup/plugin-typescript'
import commonjs from '@rollup/plugin-commonjs'
import { nodeResolve } from '@rollup/plugin-node-resolve'
import terser from '@rollup/plugin-terser'
import dts from 'rollup-plugin-dts'
import html from '@rollup/plugin-html'
import livereload from 'rollup-plugin-livereload'
import serve from 'rollup-plugin-serve'
// config
const basePath = '.'
const globalName = 'LeaferX.ruler' // <script /> 插件的全局变量名
const supportPlatforms = ['web', 'worker', 'node', 'miniapp']
const external = { '@leafer-ui/core': 'LeaferUI', '@leafer-ui/interface': 'LeaferUI', '@leafer-in/editor': 'LeaferUI' } // 声明外部依赖,不打进插件包,只引用
const port = 12121 // visit http://localhost:12121
// ------
const isDev = process.env.NODE_ENV === 'development'
const platformName = process.env.PLATFORM
const platform = {
'all': {
name: 'index', // output index.esm.js index.js
path: basePath,
withFormat: supportPlatforms.includes('node') ? ['cjs'] : false,
withGlobal: globalName,
withMin: 'min',
external
}
}
const plugins = [
nodeResolve({
browser: true,
preferBuiltins: false
}),
typescript({
tsconfig: './tsconfig.json'
}),
commonjs()
]
let config
if (isDev) {
config = {
input: 'main.ts',
output: {
file: 'dev/bundle.js',
format: 'esm'
},
watch: { exclude: ['node_modules/**'] },
plugins: [
...plugins,
html({
title: 'Leafer Plugin',
meta: [{ charset: 'utf-8' }, {
name: 'viewport',
content: 'width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no'
}]
}),
livereload(),
serve({ contentBase: ['dev/'], port })
]
}
} else {
// build
config = [{ // types/index.d.ts
input: basePath + '/src/index.ts',
output: {
file: basePath + '/types/index.d.ts'
},
plugins: [dts()]
}]
let p = platform[platformName]
if (!(p instanceof Array)) p = [p]
const list = []
p.forEach(c => {
if (c.input && c.output) {
list.push(c)
} else {
const input = c.input || c.path + '/src/index.ts'
const fileBase = c.path + '/dist/' + (c.name || platformName)
const global = c.withGlobal
const min = c.withMin
let external = c.external
list.push({ external, input, output: fileBase + '.esm.js' })
if (c.withMin) list.push({ min, external, input, output: fileBase + '.esm.' + min + '.js' })
if (c.withFormat) {
c.withFormat.forEach(format => {
const cjs = format === 'cjs'
list.push({ external, input, output: fileBase + (cjs ? '.cjs' : '.' + format + '.js'), format })
if (c.withMin) list.push({
min,
external,
input,
output: fileBase + (cjs ? '.' + min + '.cjs' : '.' + format + '.' + min + '.js'),
format
})
})
}
if (global) {
if (c.fullGlobal) external = null
list.push({ global, external, input, output: fileBase + '.js' })
if (c.withMin) list.push({ global, min, external, input, output: fileBase + '.' + min + '.js' })
}
}
})
list.forEach(c => {
const item = {
external: c.external ? Object.keys(c.external) : null,
input: c.input,
plugins: [...plugins]
}
if (c.global) {
item.output = {
file: c.output,
name: c.global,
format: c.format || 'iife'
}
if (c.external) item.output.globals = c.external
} else {
item.output = {
file: c.output,
format: c.format || 'esm'
}
}
if (c.min) item.plugins.push(terser({ format: { comments: false } }))
config.push(item)
})
}
export default config
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/sourcenet/leafer-x-ruler.git
git@gitee.com:sourcenet/leafer-x-ruler.git
sourcenet
leafer-x-ruler
leafer-x-ruler
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385