From 8f2b7e7e334195956723cb295a277d3ed17fb0e4 Mon Sep 17 00:00:00 2001 From: Prev Wong Date: Fri, 26 Jul 2024 16:40:52 +0800 Subject: [PATCH] chore: rollup config Inject Craft package version and export sourcemaps --- .changeset/fast-tigers-jump.md | 7 +++++++ packages/core/.npmignore | 3 ++- packages/core/package.json | 3 +++ packages/layers/.npmignore | 3 ++- packages/layers/package.json | 3 +++ packages/utils/.npmignore | 3 ++- packages/utils/package.json | 3 +++ rollup.config.js | 18 ++++++++++++++++++ tsconfig.json | 1 + 9 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 .changeset/fast-tigers-jump.md diff --git a/.changeset/fast-tigers-jump.md b/.changeset/fast-tigers-jump.md new file mode 100644 index 000000000..b3f7b998b --- /dev/null +++ b/.changeset/fast-tigers-jump.md @@ -0,0 +1,7 @@ +--- +'@craftjs/core': patch +'@craftjs/layers': patch +'@craftjs/utils': patch +--- + +Inject Craft package version and export sourcemaps diff --git a/packages/core/.npmignore b/packages/core/.npmignore index a2fc6a34f..439d8afe7 100644 --- a/packages/core/.npmignore +++ b/packages/core/.npmignore @@ -1,4 +1,5 @@ src rollup.config.js tsconfig.json -nodemon.json \ No newline at end of file +nodemon.json +.rollup.cache \ No newline at end of file diff --git a/packages/core/package.json b/packages/core/package.json index 5f8bfc892..41e5c6ce0 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -21,6 +21,9 @@ "main": "./dist/cjs/index.js", "module": "./dist/esm/index.js", "types": "./lib/index.d.ts", + "files": [ + "dist" + ], "repository": { "type": "git", "url": "https://github.com/prevwong/craft.js/" diff --git a/packages/layers/.npmignore b/packages/layers/.npmignore index 0fdfc98d6..94579d8b4 100644 --- a/packages/layers/.npmignore +++ b/packages/layers/.npmignore @@ -1,3 +1,4 @@ src rollup.config.js -tsconfig.json \ No newline at end of file +tsconfig.json +.rollup.cache \ No newline at end of file diff --git a/packages/layers/package.json b/packages/layers/package.json index 434715d60..765af60b5 100644 --- a/packages/layers/package.json +++ b/packages/layers/package.json @@ -17,6 +17,9 @@ "module": "./dist/esm/index.js", "license": "MIT", "types": "./lib/index.d.ts", + "files": [ + "dist" + ], "scripts": { "start": "cross-env NODE_ENV=development ../../scripts/build.sh", "build": "cross-env NODE_ENV=production ../../scripts/build.sh", diff --git a/packages/utils/.npmignore b/packages/utils/.npmignore index a2fc6a34f..439d8afe7 100644 --- a/packages/utils/.npmignore +++ b/packages/utils/.npmignore @@ -1,4 +1,5 @@ src rollup.config.js tsconfig.json -nodemon.json \ No newline at end of file +nodemon.json +.rollup.cache \ No newline at end of file diff --git a/packages/utils/package.json b/packages/utils/package.json index cb133601f..f8a2d0fee 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -7,6 +7,9 @@ "main": "./dist/cjs/index.js", "module": "./dist/esm/index.js", "types": "./lib/index.d.ts", + "files": [ + "dist" + ], "scripts": { "start": "cross-env NODE_ENV=development ../../scripts/build.sh", "build": "cross-env NODE_ENV=production ../../scripts/build.sh", diff --git a/rollup.config.js b/rollup.config.js index 31f1bbaca..d92249a29 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -8,20 +8,38 @@ import typescript from '@rollup/plugin-typescript'; const shouldMinify = process.env.NODE_ENV === 'production'; const bundle = ['tslib']; +const injectPackageVersion = () => { + const pkg = require('./package.json'); + + return ` +if ( typeof window !== 'undefined' ) { + if ( !window['__CRAFTJS__'] ) { + window['__CRAFTJS__'] = {}; + } + + window['__CRAFTJS__']["${pkg.name}"] = "${pkg.version}"; +} + `; +}; + export default { input: './src/index.ts', output: [ { file: 'dist/esm/index.js', format: 'esm', + intro: injectPackageVersion(), globals: { react: 'React', 'react-dom': 'ReactDOM', }, + sourcemap: true, }, { file: 'dist/cjs/index.js', + intro: injectPackageVersion(), format: 'cjs', + sourcemap: true, }, ], external: (id) => { diff --git a/tsconfig.json b/tsconfig.json index 6b9bc3920..db6bbbbae 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,6 +5,7 @@ "allowSyntheticDefaultImports": true, "allowJs": true, "esModuleInterop": true, + "sourceMap": true, "paths": { "@craftjs/core": ["packages/core/src/index"], "@craftjs/*": ["packages/core/src/*"],