extract vue from main chunk
This commit is contained in:
parent
fd2e3f2c1b
commit
a886935b12
@ -1,15 +1,12 @@
|
||||
import Vue from 'vue'
|
||||
import * as React from 'react'
|
||||
import ReactDOM from 'react-dom'
|
||||
import './scripts/app'
|
||||
import routes from './scripts/route'
|
||||
import * as emitter from './scripts/event'
|
||||
|
||||
Vue.config.productionTip = false
|
||||
|
||||
loadModules()
|
||||
|
||||
function loadModules() {
|
||||
async function loadModules() {
|
||||
if (blessing.route.startsWith('admin')) {
|
||||
const entry = document.querySelector<HTMLAnchorElement>('#launch-cli')
|
||||
entry?.addEventListener('click', async () => {
|
||||
@ -44,6 +41,9 @@ function loadModules() {
|
||||
})
|
||||
}
|
||||
if (route.component) {
|
||||
const { default: Vue } = await import('vue')
|
||||
const { default: inject } = await import('./scripts/injectVue')
|
||||
inject(Vue)
|
||||
Vue.prototype.$route = new RegExp(`^${route.path}$`, 'i').exec(
|
||||
blessing.route,
|
||||
)
|
||||
|
@ -1,5 +1,3 @@
|
||||
import Vue from 'vue'
|
||||
|
||||
export function trans(key: string, parameters = Object.create(null)): string {
|
||||
const segments = key.split('.')
|
||||
let temp = (blessing.i18n) as {
|
||||
@ -27,23 +25,4 @@ export function trans(key: string, parameters = Object.create(null)): string {
|
||||
|
||||
export const t = trans
|
||||
|
||||
Vue.use(_Vue => {
|
||||
// eslint-disable-next-line @typescript-eslint/unbound-method
|
||||
_Vue.prototype.$t = trans
|
||||
_Vue.directive('t', (el, { value }) => {
|
||||
if (typeof value === 'string') {
|
||||
el.textContent = trans(value)
|
||||
} else if (typeof value === 'object') {
|
||||
el.textContent = trans(value.path, value.args)
|
||||
} else {
|
||||
/* istanbul ignore next */
|
||||
// eslint-disable-next-line no-lonely-if
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
// eslint-disable-next-line no-console
|
||||
console.warn('[i18n] Invalid arguments in `v-t` directive.')
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
Object.assign(window, { trans })
|
||||
|
42
resources/assets/src/scripts/injectVue.ts
Normal file
42
resources/assets/src/scripts/injectVue.ts
Normal file
@ -0,0 +1,42 @@
|
||||
import type { VueConstructor } from 'vue'
|
||||
import { t } from './i18n'
|
||||
import * as fetch from './net'
|
||||
|
||||
export default function (Vue: VueConstructor) {
|
||||
injectI18n(Vue)
|
||||
injectFetch(Vue)
|
||||
}
|
||||
|
||||
function injectI18n(Vue: VueConstructor) {
|
||||
Vue.use((_Vue) => {
|
||||
// eslint-disable-next-line @typescript-eslint/unbound-method
|
||||
_Vue.prototype.$t = t
|
||||
_Vue.directive('t', (el, { value }) => {
|
||||
if (typeof value === 'string') {
|
||||
el.textContent = t(value)
|
||||
} else if (typeof value === 'object') {
|
||||
el.textContent = t(value.path, value.args)
|
||||
} else {
|
||||
/* istanbul ignore next */
|
||||
// eslint-disable-next-line no-lonely-if
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
// eslint-disable-next-line no-console
|
||||
console.warn('[i18n] Invalid arguments in `v-t` directive.')
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function injectFetch(Vue: VueConstructor) {
|
||||
Vue.use((_Vue) => {
|
||||
Object.defineProperty(_Vue.prototype, '$http', {
|
||||
get: () => ({
|
||||
get: fetch.get,
|
||||
post: fetch.post,
|
||||
put: fetch.put,
|
||||
del: fetch.del,
|
||||
}),
|
||||
})
|
||||
})
|
||||
}
|
@ -1,4 +1,3 @@
|
||||
import Vue from 'vue'
|
||||
import { emit } from './event'
|
||||
import { showModal } from './notify'
|
||||
import { trans, t } from './i18n'
|
||||
@ -144,17 +143,6 @@ export function del<T = any>(url: string, data = empty): Promise<T> {
|
||||
return nonGet<T>('DELETE', url, data)
|
||||
}
|
||||
|
||||
Vue.use(_Vue => {
|
||||
Object.defineProperty(_Vue.prototype, '$http', {
|
||||
get: () => ({
|
||||
get,
|
||||
post,
|
||||
put,
|
||||
del,
|
||||
}),
|
||||
})
|
||||
})
|
||||
|
||||
blessing.fetch = {
|
||||
get,
|
||||
post,
|
||||
|
Loading…
Reference in New Issue
Block a user