Skip to content

Commit

Permalink
Feat: Introduce ES module entry point
Browse files Browse the repository at this point in the history
  • Loading branch information
literat committed Nov 11, 2021
1 parent 1df5c0b commit fad5730
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
"publishConfig": {
"access": "public"
},
"main": "LmcCookieConsentManager.js",
"module": "LmcCookieConsentManager.esm.js",
"browser": {
"./LmcCookieConsentManager.js": "./LmcCookieConsentManager.js",
"./LmcCookieConsentManager.esm.js": "./LmcCookieConsentManager.esm.js"
},
"repository": {
"type": "git",
"url": "https://github.com/lmc-eu/cookie-consent-manager.git"
Expand Down
19 changes: 19 additions & 0 deletions scripts/build.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { build } = require('esbuild');

// iife
build({
entryPoints: ['src/init.js', 'src/LmcCookieConsentManager.js'],
bundle: true,
Expand All @@ -9,3 +10,21 @@ build({
console.error(error);
process.exit(1);
});

// esm
build({
entryPoints: ['src/LmcCookieConsentManager.js'],
bundle: true,
target: 'es2017',
outfile: 'dist/LmcCookieConsentManager.esm.js',
// format: 'esm', // or use platform: neutral and mainFields: ['main']
platform: 'neutral', // or use format: 'esm' without platform and mainFields
/**
* the "main" field was ignored (main fields must be configured manually when using the "neutral" platform)
* because vanilla-cookie-consent is set as `main` in package.json
*/
mainFields: ['main'],
}).catch((error) => {
console.error(error);
process.exit(1);
});

0 comments on commit fad5730

Please sign in to comment.