Skip to content

Commit

Permalink
build: output ESM and UMD
Browse files Browse the repository at this point in the history
Signed-off-by: Zixuan Liu <nodeces@gmail.com>
  • Loading branch information
nodece committed Oct 5, 2021
1 parent 23b069f commit dea6c17
Show file tree
Hide file tree
Showing 8 changed files with 325 additions and 39 deletions.
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jobs:
- run: yarn install --ignore-engines
- run: yarn lint
- run: yarn test
- run: yarn build
- run: yarn coverage
- name: Coveralls
uses: coverallsapp/github-action@master
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
.idea
.vscode
node_modules
lib
yarn-error.log
package-lock.json
coverage

lib
es
dist
46 changes: 28 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,26 @@
"name": "casbin.js",
"version": "1.0.0-beta.5",
"description": "An authorization library that supports access control models like ACL, RBAC, ABAC in Typescript",
"main": "lib/cjs/index.js",
"typings": "lib/cjs/index.d.ts",
"module": "lib/esm/index.js",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
"module": "es/index.js",
"scripts": {
"prepack": "run-s lint test build",
"postpack": "run-s clean",
"build": "run-s clean && run-p build:*",
"build:cjs": "tsc -p tsconfig.cjs.json",
"build:esm": "tsc -p tsconfig.esm.json",
"build": "run-s clean && run-p build:**",
"build:lib:cjs": "tsc -p tsconfig.cjs.json",
"build:lib:esm": "tsc -p tsconfig.esm.json",
"build:dist": "rollup -c",
"test": "jest",
"lint": "eslint . --ext .js,.ts",
"fmt": "eslint . --ext .js,.ts --fix",
"semantic-release": "semantic-release",
"commit": "git-cz",
"clean": "rimraf lib",
"clean": "rimraf lib es dist",
"coverage": "jest --coverage"
},
"devDependencies": {
"@rollup/plugin-typescript": "^8.2.5",
"@semantic-release/changelog": "^5.0.1",
"@semantic-release/commit-analyzer": "^8.0.1",
"@semantic-release/git": "^9.0.0",
Expand All @@ -28,8 +30,8 @@
"@semantic-release/release-notes-generator": "^9.0.2",
"@types/jest": "^26.0.20",
"@types/lodash": "^4.14.168",
"@types/picomatch": "^2.2.2",
"@types/node": "^10.5.3",
"@types/picomatch": "^2.2.2",
"@typescript-eslint/eslint-plugin": "^4.17.0",
"@typescript-eslint/parser": "^4.17.0",
"coveralls": "^3.0.2",
Expand All @@ -44,25 +46,30 @@
"prettier": "^2.2.1",
"pretty-quick": "^3.1.0",
"rimraf": "^3.0.2",
"rollup": "^2.58.0",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-sourcemaps": "^0.6.3",
"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-typescript2": "^0.30.0",
"semantic-release": "^17.4.2",
"ts-jest": "^26.5.3",
"tslint": "^5.11.0",
"typescript": "^4.3.5",
"picomatch": "^2.2.3",
"csv-parse": "^4.15.3",
"buffer": "^6.0.3"
},
"peerDependencies": {
"picomatch": "^2.2.3",
"buffer": "^6.0.3"
"typescript": "^4.3.5"
},
"peerDependencies": {},
"dependencies": {
"await-lock": "^2.0.1",
"expression-eval": "^4.0.0"
"buffer": "^6.0.3",
"expression-eval": "^4.0.0",
"path-browserify": "^1.0.1",
"picomatch": "^2.3.0"
},
"files": [
"lib",
"examples"
"examples",
"es",
"dist"
],
"homepage": "https://casbin.org",
"repository": {
Expand All @@ -84,5 +91,8 @@
"publishConfig": {
"registry": "https://registry.npmjs.org/",
"tag": "next"
},
"browser": {
"path": "path-browserify"
}
}
38 changes: 38 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import typescript from '@rollup/plugin-typescript';
import sourceMaps from 'rollup-plugin-sourcemaps';
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import { terser } from 'rollup-plugin-terser';

export default {
input: 'src/index.ts',
plugins: [
commonjs(),
resolve({
preferBuiltins: false,
}),
typescript({
tsconfig: 'tsconfig.esm.json',
}),
sourceMaps(),
terser(),
],
output: [
{
format: 'umd',
file: 'dist/casbin.js',
name: 'casbin',
sourcemap: true,
},
{
format: 'es',
file: 'dist/casbin.mjs',
sourcemap: true,
},
{
format: 'es',
file: 'dist/casbin.esm.js',
sourcemap: true,
},
],
};
2 changes: 1 addition & 1 deletion tsconfig.cjs.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"compilerOptions": {
"target": "ES2017",
"module": "CommonJS",
"outDir": "lib/cjs"
"outDir": "lib"
}
}
2 changes: 1 addition & 1 deletion tsconfig.esm.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"compilerOptions": {
"target": "ES2017",
"module": "ESNext",
"outDir": "lib/esm"
"outDir": "es"
}
}
3 changes: 1 addition & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
"declaration": true,
"downlevelIteration": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"rootDir": "./src"
"esModuleInterop": true
},
"include": ["src/**/*"]
}

0 comments on commit dea6c17

Please sign in to comment.