Skip to content

Commit 1cd1dd4

Browse files
authored
feat!: build as ESM-Only, drop CJS (#348)
* feat!: build as ESM-Only, drop CJS
1 parent f9c1525 commit 1cd1dd4

File tree

7 files changed

+16
-35
lines changed

7 files changed

+16
-35
lines changed

.github/workflows/main.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,6 @@ jobs:
7373
- name: Build Library
7474
run: pnpm build:lib
7575

76-
- name: validate "Are the Types Wrong"
77-
run: pnpm are-types-wrong
78-
7976
- name: Build Website (GitHub demo site)
8077
run: pnpm build:demo
8178

README.md

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,27 +98,22 @@ with this code in place, we can now use the following CSP meta tag (which is wha
9898
There are multiple ways to install and use the library, you can see below the folder structure of the distribution files
9999
1. `dist/browser`: Standalone build which assigns `multipleSelect` on the `window.multipleSelect` object
100100
- browser standalone means that you can simply load it with `<script></script>` and then `multipleSelect('#mySelect')`
101-
- 2 builds are available CJS (`.cjs`) and ESM (`.js`) and for the latter you will need to load it with `<script type="module">`
102-
2. `cjs`: to use as CommonJS with `require('multiple-select-vanilla')`
103-
3. `esm`: to use as ESM with `import from 'multiple-select-vanilla'`
101+
- only ESM build (`.js`) are provided, you will need to load it with `<script type="module">`
102+
2. `esm`: to use as ESM with `import from 'multiple-select-vanilla'`
104103

105104
```
106105
dist/
107106
browser/
108107
multiple-select.js # ESM build, use with: window.multipleSelect
109-
multiple-select.cjs # CJS (CommonJS) build, use with: window.multipleSelect
110108
locales/
111-
multiple-select-all-locales.cjs # all-in-1 locales as CJS
112109
multiple-select-all-locales.js # all-in-1 locales as ESM
113110
..
114-
multiple-select-fr-FR.cjs # French locale as CJS
115111
multiple-select-fr-FR.js # French locale as ESM
116112
...
117113
styles/ # CSS and SASS Stylings
118114
css/
119115
sass/
120116
index.d.ts # d.ts Type Definitions
121-
multiple-select.cjs # CJS (CommonJS), used by: require()
122117
multiple-select.js # ESM, used by: import from
123118
```
124119

packages/demo/src/getting-started.html

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ <h5>CDN</h5>
2222
including Multiple-Select-Vanilla. Just use the following CDN links.
2323
</p>
2424
<p>
25-
The project now ships its <code>.js</code> files as ESM by default, if you still wish to use the legacy CommonJS (CJS) format with <code>require()</code>,
26-
then you will have to use <code>.cjs</code> file extension.
25+
The project now ships as ESM-Only, if you still wish to use the legacy CommonJS (CJS) format with <code>require()</code>,
26+
then use previous 3.x version.
2727
</p>
2828

2929
<div style="background: #f7f7f7; padding: 10px">
@@ -33,9 +33,6 @@ <h5>CDN</h5>
3333

3434
&lt;!-- (ESM requires <span style="color:#d63384">type=&quot;module&quot;</span>) Latest compiled and minified JavaScript --&gt;
3535
&lt;script type=&quot;module&quot; src=&quot;<span style="color:#0a3069">https://cdn.jsdelivr.net/npm/[email protected]/dist/browser/multiple-select.js</span>&quot;&gt;&lt;/script&gt;
36-
37-
&lt;!-- (CJS requires <span style="color:#d63384">.cjs</span> extension) Latest compiled and minified JavaScript --&gt;
38-
&lt;script src=&quot;<span style="color:#0a3069">https://cdn.jsdelivr.net/npm/[email protected]/dist/browser/multiple-select.cjs</span>&quot;&gt;&lt;/script&gt;</pre>
3936
</div>
4037

4138
<quote>
@@ -52,16 +49,12 @@ <h5>NPM</h5>
5249
</div>
5350
</section>
5451

55-
<h5>CommonJS <code>require()</code> / ESM <code>import from</code></h5>
52+
<h5>ESM <code>import from</code></h5>
5653
<p>
5754
The library provides both CommonJS or ESM, see the example below:
5855
</p>
5956
<div style="background: #f7f7f7; padding: 10px">
6057
<pre>
61-
// CommonJS
62-
<span style="color:#cf222e">const</span> { multipleSelect } = <span style="color:#6639ba">require</span>(<span style="color:#0a3069">'multiple-select-vanilla'</span>);
63-
<span style="color:#6639ba">multipleSelect</span>(<span style="color:#0a3069">'.multiple-select'</span>, {<span style="color:#a0a1a7">/*...*/</span>});
64-
6558
// ESM
6659
<span style="color:#cf222e">import</span> { multipleSelect } <span style="color:#cf222e">from</span> <span style="color:#0a3069">'multiple-select-vanilla'</span>;
6760
<span style="color:#6639ba">multipleSelect</span>(<span style="color:#0a3069">'.multiple-select'</span>, {<span style="color:#a0a1a7">/*...*/</span>});

packages/demo/vite.config.mts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ import { defineConfig } from 'vite';
22

33
export default defineConfig({
44
base: './',
5+
css: {
6+
preprocessorOptions: {
7+
scss: {
8+
quietDeps: true,
9+
},
10+
},
11+
},
512
server: {
613
port: 4000,
714
cors: true,

packages/multiple-select-vanilla/build-prod.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { buildSync } from 'esbuild';
22
import { globSync } from 'tinyglobby';
33

4-
const buildFormats = ['cjs', 'esm'];
4+
const buildFormats = ['esm'];
55
const localeFiles = globSync('src/locales/**/*.ts');
66
const localeEntryPoints = [];
77

packages/multiple-select-vanilla/clone-dts.mjs

Lines changed: 0 additions & 3 deletions
This file was deleted.

packages/multiple-select-vanilla/package.json

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,11 @@
2121
"homepage": "https://github.com/ghiscoding/multiple-select-vanilla",
2222
"license": "MIT",
2323
"type": "module",
24-
"main": "./dist/index.cjs",
2524
"types": "./dist/index.d.ts",
2625
"exports": {
2726
".": {
28-
"import": {
29-
"types": "./dist/index.d.ts",
30-
"default": "./dist/index.js"
31-
},
32-
"require": {
33-
"types": "./dist/index.d.cts",
34-
"default": "./dist/index.cjs"
35-
}
27+
"types": "./dist/index.d.ts",
28+
"default": "./dist/index.js"
3629
},
3730
"./dist/browser/*": "./dist/browser/*",
3831
"./dist/locales/*": "./dist/locales/*",
@@ -57,7 +50,7 @@
5750
"scripts": {
5851
"are-types-wrong": "pnpx @arethetypeswrong/cli --pack .",
5952
"clean": "rimraf dist",
60-
"build": "pnpm build:all && pnpm build:types:prod && pnpm clone:dts",
53+
"build": "pnpm build:all && pnpm build:types:prod",
6154
"postbuild": "pnpm sass:build && pnpm sass:copy",
6255
"dev:init": "pnpm sass:build && pnpm sass:copy && pnpm build:all",
6356
"build:all": "node build-prod.mjs",
@@ -66,7 +59,6 @@
6659
"build:esm": "esbuild src/index.ts --bundle --minify --format=esm --target=es2021 --sourcemap --outfile=dist/multiple-select.js",
6760
"build:types": "tsc --emitDeclarationOnly --incremental --declarationMap false --outDir dist",
6861
"build:types:prod": "tsc --emitDeclarationOnly --incremental --declarationMap --outDir dist",
69-
"clone:dts": "node clone-dts.mjs",
7062
"sass:build": "sass src/styles:dist/styles/css --style=compressed --quiet-deps --no-source-map",
7163
"postsass:build": "postcss dist/styles/css/**/* --dir dist/styles/css --base dist/styles/css --no-map --use cssnano --use autoprefixer --style=compressed",
7264
"sass:watch": "sass src/styles:dist/styles/css --watch --style=compressed --quiet-deps --no-source-map",

0 commit comments

Comments
 (0)