From 4e04f185118f7fe38b2a26c3265980ade90b2dc7 Mon Sep 17 00:00:00 2001 From: dntzhang Date: Thu, 19 Oct 2023 16:59:31 +0800 Subject: [PATCH] chore: inject code: window.omi = window.Omi --- packages/omi/package.json | 4 ++-- packages/omi/post-build.js | 43 ++++++++++++++++++++++++++++++++++++++ packages/omi/src/index.ts | 2 +- 3 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 packages/omi/post-build.js diff --git a/packages/omi/package.json b/packages/omi/package.json index 1f8c8fe974..7aaec7dd3f 100644 --- a/packages/omi/package.json +++ b/packages/omi/package.json @@ -1,12 +1,12 @@ { "name": "omi", - "version": "7.1.4", + "version": "7.1.5", "scripts": { "start": "vite", "dev-vite": "vite", "build-vite": "vite build", "build-vite:w": "vite build --watch", - "build": "microbundle --name Omi", + "build": "microbundle --name Omi && node post-build.js", "dev": "microbundle watch", "server": "live-server ./build --watch", "preview": "vite preview", diff --git a/packages/omi/post-build.js b/packages/omi/post-build.js new file mode 100644 index 0000000000..70c4cb7923 --- /dev/null +++ b/packages/omi/post-build.js @@ -0,0 +1,43 @@ +import * as fs from 'fs' + +const outputFile = 'dist/omi.umd.js' +const customCode = `if(typeof window!=='undefined'){window.omi=window.Omi};` + +fs.readFile(outputFile, 'utf8', (err, data) => { + if (err) { + console.error('Error reading file:', err) + return + } + + const sourceMappingIndex = data.lastIndexOf('//# sourceMappingURL=omi.umd.js.map') + const updatedData = [ + data.slice(0, sourceMappingIndex), + customCode, + '\n', + data.slice(sourceMappingIndex), + ].join('') + + fs.writeFile(outputFile, updatedData, 'utf8', (err) => { + if (err) { + console.error('Error writing file:', err) + return + } + console.log('Custom code injected successfully!') + }) +}) + +const noop = () => { } +fs.unlink('class.d.ts', noop) +fs.unlink('component.d.ts', noop) +fs.unlink('constants.d.ts', noop) +fs.unlink('construct-style-sheets-polyfill.d.ts', noop) +fs.unlink('css-tag.d.ts', noop) +fs.unlink('define.d.ts', noop) +fs.unlink('diff.d.ts', noop) +fs.unlink('dom.d.ts', noop) +fs.unlink('index.d.ts', noop) +fs.unlink('reactivity.d.ts', noop) +fs.unlink('render.d.ts', noop) +fs.unlink('signal.d.ts', noop) +fs.unlink('utils.d.ts', noop) +fs.unlink('vdom.d.ts', noop) \ No newline at end of file diff --git a/packages/omi/src/index.ts b/packages/omi/src/index.ts index e76298e839..605e307141 100644 --- a/packages/omi/src/index.ts +++ b/packages/omi/src/index.ts @@ -7,6 +7,6 @@ export { createRef, bind } from './utils' export { signal, computed, effect, batch, setActiveComponent, getActiveComponent } from './reactivity' export { Signal } from './signal' export { css } from './css-tag' -export const version = '7.1.4' +export const version = '7.1.5'