diff --git a/package.json b/package.json index 4bf85db0..efaa1aaa 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/scripts/build.js b/scripts/build.js index fff6451c..47780b4e 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -1,5 +1,6 @@ const { build } = require('esbuild'); +// iife build({ entryPoints: ['src/init.js', 'src/LmcCookieConsentManager.js'], bundle: true, @@ -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); +});