Skip to content

Commit

Permalink
dropped babel support
Browse files Browse the repository at this point in the history
  • Loading branch information
memob0x committed Aug 22, 2023
1 parent 6a28b67 commit 16cd22b
Show file tree
Hide file tree
Showing 12 changed files with 315 additions and 2,559 deletions.
18 changes: 4 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,16 @@ $ npm install scroll-padlock
```

The source code is entirely written in [standard ECMAScript](https://tc39.es/) with no dependencies.
All major budle formats are supported, including [umd](https://github.com/umdjs/umd), [iife](https://developer.mozilla.org/en-US/docs/Glossary/IIFE), [amd](https://en.wikipedia.org/wiki/Asynchronous_module_definition), [cjs](https://en.wikipedia.org/wiki/CommonJS), [esm](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules) and [SystemJS](https://github.com/systemjs/systemjs); also, a minified version and a transpiled version through babel are available for each of those.
All major bundle formats are supported, including [umd](https://github.com/umdjs/umd), [iife](https://developer.mozilla.org/en-US/docs/Glossary/IIFE), [amd](https://en.wikipedia.org/wiki/Asynchronous_module_definition), [cjs](https://en.wikipedia.org/wiki/CommonJS), [esm](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules) and [SystemJS](https://github.com/systemjs/systemjs); a minified gzipped version is also available for each bundle format.

### Node (basic):
### Node:

```javascript
// umd minified version
import ScrollPadlock from "scroll-padlock";

const scrollPadlock = new ScrollPadlock();
```

### Node (advanced):

```javascript
// es modules version
import ScrollPadlock from "scroll-padlock/dist/es/scroll-padlock.js";

const scrollPadlock = new ScrollPadlock();
```

### Browser (modules):

```html
Expand All @@ -67,8 +57,8 @@ const scrollPadlock = new ScrollPadlock();
### Browser (globals):

```html
<!-- iife babel transpiled minified version -->
<script src="path/to/scroll-padlock/dist/iife/scroll-padlock.babel.min.js"></script>
<!-- iife minified version -->
<script src="path/to/scroll-padlock/dist/iife/scroll-padlock.min.js"></script>

<script>
var scrollPadlock = new ScrollPadlock();
Expand Down
3 changes: 2 additions & 1 deletion build-docs.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { writeFile } from 'fs/promises';
import { writeFile } from 'node:fs/promises';

import jsdoc2md from 'jsdoc-to-markdown';

await writeFile(
Expand Down
90 changes: 35 additions & 55 deletions build.js
Original file line number Diff line number Diff line change
@@ -1,83 +1,63 @@
import { resolve } from 'node:path';

import { rollup } from 'rollup';
import { getBabelOutputPlugin as rollupBabel } from '@rollup/plugin-babel';
import rollupGzip from 'rollup-plugin-gzip';
import rollupTerser from '@rollup/plugin-terser';
import { resolve } from 'path';

const BUNDLES_PRESETS = [
{ format: 'amd' },
{ format: 'amd', babel: true },
{ format: 'amd', min: true },
{ format: 'amd', min: true, babel: true },

{ format: 'iife' },
{ format: 'iife', babel: true },
{ format: 'iife', min: true },
{ format: 'iife', min: true, babel: true },

{ format: 'system' },
{ format: 'system', babel: true },
{ format: 'system', min: true },
{ format: 'system', min: true, babel: true },

{ format: 'es' },
{ format: 'es', babel: true },
{ format: 'es', min: true },
{ format: 'es', min: true, babel: true },

{ format: 'cjs' },
{ format: 'cjs', babel: true },
{ format: 'cjs', min: true },
{ format: 'cjs', min: true, babel: true },

{ format: 'umd' },
{ format: 'umd', babel: true },
{ format: 'umd', min: true },
{ format: 'umd', min: true, babel: true },
];

const pathRoot = resolve('.');

(async () => {
const rollupResult = await rollup({
input: `${pathRoot}/src/padlock.js`,
});
const formats = [
'umd',

return Promise.all(BUNDLES_PRESETS.reduce((accumulator, { format, min, babel }) => {
const plugins = [];
'amd',

if (babel) {
plugins.push(rollupBabel({
presets: [
'@babel/preset-env',
],
'cjs',

comments: false,
'iife',

allowAllFormats: true,
}));
}
'es',

'system',
];

const rollupResult = await rollup({
input: `${pathRoot}/src/padlock.js`,
});

if (min) {
const tasks = [];

for (let formatIndex = 0, { length } = formats; formatIndex < length; formatIndex += 1) {
const format = formats[formatIndex];

const folder = `dist/${format}`;

for (let versionIndex = 0; versionIndex < 2; versionIndex += 1) {
const plugins = [];

let suffixes = '';

if (versionIndex % 2 === 0) {
plugins.push(rollupTerser());

suffixes += '.min';
}

plugins.push(rollupGzip());

accumulator.push(rollupResult.write({
tasks.push(rollupResult.write({
sourcemap: true,

format,

name: 'ScrollPadlock',

file: `${pathRoot}/dist/${format}/scroll-padlock${babel ? '.babel' : ''}${min ? '.min' : ''}.js`,
file: `${pathRoot}/${folder}/scroll-padlock${suffixes}.js`,

exports: 'default',

plugins,
}));
}
}

return accumulator;
}, []));
})();
await Promise.all(tasks);
Loading

0 comments on commit 16cd22b

Please sign in to comment.