Skip to content

Commit

Permalink
Update way to build demo and add comments for different App*.vue vers…
Browse files Browse the repository at this point in the history
…ions
  • Loading branch information
julienbourdeau committed Dec 28, 2024
1 parent b0c0bb6 commit 0dabbe9
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 22 deletions.
3 changes: 3 additions & 0 deletions build_client.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@

rm -rf client/dist
(cd client && npm run build)

echo
echo " -> Copying new assets version to public/debugbar.js"
cp client/dist/assets/debugbar-*.js public/debugbar.js
7 changes: 6 additions & 1 deletion build_demo.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
#!/bin/bash

ruby ./build_fixtures.rb

rm -rf client/dist-demo
(cd client/ && VITE_DEMO_MODE=true npm run build)
(cd client/ && npm run build:demo)

if [ -d "../debugbar.dev/source/assets/debugbar" ]; then
echo
echo "debugbar.dev found in parent directory"
echo " -> Copying assets"
rm -f ../debugbar.dev/source/assets/debugbar/*
cp ./client/dist-demo/assets/* ../debugbar.dev/source/assets/debugbar/
else
echo "####################################################"
echo "## debugbar.dev was NOT FOUND in parent directory ##"
echo "####################################################"
fi
2 changes: 1 addition & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"dev": "vite",
"build": "vue-tsc && vite build",
"preview": "vite preview"
"build:demo": "vue-tsc && vite build -c vite.demo.config.ts"
},
"dependencies": {
"@heroicons/vue": "^2.1.1",
Expand Down
4 changes: 4 additions & 0 deletions client/src/App.vue
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
<!-- This is the component used the build the final production assets. -->
<!-- It's primary used to load the app in the shadow DOM -->
<!-- See vite.config.ts and other App*.vue for details -->

<script setup lang="ts">
import Debugbar from "@/Debugbar.vue"
import { ShadowRoot, ShadowStyle } from "vue-shadow-dom"
Expand Down
6 changes: 6 additions & 0 deletions client/src/AppDemo.vue
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
<!-- This file is used when building the demo assets. -->
<!-- The demo is a self-contained version of the app with fixtures. It's meant to be displayed on debugbar.dev -->
<!-- The demo is built with `./build_demo.sh` which build the assets with the `vite.demo.config.ts` (via `npm run build:demo`) -->
<!-- The dedicated config allows is to have sourcemap and vite devtools. -->
<!-- This component load fixturs onMounted and show the app in a shadow DOM. -->

<script setup lang="ts">
import Debugbar from "@/Debugbar.vue"
import { ShadowRoot, ShadowStyle } from "vue-shadow-dom"
Expand Down
6 changes: 6 additions & 0 deletions client/src/AppDev.vue
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
<!-- This file is used when developing the frontend. -->
<!-- ./index.html will load `dev.ts` which build the app with this AppDev.vue component. -->
<!-- This component makes pre-registered calls to a rails backend to load data so you can edit -->
<!-- the app and with HMR, you never have leave the page. -->
<!-- Use with `npm run dev` and open http://localhost:5173/ -->

<script setup lang="ts">
import Debugbar from "@/Debugbar.vue"
import { onMounted } from "vue"
Expand Down
3 changes: 3 additions & 0 deletions client/src/Debugbar.vue
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<!-- This is the main component of the debugbar. -->
<!--It's imported in the different App*.vue components.-->

<script setup lang="ts">
import { createConsumer } from "@rails/actioncable"
import { computed, onMounted, reactive, ref } from "vue"
Expand Down
2 changes: 1 addition & 1 deletion client/tsconfig.node.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
"moduleResolution": "bundler",
"allowSyntheticDefaultImports": true
},
"include": ["vite.config.ts"]
"include": ["vite.config.ts", "vite.demo.config.ts"]
}
24 changes: 5 additions & 19 deletions client/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,13 @@ import { fileURLToPath, URL } from "node:url"

import { defineConfig } from "vite"
import vue from "@vitejs/plugin-vue"
import { resolve } from "path"

const entryFile = process.env.VITE_DEMO_MODE ? "./src/demo.ts" : "./src/main.ts"

const currentConfig = {
entry: resolve(__dirname, entryFile),
fileName: "debugbar.js",
}

const isNotReallyProd = () => {
if (process.env.VITE_DEMO_MODE && process.env.NODE_ENV === "production") {
return true
}

return process.env.NODE_ENV != "production"
}
const isNotProd = () => process.env.NODE_ENV != "production"

// https://vitejs.dev/config/
export default defineConfig({
define: {
__VUE_PROD_DEVTOOLS__: isNotReallyProd(),
__VUE_PROD_DEVTOOLS__: isNotProd(),
},
plugins: [
vue({
Expand All @@ -42,12 +28,12 @@ export default defineConfig({
},
build: {
manifest: true,
sourcemap: isNotReallyProd(),
sourcemap: isNotProd(),
emptyOutDir: false,
outDir: process.env.VITE_DEMO_MODE ? "./dist-demo" : "./dist",
outDir: "./dist",
rollupOptions: {
input: {
debugbar: fileURLToPath(new URL(entryFile, import.meta.url)),
debugbar: fileURLToPath(new URL("./src/main.ts", import.meta.url)),
},
},
},
Expand Down
38 changes: 38 additions & 0 deletions client/vite.demo.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { fileURLToPath, URL } from "node:url"

import { defineConfig } from "vite"
import vue from "@vitejs/plugin-vue"

// https://vitejs.dev/config/
export default defineConfig({
define: {
__VUE_PROD_DEVTOOLS__: true, // nice for demo mode
},
plugins: [
vue({
template: {
compilerOptions: {
// This is because I embed the ruby logo SVG as a vue component.
// There is probably a better way.
isCustomElement: (tag) => tag.includes(":"),
},
},
}),
],
resolve: {
alias: {
"@": fileURLToPath(new URL("./src", import.meta.url)),
},
},
build: {
manifest: true,
sourcemap: true, // very nice for demo mode
emptyOutDir: false,
outDir: "./dist-demo",
rollupOptions: {
input: {
debugbar: fileURLToPath(new URL("./src/demo.ts", import.meta.url)),
},
},
},
})

0 comments on commit 0dabbe9

Please sign in to comment.