代码拉取完成,页面将自动刷新
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
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。