Skip to content

Commit

Permalink
feat(build): exports UMD, ESM, and CJS #181 #203
Browse files Browse the repository at this point in the history
Switches from Webpack/TSC to Rollup. This change exports ESM and CJS in
addition to the standard UMD.
  • Loading branch information
jshor committed Nov 26, 2022
1 parent f445fa5 commit dcb97e4
Show file tree
Hide file tree
Showing 7 changed files with 271 additions and 32 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:

env:
GIT_USER: 'GitHub Actions'
GIT_EMAIL: '41898282+github-actions[bot]@users.noreply.github.com'
GIT_EMAIL: 'github-actions[bot]@users.noreply.github.com'
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

jobs:
Expand All @@ -19,7 +19,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 14
node-version: 18
- name: Install Yarn
run: npm i -g yarn
- name: Install npm dependencies
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 14
node-version: 18
- name: Install Yarn
run: npm i -g yarn
- name: Install npm dependencies
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<p align="center">A library for adding events to popular calendar apps.</p>

<p align="center">It provides full support for .ics files for iCalendar and Office Outlook, and also supports Google Calendar, Yahoo! Calendar and Outlook Web.</p>
<p align="center">It provides full support for rendering .ics file content for iCalendar and Office Outlook, and also supports URL generation for Google Calendar, Yahoo! Calendar, and Outlook Web.</p>

<br>

Expand Down Expand Up @@ -123,13 +123,13 @@ icalendar.addProperty('CATEGORIES', 'MEETINGS,MANAGEMENT')

This will [add the `CATEGORIES` ICS property](https://datebook.dev/api/icalendar.html#addproperty-key-string-value-icspropertyvalue) to the iCalendar instance.

##### Downloading
##### Rendering ICS file content

```ts
icalendar.render()
const content = icalendar.render()
```

This will render ICS file content that could be [downloaded for use in iCalendar apps](https://datebook.dev/downloading).
This will render ICS file content which can be [downloaded onto the user's device](https://datebook.dev/api/icalendar.html#example-for-downloading-an-ics-file) for use in local calendar apps.

#### Google Calendar

Expand Down
24 changes: 18 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "datebook",
"version": "7.0.11",
"description": "Generates URLs and downloadable ICS files for adding events to popular calendar apps.",
"description": "Generates URLs and ICS file content for adding events to popular calendar apps.",
"keywords": [
"icalendar",
"google calendar",
Expand All @@ -21,38 +21,50 @@
"url": "https://github.com/jshor/datebook/issues"
},
"homepage": "https://datebook.dev",
"main": "dist/datebook.min.js",
"types": "dist/datebook.d.ts",
"main": "dist/datebook.umd.min.js",
"module": "dist/datebook.esm.min.js",
"types": "dist/index.d.ts",
"files": ["dist"],
"scripts": {
"build": "tsc && esbuild dist/datebook.js --minify --outfile=dist/datebook.min.js",
"build": "rollup -c",
"test": "jest",
"lint": "yarn eslint ./src",
"docs:dev": "vuepress dev docs",
"docs:build": "vuepress build docs",
"release": "standard-version -n"
},
"dependencies": {
"file-saver": "^2.0.2"
"file-saver": "^2.0.5"
},
"devDependencies": {
"@commitlint/cli": "^17.3.0",
"@commitlint/config-conventional": "^17.3.0",
"@rollup/plugin-commonjs": "^23.0.2",
"@rollup/plugin-node-resolve": "^15.0.1",
"@rollup/plugin-typescript": "^9.0.2",
"@types/file-saver": "^2.0.5",
"@types/jest": "^29.2.3",
"@types/node": "^18.11.9",
"@typescript-eslint/eslint-plugin": "^5.44.0",
"@typescript-eslint/parser": "^5.44.0",
"@vuepress/plugin-register-components": "^2.0.0-beta.53",
"codecov": "^3.8.3",
"commitizen": "^4.2.5",
"esbuild": "^0.15.15",
"eslint": "^8.28.0",
"husky": "^8.0.2",
"jest": "^29.3.1",
"jest-environment-jsdom": "^29.3.1",
"query-string": "^7.1.1",
"rollup": "^3.4.0",
"rollup-plugin-terser": "^7.0.2",
"standard-version": "^9.5.0",
"ts-jest": "^29.0.3",
"ts-node": "^10.9.1",
"tslib": "^2.4.1",
"typescript": ">=3.0.0",
"vuepress": "^2.0.0-beta.53"
},
"resolutions": {
"vuepress-vite": "2.0.0-beta.53"
}
}
45 changes: 45 additions & 0 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { nodeResolve } from '@rollup/plugin-node-resolve'
import typescript from '@rollup/plugin-typescript'
import commonjs from '@rollup/plugin-commonjs'
import { terser } from 'rollup-plugin-terser'

const plugins = [
// TODO: this commonjs plugin will no longer be needed after file-saver is removed
// once commonjs plugin is removed, this file can also be renamed to rollup.config.ts
commonjs({
namedExports: {
'file-saver': ['saveAs']
}
}),
typescript(),
nodeResolve()
]

const getOutput = (format, config) => ({
format,
sourcemap: true,
exports: 'named',
file: `dist/datebook.${format}.min.js`,
...config
})

export default [
{
// UMD
input: 'src/index.ts',
plugins: plugins.concat(terser()),
output: getOutput('umd', {
name: 'datebook', // this is the name of the global object
esModule: false
})
},
{
// ESM and CJS
input: 'src/index.ts',
plugins,
output: [
getOutput('esm'),
getOutput('cjs')
]
}
]
7 changes: 3 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
{
"compilerOptions": {
"lib": ["es5", "es6", "dom"],
"outFile": "./dist/datebook.js",
"module": "System",
"outDir": "./dist",
"declaration": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"moduleResolution": "node",
"allowJs": true,
"declaration": true,
"strict": true,
"skipLibCheck": true
},
"include": [
"./src/**/*"
"./src/**/*.ts"
],
"exclude": [
"node_modules",
Expand Down
Loading

0 comments on commit dcb97e4

Please sign in to comment.