1 Star 0 Fork 0

3crazy/rematch

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
rollup.config.js 2.17 KB
一键复制 编辑 原始数据 按行查看 历史
shmck 提交于 2019-01-05 08:47 . update rollup/ts build scripts
import { mkdirSync, writeFileSync } from 'fs'
import { join } from 'path'
import replace from 'rollup-plugin-replace'
import { uglify } from 'rollup-plugin-uglify'
import commonJs from 'rollup-plugin-commonjs'
import typescript from 'rollup-plugin-typescript'
import resolve from 'rollup-plugin-node-resolve'
import { minify } from 'uglify-es'
// experimental minifier for ES modules
// https://github.com/TrySound/rollup-plugin-uglify#warning
const pkg = require('./package.json')
const productionPlugins = [
typescript({
typescript: require('typescript'),
}),
replace({
'process.env.NODE_ENV': "'production'",
}),
resolve(),
uglify(
{
compress: {
pure_getters: true,
unsafe: true,
},
output: {
comments: false,
semicolons: false,
},
mangle: {
reserved: ['payload', 'type', 'meta'],
},
},
minify
),
]
// minified production builds
const umdProduction = {
input: 'src/index.ts',
output: [
{
name: 'Rematch',
file: pkg.browser,
format: 'umd',
exports: 'named',
sourcemap: true,
}, // Universal Modules
],
plugins: productionPlugins
}
const cjsProduction = {
input: 'src/index.ts',
output: [
{
file: `${pkg.main}/rematch.min.js`,
format: 'cjs',
exports: 'named',
sourcemap: true,
}, // CommonJS Modules
],
plugins: productionPlugins.concat(commonJs())
}
// full source development builds
const development = {
input: 'src/index.ts',
output: [
{ file: `${pkg.main}/rematch.js`, format: 'cjs', exports: 'named' }, // CommonJS Modules
{ file: pkg.module, format: 'es', exports: 'named', sourcemap: true }, // ES Modules
],
plugins: [
typescript({
typescript: require('typescript'),
}),
replace({
'process.env.NODE_ENV': '"development"',
}),
resolve(),
],
}
// point user to needed build
const root = `"use strict";module.exports="production"===process.env.NODE_ENV?require("./rematch.min.js"):require("./rematch.js");`
const rootFile = folder => {
mkdirSync(join('dist', folder))
writeFileSync(join('dist', folder, 'index.js'), root)
}
export default (() => {
// generate root mapping files
mkdirSync('dist')
rootFile('cjs')
return [development, umdProduction, cjsProduction]
})()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/crazy3/rematch.git
git@gitee.com:crazy3/rematch.git
crazy3
rematch
rematch
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385