Skip to content
Permalink
Browse files

chore: update rollup config

  • Loading branch information
simonwong committed Dec 26, 2019
1 parent 36f63d7 commit 0aab814f129de73ef12b1652c43e04139000a2db
Showing with 1,144 additions and 7 deletions.
  1. +10 −0 .babelrc
  2. +2 −0 .gitignore
  3. +10 −0 package.json
  4. +69 −0 rollup.config.ts
  5. +3 −0 src/index.ts
  6. +1,050 −7 yarn.lock
@@ -0,0 +1,10 @@
{
"presets": [
[
"@babel/preset-env",
{
"modules": false
}
]
]
}
@@ -102,3 +102,5 @@ dist

# TernJS port file
.tern-port

lib
@@ -18,9 +18,19 @@
"lint:fix": "eslint --fix --ext .js,.ts ./src"
},
"devDependencies": {
"@babel/preset-env": "^7.7.7",
"@typescript-eslint/eslint-plugin": "^2.13.0",
"@typescript-eslint/parser": "^2.13.0",
"eslint": "^6.8.0",
"rollup": "^1.27.14",
"rollup-plugin-babel": "^4.3.3",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-eslint": "^7.0.0",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-typescript2": "^0.25.3",
"typescript": "^3.7.4"
},
"dependencies": {
"lodash": "^4.17.15"
}
}
@@ -0,0 +1,69 @@
import path from 'path'
import { RollupOptions } from 'rollup'
import rollupTypescript from 'rollup-plugin-typescript2'
import babel from 'rollup-plugin-babel'
import resolve from 'rollup-plugin-node-resolve'
import commonjs from 'rollup-plugin-commonjs'
import { eslint } from 'rollup-plugin-eslint'
import { DEFAULT_EXTENSIONS } from '@babel/core'

import pkg from './package.json'

const paths = {
input: path.join(__dirname, '/src/index.ts'),
output: path.join(__dirname, '/lib'),
}

// rollup 配置项
const rollupConfig: RollupOptions = {
input: paths.input,
output: [
// 输出 commonjs 规范的代码
{
file: path.join(paths.output, 'index.js'),
format: 'cjs',
name: pkg.name,
},
// 输出 es 规范的代码
{
file: path.join(paths.output, 'index.esm.js'),
format: 'es',
name: pkg.name,
},
],
// external: ['lodash'], // 指出应将哪些模块视为外部模块,如 Peer dependencies 中的依赖
// plugins 需要注意引用顺序
plugins: [
// 验证导入的文件
eslint({
throwOnError: true, // lint 结果有错误将会抛出异常
throwOnWarning: true,
include: ['src/**/*.ts'],
exclude: ['node_modules/**', 'lib/**', '*.js'],
}),

// 使得 rollup 支持 commonjs 规范,识别 commonjs 规范的依赖
commonjs(),

// 配合 commnjs 解析第三方模块
resolve({
// 将自定义选项传递给解析插件
customResolveOptions: {
moduleDirectory: 'node_modules',
},
}),
rollupTypescript(),
babel({
runtimeHelpers: true,
// 只转换源代码,不运行外部依赖
exclude: 'node_modules/**',
// babel 默认不支持 ts 需要手动添加
extensions: [
...DEFAULT_EXTENSIONS,
'.ts',
],
}),
],
}

export default rollupConfig
@@ -0,0 +1,3 @@
export default function myFirstFunc () {
return 'hello rollup'
}

0 comments on commit 0aab814

Please sign in to comment.
You can’t perform that action at this time.