Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make ical.es5.cjs an UMD module for browsers #659

Merged
merged 1 commit into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 30 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,48 @@ and example links.
There is also a validator that demonstrates how to use the library in a webpage in the
[tools/](https://github.com/kewisch/ical.js/tree/main/tools) subdirectory.

[Try the validator online](http://kewisch.github.io/ical.js/validator.html), it always uses the latest release of ICAL.js.
[Try the validator online](http://kewisch.github.io/ical.js/validator.html), it always uses the
latest release of ICAL.js.

## Installing

You can install ICAL.js via [npm](https://www.npmjs.com/), if you would like to use it in Node.js:
```
ICAL.js has no dependencies and is written in modern JavaScript. You can install ICAL.js via
[npm](https://www.npmjs.com/), if you would like to use it in Node.js:
```bash
npm install ical.js
```
Then simply import it for use:
```javascript
import ICAL from "ical.js";
```

ICAL.js has no dependencies and is written in modern JavaScript. A version transpiled to ES5 is
available as well. It should work in all versions of Node.js and modern browsers.
If you are working with a browser, be aware this is an ES6 module:

```html
<script type="module">
import ICAL from "https://unpkg.com/ical.js";
document.querySelector("button").addEventListener("click", () => {
ICAL.parse(document.getElementById("txt").value);
});
</script>
```

If you need to make use of a script tag, you can use the transpiled ES5 version:
```html
<script src="https://unpkg.com/ical.js/dist/ical.es5.cjs"></script>
<textarea id="txt"></textarea>
<button onclick="ICAL.parse(document.getElementById('txt').value)"></button>
```

## Timezones
The stock ical.js does not register any timezones, due to the additional size it brings. If you'd
like to do timezone conversion, and the timezone definitions are not included in the respective ics
files, you'll need to use `ical.timezones.js` or its minified counterpart.

This file is not included in the distribution since it pulls in IANA timezones that might change
regularly. See the github actions on building your own timezones during CI, or grab a recent build
from main.

## Documentation

For a few guides with code samples, please check out
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ical.js",
"version": "2.0.0",
"version": "2.0.1",
"author": "Philipp Kewisch",
"contributors": [
"Github Contributors (https://github.com/kewisch/ical.js/graphs/contributors)"
Expand Down
59 changes: 41 additions & 18 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,55 @@
import { getBabelOutputPlugin } from '@rollup/plugin-babel';
import { babel } from '@rollup/plugin-babel';
import { terser } from 'rollup-plugin-terser';

export default {
const LICENSE =
`/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
* Portions Copyright (C) Philipp Kewisch */`;

const TERSER_OPTIONS = {
format: {
comments: function(node, comment) {
if (comment.type == 'comment2') {
return /terms of the Mozilla Public/.test(comment.value) && comment.pos === 0;
}
return false;
}
}
};

export default [{
input: 'lib/ical/module.js',
output: [
{ file: 'dist/ical.js', format: 'es', exports: "default" },
{ file: 'dist/ical.js', format: 'es', exports: 'default' },
{
file: 'dist/ical.min.js',
banner: LICENSE,
format: 'es',
exports: "default",
plugins: [terser()]
},
exports: 'default',
plugins: [terser(TERSER_OPTIONS)]
}
]
}, {
input: 'lib/ical/module.js',
output: [
{
file: 'dist/ical.es5.cjs',
exports: "default",
format: 'cjs',
plugins: [
getBabelOutputPlugin({ presets: ['@babel/preset-env'] })
],
exports: 'default',
name: 'ICAL',
format: 'umd',
banner: LICENSE,
},
{
file: 'dist/ical.es5.min.cjs',
exports: "default",
format: 'cjs',
plugins: [
getBabelOutputPlugin({ presets: ['@babel/preset-env'] }),
terser()
]
exports: 'default',
name: 'ICAL',
format: 'umd',
banner: LICENSE,
plugins: [terser(TERSER_OPTIONS)],
}
],
plugins: [
babel({ babelHelpers: 'bundled', presets: ['@babel/preset-env'] })
]
};
}];