Skip to content

Commit

Permalink
fix(vite+overlay): using mjs overlay bundle for vite plugin (#408)
Browse files Browse the repository at this point in the history
Co-authored-by: arlo <[email protected]>
  • Loading branch information
alexzhang1030 and webfansplz authored Jun 5, 2024
1 parent f138c20 commit 2b4fbd2
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 8 deletions.
19 changes: 19 additions & 0 deletions packages/overlay/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,32 @@ export default defineConfig({
async closeBundle() {
// copy
const overlayFile = resolve(__dirname, './dist')

const overlayJsFile = resolve(__dirname, './dist/devtools-overlay.js')
const overlayMjsFile = resolve(__dirname, './dist/devtools-overlay.mjs')

fse.copyFileSync(overlayJsFile, overlayMjsFile)

// Browser extension keep using js file
fse.copySync(
overlayFile,
resolve(__dirname, '../browser-extension/overlay'),
{
filter: (file) => {
return !file.endsWith('.mjs')
},
},
)

// Vite using mjs file to skip some commonjs -> es6 plugins
fse.copySync(
overlayFile,
resolve(__dirname, '../vite/src/overlay'),
{
filter: (file) => {
return !file.endsWith('.js')
},
},
)
},
},
Expand Down
1 change: 1 addition & 0 deletions packages/playground/basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"vuex": "^4.1.0"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^25.0.8",
"@tanstack/vue-query-devtools": "^5.38.0",
"@vitejs/plugin-vue": "^5.0.4",
"@vue/devtools": "workspace:^",
Expand Down
5 changes: 4 additions & 1 deletion packages/playground/basic/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import VueDevTools from 'vite-plugin-vue-devtools'

import commonjs from '@rollup/plugin-commonjs'
import Unocss from 'unocss/vite'
import AutoImport from 'unplugin-auto-import/vite'
import inspect from 'vite-plugin-inspect'

// https://vitejs.dev/config/
export default defineConfig({
plugins: [
vue(),
commonjs(),
VueDevTools({
launchEditor: 'code',
}),
Expand All @@ -20,6 +22,7 @@ export default defineConfig({
'@vueuse/core',
],
}),
inspect(),
],
server: {
port: 3000,
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/overlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ link.href = `${overlayDir}/devtools-overlay.css`

// create script
const script = document.createElement('script')
script.src = `${overlayDir}/devtools-overlay.js`
script.src = `${overlayDir}/devtools-overlay.mjs`
script.type = 'module'

// append to head
Expand Down
26 changes: 20 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2b4fbd2

Please sign in to comment.