Skip to content

Commit

Permalink
fix: Vite: faster builds & fewer dependencies
Browse files Browse the repository at this point in the history
Use Vite instead of Webpack!
  • Loading branch information
billyc committed Dec 1, 2021
1 parent e480798 commit a4d92c0
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 16 deletions.
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
"name": "simwrapper",
"version": "1.1.0",
"private": true,
"license": "GPL-3.0-or-later",
"author": "Billy Charlton <charlton@tu-berlin.de>",
"contributors": [
"Friedrich Voelkers <friedrich.k.voelkers@tu-berlin.de>",
"Janek Laudan <laudan@vsp.tu-berlin.de>"
],
"scripts": {
"serve": "vite",
"build": "vite build",
Expand Down
4 changes: 3 additions & 1 deletion src/components/RunFinderPanel.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template lang="pug">
.run-finder-panel
router-link.logo(:to="'/'")
router-link.logo(:to="baseURL")
img(src="@/assets/simwrapper-logo/SW_logo_icon_white.png")
h3 {{globalState.app }}

Expand Down Expand Up @@ -64,6 +64,8 @@ class MyComponent extends Vue {
private rootNodes: any[] = []
private baseURL = import.meta.env.BASE_URL
private mounted() {
// start the run finder process
runFinder.findRuns()
Expand Down
8 changes: 7 additions & 1 deletion src/js/DashboardDataManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,13 @@ export default class DashboardDataManager {
}

public removeFilterListener(config: { dataset: string }, listener: any) {
this.datasets[config.dataset].filterListeners.delete(listener)
try {
if (this.datasets[config.dataset].filterListeners) {
this.datasets[config.dataset].filterListeners.delete(listener)
}
} catch (e) {
// doesn't matter
}
}

public clearCache() {
Expand Down
17 changes: 12 additions & 5 deletions src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,24 @@ import globalStore from '@/store'

Vue.use(VueRouter)

const BASE = import.meta.env.BASE_URL

const routes = [
{
path: '/gist/:id',
path: BASE + 'gist/:id',
component: () => import(/* webpackChunkName: "gist" */ '@/views/GistView.vue'),
props: (route: Route) => ({
id: route.params.id,
}),
},
{
path: '/*',
path: BASE + '*',
component: () => import(/* webpackChunkName: "split" */ '@/views/ScreenSplitter.vue'),
},
{
// catch-all back to home page
path: '*',
redirect: '/',
redirect: BASE,
},
]

Expand All @@ -29,7 +31,7 @@ function vizPlugins(): any[] {
const plugins = []
for (const plugin of globalStore.state.visualizationTypes.values()) {
plugins.push({
path: '/v/' + plugin.kebabName + '/:slug/*',
path: BASE + 'v/' + plugin.kebabName + '/:slug/*',
name: plugin.kebabName,
component: plugin.component,
props: (route: Route) => {
Expand All @@ -51,7 +53,7 @@ function vizPlugins(): any[] {

const router = new VueRouter({
mode: 'history',
base: process.env.BASE_URL,
base: '/',
routes: vizPlugins().concat(routes),
// native-like back/forward and top-of-page routing
scrollBehavior(to, from, savedPosition) {
Expand All @@ -63,4 +65,9 @@ const router = new VueRouter({
},
})

// router.beforeEach((to, from, next) => {
// console.log(to.path)
// next()
// })

export default router
1 change: 0 additions & 1 deletion src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ export default new Vuex.Store({
setLocale(state: GlobalState, value: string) {
state.locale = value.toLocaleLowerCase()
localStorage.setItem('locale', state.locale)
console.log('NEW LOCALE:', state.locale)
},
},

Expand Down
1 change: 0 additions & 1 deletion src/templates/BlankDeckFrame.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ de:
<script lang="ts">
import { Vue, Component, Prop, Watch } from 'vue-property-decorator'
import YAML from 'yaml'
import { spawn, Worker, Thread, ModuleThread } from 'threads'
import util from '@/js/util'
import globalStore from '@/store'
Expand Down
12 changes: 8 additions & 4 deletions src/views/ScreenSplitter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ import SplashPage from '@/views/SplashPage.vue'
class MyComponent extends Vue {
// the calls to $forceUpdate() below are because Vue does not watch deep array contents.
private baseURL = import.meta.env.BASE_URL
private panels = [
{
component: 'SplashPage',
Expand All @@ -64,7 +66,7 @@ class MyComponent extends Vue {
}
@Watch('$route') routeChanged(to: Route, from: Route) {
if (to.path === '/') {
if (to.path === this.baseURL) {
// root node is not a normal splitpane, so we instead replace
// with a brand new clean startpage.
this.panels = [
Expand Down Expand Up @@ -162,20 +164,22 @@ class MyComponent extends Vue {
private updateURL() {
// console.log(this.panels)
const BASE = import.meta.env.BASE_URL
if (this.panels.length === 1) {
const root = this.panels[0].props.root || ''
const xsubfolder = this.panels[0].props.xsubfolder || ''
const yaml = this.panels[0].props.yamlConfig || ''
if (yaml) {
const base64 = btoa(JSON.stringify(this.panels))
this.$router.push(`/split/${base64}`)
this.$router.push(`${BASE}split/${base64}`)
} else {
this.$router.push(`/${root}/${xsubfolder}`)
this.$router.push(`${BASE}${root}/${xsubfolder}`)
}
} else {
const base64 = btoa(JSON.stringify(this.panels))
this.$router.push(`/split/${base64}`)
this.$router.push(`${BASE}split/${base64}`)
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ import { createVuePlugin } from 'vite-plugin-vue2'
import markdownPlugin from 'vite-plugin-md'

export default defineConfig({
// base: '/',
// publicDir: '/simwrapper/',
base: '/simwrapper/',
build: { sourcemap: true },
plugins: [
// vue
createVuePlugin({ include: [/\.vue$/, /\.md$/] }),
markdownPlugin(),
],
build: { sourcemap: true },
resolve: {
alias: {
'@': '/src',
Expand All @@ -25,4 +24,5 @@ export default defineConfig({
// requireFromFile: null,
// requireFromString: null,
},
// optimizeDeps: { exclude: ['@deck.gl/layers'] },
})

0 comments on commit a4d92c0

Please sign in to comment.