Skip to content

Commit

Permalink
feat: add cjs module export. Closes #59
Browse files Browse the repository at this point in the history
  • Loading branch information
radiovisual committed Nov 23, 2023
1 parent c5a7958 commit bc6015e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
10 changes: 10 additions & 0 deletions __tests__/builds/cjs-module.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* istanbul ignore file */
/* eslint-disable unicorn/prefer-module */
const getVideoId = require('../../dist/get-video-id.cjs.js');

describe('bundled CJS module', () => {
test('has the expected API', () => {
expect(typeof getVideoId).toBe('function');
expect(getVideoId('https://www.youtube.com/watch?v=1234').id).toBe('1234');
});
});
2 changes: 1 addition & 1 deletion __tests__/builds/umd-module.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* istanbul ignore file */
/* eslint-disable unicorn/prefer-module */
const getVideoId = require('../../dist/get-video-id.js');
const getVideoId = require('../../dist/get-video-id.umd.js');

describe('bundled umd module', () => {
test('has the expected API', () => {
Expand Down
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ You can use this module in **Node.js** or in the **browser**. See below for the
const getVideoId = require('get-video-id');
```

**ES2015 Module**
**ES Module**
```js
import getVideoId from 'get-video-id';
```

**Browser**
```html
<script src="https://cdn.jsdelivr.net/npm/get-video-id/dist/get-video-id.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/get-video-id/dist/get-video-id.umd.min.js"></script>
```

###### Download
Expand Down
20 changes: 16 additions & 4 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,14 @@ const config = {
output: [
{
file: pkg.main,
format: 'umd',
format: 'cjs',
sourcemap: true,
name: 'getVideoId',
banner,
},
{
file: minified(pkg.main),
format: 'umd',
format: 'cjs',
sourcemap: true,
name: 'getVideoId',
banner,
},
{
Expand All @@ -38,6 +36,20 @@ const config = {
sourcemap: true,
banner,
},
{
file: minified('dist/get-video-id.umd.js'),
format: 'umd',
sourcemap: true,
name: 'getVideoId',
banner,
},
{
file: 'dist/get-video-id.umd.js',
format: 'umd',
sourcemap: true,
name: 'getVideoId',
banner,
},
],
preserveModules: false,
plugins: [
Expand Down

0 comments on commit bc6015e

Please sign in to comment.