Skip to content

Commit

Permalink
chore: inject code: window.omi = window.Omi
Browse files Browse the repository at this point in the history
  • Loading branch information
dntzhang committed Oct 19, 2023
1 parent 8baaeea commit 4e04f18
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/omi/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
43 changes: 43 additions & 0 deletions packages/omi/post-build.js
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion packages/omi/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'


0 comments on commit 4e04f18

Please sign in to comment.