Skip to content

Commit

Permalink
Fix package.json for bundling for browser environments
Browse files Browse the repository at this point in the history
  • Loading branch information
lahmatiy committed Oct 10, 2024
1 parent 6cbbf03 commit 0ef00a7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- Bumped `csstree` to [^3.0.0](https://github.com/csstree/csstree/releases/tag/v3.0.0)
- Added default reporters into bundle entry points
- Fixed the resolution of a path to a reporter by employing `enhanced-resolve`, which now considers the `exports` field in `package.json`
- Fixed `package.json` for bundling for browser environments

## 3.0.0 (December 13, 2021)

Expand Down
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
"module": "./lib/index.js",
"exports": {
".": {
"browser": {
"import": "./lib/bundle.js",
"require": "./cjs/bundle.cjs"
},
"import": "./lib/index.js",
"require": "./cjs/index.cjs"
},
Expand All @@ -27,6 +31,8 @@
"unpkg": "dist/csstree-validator.esm.js",
"jsdelivr": "dist/csstree-validator.esm.js",
"browser": {
"./cjs/index.cjs": "./cjs/bundle.cjs",
"./lib/index.js": "./lib/bundle.js",
"./cjs/version.cjs": "./dist/version.cjs",
"./lib/version.js": "./dist/version.js"
},
Expand Down
6 changes: 3 additions & 3 deletions scripts/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const { version } = createRequire(import.meta.url)('../package.json');
async function build() {
const genModules = {
'version.js': `export const version = "${version}";`,
'version.cjs': `module.exports = "${version}";`
'version.cjs': `exports.version = "${version}";`
};
const genModulesFilter = new RegExp('lib[\\\\/](' + Object.keys(genModules).join('|').replace(/\./g, '\\.') + ')$');
const plugins = [{
Expand All @@ -22,7 +22,7 @@ async function build() {

await Promise.all([
esbuild.build({
entryPoints: ['lib/validate.js'],
entryPoints: ['lib/bundle.js'],
outfile: 'dist/csstree-validator.js',
format: 'iife',
globalName: 'csstreeValidator',
Expand All @@ -33,7 +33,7 @@ async function build() {
}),

esbuild.build({
entryPoints: ['lib/validate.js'],
entryPoints: ['lib/bundle.js'],
outfile: 'dist/csstree-validator.esm.js',
format: 'esm',
bundle: true,
Expand Down

0 comments on commit 0ef00a7

Please # to comment.