Merge pull request #517 from YunoHost/tool-vite

Switch from vue-cli to vite
This commit is contained in:
Alexandre Aubin 2023-04-04 13:21:48 +02:00 committed by GitHub
commit c2cba173b8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
31 changed files with 464 additions and 7391 deletions

View file

@ -1,6 +1,7 @@
module.exports = {
root: true,
env: {
es2021: true,
node: true
},
extends: [
@ -8,9 +9,6 @@ module.exports = {
'eslint:recommended',
'standard'
],
parserOptions: {
parser: '@babel/eslint-parser'
},
rules: {
'vue/max-attributes-per-line': [
'error',

View file

@ -1,5 +0,0 @@
module.exports = {
presets: [
'@vue/cli-plugin-babel/preset'
]
}

View file

@ -6,14 +6,14 @@
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<meta name="format-detection" content="telephone=no" />
<meta name="robots" content="noindex, nofollow">
<link rel="icon" href="<%= BASE_URL %>favicon.png">
<link rel="icon" href="/favicon.png">
<title>YunoHost Admin</title>
</head>
<body>
<noscript>
<strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
<strong>We're sorry but YunoHost Admin doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
</noscript>
<div id="app"></div>
<!-- built files will be auto injected -->
<script type="module" src="/src/main.js"></script>
</body>
</html>

7474
app/package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -5,17 +5,15 @@
"description": "YunoHost Admin web interface",
"author": "Yunohost",
"scripts": {
"serve": "./node_modules/@vue/cli-service/bin/vue-cli-service.js serve",
"build": "./node_modules/@vue/cli-service/bin/vue-cli-service.js build",
"lint": "./node_modules/@vue/cli-service/bin/vue-cli-service.js lint --no-fix",
"i18n": "./node_modules/@vue/cli-service/bin/vue-cli-service.js i18n:report --src './src/**/*.?(js|vue)' --locales './src/i18n/locales/*.json'",
"i18n:en": "./node_modules/@vue/cli-service/bin/vue-cli-service.js i18n:report --src './src/**/*.?(js|vue)' --locales './src/i18n/locales/en.json'"
"dev": "vite",
"build": "vite build",
"lint": "eslint --ext .js,.vue src",
"lint-fix": "lint --fix"
},
"dependencies": {
"@fontsource/fira-code": "^4.5.13",
"@fontsource/firago": "^4.5.3",
"bootstrap-vue": "^2.22.0",
"core-js": "^3.29.1",
"date-fns": "^2.29.3",
"fork-awesome": "^1.2.0",
"simple-evaluate": "^1.4.6",
@ -27,23 +25,15 @@
"vuex": "^3.6.2"
},
"devDependencies": {
"@babel/eslint-parser": "^7.21.3",
"@vue/cli-plugin-babel": "^5.0.8",
"@vue/cli-plugin-eslint": "^5.0.8",
"@vue/cli-plugin-router": "^5.0.8",
"@vue/cli-plugin-vuex": "^5.0.8",
"@vue/cli-service": "^5.0.8",
"@vitejs/plugin-vue2": "^2.2.0",
"bootstrap": "^4.6.0",
"eslint": "^8.36.0",
"eslint-plugin-vue": "^9.10.0",
"popper.js": "^1.16.0",
"portal-vue": "^2.1.7",
"sass": "^1.60.0",
"sass-loader": "^13.2.1",
"sass-resources-loader": "^2.2.5",
"standard": "^17.0.0",
"vue-cli-plugin-bootstrap-vue": "^0.8.2",
"vue-cli-plugin-i18n": "^2.3.1"
"vite": "^4.2.1"
},
"browserslist": [
"> 1%",

View file

@ -78,10 +78,7 @@ export async function handleError (request, response, errorData) {
* @param {APIError} error
*/
export function onUnhandledAPIError (error) {
// In 'development', Babel seems to also catch the error so there's no need to log it twice.
if (process.env.NODE_ENV !== 'development') {
error.log()
}
error.log()
store.dispatch('HANDLE_ERROR', error)
}

View file

@ -1,3 +1,12 @@
// helper module to expose custom and vuelidate validators.
export * from './customValidators'
export * from 'vuelidate/lib/validators'
export {
between,
helpers,
integer,
maxValue,
minLength,
minValue,
required,
sameAs
} from 'vuelidate/lib/validators'

View file

@ -49,9 +49,7 @@ function loadLocaleMessages (locale) {
if (loadedLanguages.includes(locale)) {
return Promise.resolve(locale)
}
return import(
/* webpackChunkName: "lc/lang-[request]" */ `@/i18n/locales/${locale}`
).then(messages => {
return import(`@/i18n/locales/${locale}.json`).then(messages => {
i18n.setLocaleMessage(locale, messages.default)
loadedLanguages.push(locale)
return locale
@ -63,12 +61,9 @@ function loadLocaleMessages (locale) {
*/
async function loadDateFnsLocale (locale) {
const dateFnsLocaleName = supportedLocales[locale].dateFnsLocale || locale
return import(
/* webpackChunkName: "lc/datefns-[request]" */
`date-fns/locale/${dateFnsLocaleName}/index.js`
).then(locale => {
dateFnsLocale = locale.default
})
dateFnsLocale = (await import(
`../../node_modules/date-fns/esm/locale/${dateFnsLocaleName}/index.js`
)).default
}
/**

View file

@ -54,12 +54,12 @@ Vue.prototype.$askMdConfirmation = function (markdown, props, ok = false) {
}
// Register global components
const requireComponent = require.context('@/components/globals', true, /\.(js|vue)$/i)
// For each matching file name...
requireComponent.keys().forEach((fileName) => {
// Get the component
const component = requireComponent(fileName).default
// Globally register the component
const globalComponentsModules = import.meta.glob([
'@/components/globals/*.vue',
'@/components/globals/*/*.vue'
], { eager: true })
Object.values(globalComponentsModules).forEach((module) => {
const component = module.default
Vue.component(component.name, component)
})

View file

@ -7,7 +7,7 @@ Vue.use(VueRouter)
const router = new VueRouter({
// mode: 'history', // this allow all routes to be real ones (without '#')
base: process.env.BASE_URL,
base: import.meta.env.BASE_URL,
routes,
scrollBehavior (to, from, savedPosition) {

View file

@ -6,11 +6,11 @@
// Simple views are normally imported and will be included into the main webpack entry.
// Others will be chunked by webpack so they can be lazy loaded.
// Webpack chunk syntax is:
// `() => import(/* webpackChunkName: "views/:nameOfWantedFile" */ '@/views/:ViewComponent')`
// `() => import('@/views/:ViewComponent.vue')`
import Home from '@/views/Home'
import Login from '@/views/Login'
import ToolList from '@/views/tool/ToolList'
import Home from '@/views/Home.vue'
import Login from '@/views/Login.vue'
import ToolList from '@/views/tool/ToolList.vue'
const routes = [
{
@ -38,7 +38,7 @@ const routes = [
{
name: 'post-install',
path: '/postinstall',
component: () => import(/* webpackChunkName: "views/post-install" */ '@/views/PostInstall'),
component: () => import('@/views/PostInstall.vue'),
meta: {
noAuth: true,
args: { trad: 'postinstall.title' }
@ -51,7 +51,7 @@ const routes = [
{
name: 'user-list',
path: '/users',
component: () => import(/* webpackChunkName: "views/user/list" */ '@/views/user/UserList'),
component: () => import('@/views/user/UserList.vue'),
meta: {
args: { trad: 'users' },
breadcrumb: ['user-list']
@ -60,7 +60,7 @@ const routes = [
{
name: 'user-create',
path: '/users/create',
component: () => import(/* webpackChunkName: "views/user/create" */ '@/views/user/UserCreate'),
component: () => import('@/views/user/UserCreate.vue'),
meta: {
args: { trad: 'users_new' },
breadcrumb: ['user-list', 'user-create']
@ -69,7 +69,7 @@ const routes = [
{
name: 'user-import',
path: '/users/import',
component: () => import(/* webpackChunkName: "views/user/import" */ '@/views/user/UserImport'),
component: () => import('@/views/user/UserImport.vue'),
props: true,
meta: {
args: { trad: 'users_import' },
@ -79,7 +79,7 @@ const routes = [
{
name: 'user-info',
path: '/users/:name',
component: () => import(/* webpackChunkName: "views/user/info" */ '@/views/user/UserInfo'),
component: () => import('@/views/user/UserInfo.vue'),
props: true,
meta: {
args: { param: 'name' },
@ -89,7 +89,7 @@ const routes = [
{
name: 'user-edit',
path: '/users/:name/edit',
component: () => import(/* webpackChunkName: "views/user/edit" */ '@/views/user/UserEdit'),
component: () => import('@/views/user/UserEdit.vue'),
props: true,
meta: {
args: { param: 'name', trad: 'user_username_edit' },
@ -103,7 +103,7 @@ const routes = [
{
name: 'group-list',
path: '/groups',
component: () => import(/* webpackChunkName: "views/group/list" */ '@/views/group/GroupList'),
component: () => import('@/views/group/GroupList.vue'),
meta: {
args: { trad: 'groups_and_permissions' },
breadcrumb: ['user-list', 'group-list']
@ -112,7 +112,7 @@ const routes = [
{
name: 'group-create',
path: '/groups/create',
component: () => import(/* webpackChunkName: "views/group/create" */ '@/views/group/GroupCreate'),
component: () => import('@/views/group/GroupCreate.vue'),
meta: {
args: { trad: 'group_new' },
breadcrumb: ['user-list', 'group-list', 'group-create']
@ -125,7 +125,7 @@ const routes = [
{
name: 'domain-list',
path: '/domains',
component: () => import(/* webpackChunkName: "views/domain/list" */ '@/views/domain/DomainList'),
component: () => import('@/views/domain/DomainList.vue'),
meta: {
args: { trad: 'domains' },
breadcrumb: ['domain-list']
@ -134,7 +134,7 @@ const routes = [
{
name: 'domain-add',
path: '/domains/add',
component: () => import(/* webpackChunkName: "views/domain/add" */ '@/views/domain/DomainAdd'),
component: () => import('@/views/domain/DomainAdd.vue'),
meta: {
args: { trad: 'domain_add' },
breadcrumb: ['domain-list', 'domain-add']
@ -142,13 +142,13 @@ const routes = [
},
{
path: '/domains/:name',
component: () => import(/* webpackChunkName: "views/domain/info" */ '@/views/domain/DomainInfo'),
component: () => import('@/views/domain/DomainInfo.vue'),
props: true,
children: [
{
name: 'domain-info',
path: ':tabId?',
component: () => import(/* webpackChunkName: "components/configPanel" */ '@/components/ConfigPanel'),
component: () => import('@/components/ConfigPanel.vue'),
props: true,
meta: {
routerParams: ['name'], // Override router key params to avoid view recreation at tab change.
@ -165,7 +165,7 @@ const routes = [
{
name: 'app-list',
path: '/apps',
component: () => import(/* webpackChunkName: "views/apps/list" */ '@/views/app/AppList'),
component: () => import('@/views/app/AppList.vue'),
meta: {
args: { trad: 'applications' },
breadcrumb: ['app-list']
@ -174,7 +174,7 @@ const routes = [
{
name: 'app-catalog',
path: '/apps/catalog',
component: () => import(/* webpackChunkName: "views/apps/catalog" */ '@/views/app/AppCatalog'),
component: () => import('@/views/app/AppCatalog.vue'),
props: route => route.query,
meta: {
args: { trad: 'catalog' },
@ -184,7 +184,7 @@ const routes = [
{
name: 'app-install',
path: '/apps/install/:id',
component: () => import(/* webpackChunkName: "views/apps/install" */ '@/views/app/AppInstall'),
component: () => import('@/views/app/AppInstall.vue'),
props: true,
meta: {
args: { trad: 'install_name', param: 'id' },
@ -194,7 +194,7 @@ const routes = [
{
name: 'app-install-custom',
path: '/apps/install-custom/:id',
component: () => import(/* webpackChunkName: "views/apps/install" */ '@/views/app/AppInstall'),
component: () => import('@/views/app/AppInstall.vue'),
props: true,
meta: {
args: { trad: 'install_name', param: 'id' },
@ -203,13 +203,13 @@ const routes = [
},
{
path: '/apps/:id',
component: () => import(/* webpackChunkName: "views/apps/info" */ '@/views/app/AppInfo'),
component: () => import('@/views/app/AppInfo.vue'),
props: true,
children: [
{
name: 'app-info',
path: ':tabId?',
component: () => import(/* webpackChunkName: "components/configPanel" */ '@/components/ConfigPanel'),
component: () => import('@/components/ConfigPanel.vue'),
props: true,
meta: {
routerParams: ['id'], // Override router key params to avoid view recreation at tab change.
@ -226,7 +226,7 @@ const routes = [
{
name: 'update',
path: '/update',
component: () => import(/* webpackChunkName: "views/update" */ '@/views/update/SystemUpdate'),
component: () => import('@/views/update/SystemUpdate.vue'),
meta: {
args: { trad: 'system_update' },
breadcrumb: ['update']
@ -239,7 +239,7 @@ const routes = [
{
name: 'service-list',
path: '/services',
component: () => import(/* webpackChunkName: "views/service/list" */ '@/views/service/ServiceList'),
component: () => import('@/views/service/ServiceList.vue'),
meta: {
args: { trad: 'services' },
breadcrumb: ['tool-list', 'service-list']
@ -248,7 +248,7 @@ const routes = [
{
name: 'service-info',
path: '/services/:name',
component: () => import(/* webpackChunkName: "views/service/info" */ '@/views/service/ServiceInfo'),
component: () => import('@/views/service/ServiceInfo.vue'),
props: true,
meta: {
args: { param: 'name' },
@ -271,7 +271,7 @@ const routes = [
{
name: 'tool-logs',
path: '/tools/logs',
component: () => import(/* webpackChunkName: "views/tools/logs" */ '@/views/tool/ToolLogs'),
component: () => import('@/views/tool/ToolLogs.vue'),
meta: {
args: { trad: 'logs' },
breadcrumb: ['tool-list', 'tool-logs']
@ -280,7 +280,7 @@ const routes = [
{
name: 'tool-log',
path: '/tools/logs/:name',
component: () => import(/* webpackChunkName: "views/tools/log" */ '@/views/tool/ToolLog'),
component: () => import('@/views/tool/ToolLog.vue'),
props: true,
meta: {
args: { param: 'name' },
@ -290,7 +290,7 @@ const routes = [
{
name: 'tool-migrations',
path: '/tools/migrations',
component: () => import(/* webpackChunkName: "views/tools/migrations" */ '@/views/tool/ToolMigrations'),
component: () => import('@/views/tool/ToolMigrations.vue'),
meta: {
args: { trad: 'migrations' },
breadcrumb: ['tool-list', 'tool-migrations']
@ -299,7 +299,7 @@ const routes = [
{
name: 'tool-firewall',
path: '/tools/firewall',
component: () => import(/* webpackChunkName: "views/tools/firewall" */ '@/views/tool/ToolFirewall'),
component: () => import('@/views/tool/ToolFirewall.vue'),
meta: {
args: { trad: 'firewall' },
breadcrumb: ['tool-list', 'tool-firewall']
@ -308,7 +308,7 @@ const routes = [
{
name: 'tool-webadmin',
path: '/tools/webadmin',
component: () => import(/* webpackChunkName: "views/tools/webadmin" */ '@/views/tool/ToolWebadmin'),
component: () => import('@/views/tool/ToolWebadmin.vue'),
meta: {
args: { trad: 'tools_webadmin_settings' },
breadcrumb: ['tool-list', 'tool-webadmin']
@ -316,12 +316,12 @@ const routes = [
},
{
path: '/tools/settings',
component: () => import(/* webpackChunkName: "views/tools/settings" */ '@/views/tool/ToolSettings'),
component: () => import('@/views/tool/ToolSettings.vue'),
children: [
{
name: 'tool-settings',
path: ':tabId?',
component: () => import(/* webpackChunkName: "components/configPanel" */ '@/components/ConfigPanel'),
component: () => import('@/components/ConfigPanel.vue'),
props: true,
meta: {
routerParams: [],
@ -334,7 +334,7 @@ const routes = [
{
name: 'tool-power',
path: '/tools/power',
component: () => import(/* webpackChunkName: "views/tools/power" */ '@/views/tool/ToolPower'),
component: () => import('@/views/tool/ToolPower.vue'),
meta: {
args: { trad: 'tools_shutdown_reboot' },
breadcrumb: ['tool-list', 'tool-power']
@ -347,7 +347,7 @@ const routes = [
{
name: 'diagnosis',
path: '/diagnosis',
component: () => import(/* webpackChunkName: "views/diagnosis" */ '@/views/diagnosis/Diagnosis'),
component: () => import('@/views/diagnosis/Diagnosis.vue'),
meta: {
args: { trad: 'diagnosis' },
breadcrumb: ['diagnosis']
@ -360,7 +360,7 @@ const routes = [
{
name: 'backup',
path: '/backup',
component: () => import(/* webpackChunkName: "views/backup/backup" */ '@/views/backup/Backup'),
component: () => import('@/views/backup/Backup.vue'),
meta: {
args: { trad: 'backup' },
breadcrumb: ['backup']
@ -369,7 +369,7 @@ const routes = [
{
name: 'backup-list',
path: '/backup/:id',
component: () => import(/* webpackChunkName: "views/backup/list" */ '@/views/backup/BackupList'),
component: () => import('@/views/backup/BackupList.vue'),
props: true,
meta: {
args: { param: 'id' },
@ -379,7 +379,7 @@ const routes = [
{
name: 'backup-info',
path: '/backup/:id/info/:name',
component: () => import(/* webpackChunkName: "views/backup/info" */ '@/views/backup/BackupInfo'),
component: () => import('@/views/backup/BackupInfo.vue'),
props: true,
meta: {
args: { param: 'name' },
@ -389,7 +389,7 @@ const routes = [
{
name: 'backup-create',
path: '/backup/:id/create',
component: () => import(/* webpackChunkName: "views/backup/create" */ '@/views/backup/BackupCreate'),
component: () => import('@/views/backup/BackupCreate.vue'),
props: true,
meta: {
args: { trad: 'backup_create' },

View file

@ -85,7 +85,7 @@ import { validationMixin } from 'vuelidate'
import api from '@/api'
import { DomainForm } from '@/views/_partials'
import Login from '@/views/Login'
import Login from '@/views/Login.vue'
import { alphalownum_, required, minLength, name, sameAs } from '@/helpers/validators'
export default {

View file

@ -53,7 +53,7 @@
import { mapGetters } from 'vuex'
import { validationMixin } from 'vuelidate'
import AdressInputSelect from '@/components/AdressInputSelect'
import AdressInputSelect from '@/components/AdressInputSelect.vue'
import { formatFormDataValue } from '@/helpers/yunohostArguments'
import { required, domain, dynDomain } from '@/helpers/validators'

View file

@ -52,7 +52,7 @@
</template>
<script>
import MessageListGroup from '@/components/MessageListGroup'
import MessageListGroup from '@/components/MessageListGroup.vue'
export default {
name: 'ErrorDisplay',

View file

@ -70,8 +70,8 @@
<script>
import { mapGetters } from 'vuex'
import QueryHeader from '@/components/QueryHeader'
import MessageListGroup from '@/components/MessageListGroup'
import QueryHeader from '@/components/QueryHeader.vue'
import MessageListGroup from '@/components/MessageListGroup.vue'
export default {
name: 'HistoryConsole',

View file

@ -38,7 +38,7 @@
import { mapGetters } from 'vuex'
import api from '@/api'
import LoginView from '@/views/Login'
import LoginView from '@/views/Login.vue'
export default {

View file

@ -21,7 +21,7 @@
<script>
import { mapGetters } from 'vuex'
import { ErrorDisplay, WarningDisplay, WaitingDisplay, ReconnectingDisplay } from '@/views/_partials'
import QueryHeader from '@/components/QueryHeader'
import QueryHeader from '@/components/QueryHeader.vue'
export default {
name: 'ViewLockOverlay',

View file

@ -24,7 +24,7 @@
</template>
<script>
import MessageListGroup from '@/components/MessageListGroup'
import MessageListGroup from '@/components/MessageListGroup.vue'
export default {
name: 'WaitingDisplay',

View file

@ -1,9 +1,9 @@
export { default as ErrorDisplay } from './ErrorDisplay'
export { default as WarningDisplay } from './WarningDisplay'
export { default as WaitingDisplay } from './WaitingDisplay'
export { default as ReconnectingDisplay } from './ReconnectingDisplay'
export { default as ErrorDisplay } from './ErrorDisplay.vue'
export { default as WarningDisplay } from './WarningDisplay.vue'
export { default as WaitingDisplay } from './WaitingDisplay.vue'
export { default as ReconnectingDisplay } from './ReconnectingDisplay.vue'
export { default as HistoryConsole } from './HistoryConsole'
export { default as ViewLockOverlay } from './ViewLockOverlay'
export { default as HistoryConsole } from './HistoryConsole.vue'
export { default as ViewLockOverlay } from './ViewLockOverlay.vue'
export { default as DomainForm } from './DomainForm'
export { default as DomainForm } from './DomainForm.vue'

View file

@ -165,7 +165,7 @@
<script>
import { validationMixin } from 'vuelidate'
import CardDeckFeed from '@/components/CardDeckFeed'
import CardDeckFeed from '@/components/CardDeckFeed.vue'
import { required, appRepoUrl } from '@/helpers/validators'
import { randint } from '@/helpers/commons'

View file

@ -283,7 +283,7 @@ import {
formatI18nField,
formatYunoHostConfigPanels
} from '@/helpers/yunohostArguments'
import ConfigPanels from '@/components/ConfigPanels'
import ConfigPanels from '@/components/ConfigPanels.vue'
export default {
name: 'AppInfo',

View file

@ -164,7 +164,7 @@ import {
formatI18nField,
formatFormData
} from '@/helpers/yunohostArguments'
import CardCollapse from '@/components/CardCollapse'
import CardCollapse from '@/components/CardCollapse.vue'
export default {
name: 'AppInstall',

View file

@ -95,7 +95,7 @@ import {
formatFormData,
formatYunoHostConfigPanels
} from '@/helpers/yunohostArguments'
import ConfigPanels from '@/components/ConfigPanels'
import ConfigPanels from '@/components/ConfigPanels.vue'
import DomainDns from './DomainDns.vue'

View file

@ -41,7 +41,7 @@
<script>
import { mapGetters } from 'vuex'
import RecursiveListGroup from '@/components/RecursiveListGroup'
import RecursiveListGroup from '@/components/RecursiveListGroup.vue'
export default {

View file

@ -109,7 +109,7 @@ import Vue from 'vue'
import api from '@/api'
import { isEmptyValue } from '@/helpers/commons'
import TagsSelectizeItem from '@/components/globals/formItems/TagsSelectizeItem'
import TagsSelectizeItem from '@/components/globals/formItems/TagsSelectizeItem.vue'
// TODO add global search with type (search by: group, user, permission)
// TODO add vuex store update on inputs ?

View file

@ -13,7 +13,7 @@ import {
formatFormData,
formatYunoHostConfigPanels
} from '@/helpers/yunohostArguments'
import ConfigPanels from '@/components/ConfigPanels'
import ConfigPanels from '@/components/ConfigPanels.vue'
export default {

View file

@ -84,7 +84,7 @@ export default {
const availableLocales = this.$store.getters.availableLocales
this.fields.locale.props.choices = availableLocales
this.fields.fallbackLocale.props.choices = availableLocales
if (process.env.NODE_ENV === 'development') {
if (import.meta.env.DEV) {
this.fields.experimental = {
id: 'experimental',
label: this.$i18n.t('tools_webadmin.experimental'),

View file

@ -114,7 +114,7 @@
import api from '@/api'
import { mapGetters } from 'vuex'
import CardCollapse from '@/components/CardCollapse'
import CardCollapse from '@/components/CardCollapse.vue'
export default {
name: 'SystemUpdate',

View file

@ -101,7 +101,7 @@ import {
name, required, minLength, emailLocalPart, sameAs, integer, minValue, emailForward
} from '@/helpers/validators'
import AdressInputSelect from '@/components/AdressInputSelect'
import AdressInputSelect from '@/components/AdressInputSelect.vue'
export default {

85
app/vite.config.js Normal file
View file

@ -0,0 +1,85 @@
import { fileURLToPath, URL } from 'url';
import { defineConfig, loadEnv } from 'vite'
import fs from 'fs'
import vue from '@vitejs/plugin-vue2'
export default defineConfig(({ command, mode }) => {
// Load env file based on `mode` in the current working directory.
// Set the third parameter to '' to load all env regardless of the `VITE_` prefix.
const env = loadEnv(mode, process.cwd())
const config = {
define: {
// fake process.env for some deps
'process.env': {}
},
resolve:{
alias:[
// this is required for the SCSS modules imports with `~` (node_modules)
{ find: /^~(.*)$/, replacement: '$1' },
{ find: '@', replacement: fileURLToPath(new URL('./src', import.meta.url)) },
]
},
css: {
preprocessorOptions: {
scss: {
// To auto inject scss variables into componentns scope
additionalData: `
@import "@/scss/_variables.scss";
`
}
}
},
plugins: [
vue()
],
build: {
rollupOptions: {
output: {
manualChunks: (id) => {
// Circular import problems, this will merge vue/vuex/etc. and api together
if (!id.includes('node_modules') && id.includes('api/')) {
return 'core';
}
}
}
}
}
}
if (mode === 'production') {
return {
...config,
base: '/yunohost/admin',
}
} else if (mode === 'development') {
return {
...config,
server: {
port: 8080,
host: env.VITE_IP,
https: {
// Use already created cert from yunohost instance
key: fs.readFileSync('/etc/yunohost/certs/yunohost.org/key.pem'),
cert: fs.readFileSync('/etc/yunohost/certs/yunohost.org/crt.pem'),
},
fs: {
// Needed for special ynh-dev context where node_modules is symlinked
allow: [
'/ynh-dev/yunohost-admin/app',
'/var/cache/ynh-dev/yunohost-admin/node_modules'
]
},
proxy: {
'/yunohost': {
target: `https://${env.VITE_IP}`,
ws: true,
logLevel: 'info',
secure: false,
},
},
}
}
}
})

View file

@ -1,90 +0,0 @@
const webpack = require('webpack')
const fs = require('fs')
const dateFnsLocales = [
'ar',
'ar-DZ', // for `kab`
'bn', // for 'bn_BD'
'ca', // for 'ca' & 'oc'
'cs',
'da',
'de',
'el',
'en-GB', // for 'en' & 'ne'
'eo',
'es',
'eu',
'fa-IR',
'fi',
'fr', // for 'fr' & 'br'
'gl',
'he',
'hi',
'hu',
'id',
'it',
'lt',
'mk',
'nb', // for 'nb_NO'
'nl',
'oc',
'pl',
'pt',
'pt-BR',
'ru',
'sl',
'sv',
'tr',
'uk',
'zh_CN' // for 'zh_Hans'
]
module.exports = {
configureWebpack: {
plugins: [
// Will limit the available locales so webpack won't generate chunks for every
// locales found in `date-fns/locales/` but only those listed.
new webpack.ContextReplacementPlugin(
/date-fns[/\\]/,
new RegExp(`[/\\\\](${dateFnsLocales.join('|')})[/\\\\]index.js$`)
)
]
},
pluginOptions: {
i18n: {
locale: 'en',
fallbackLocale: 'en',
localeDir: 'src/i18n/locales',
enableInSFC: false
}
},
css: {
loaderOptions: {
sass: {
additionalData: '@import "@/scss/_variables.scss";'
}
}
},
publicPath: '/yunohost/admin',
devServer: process.env.NODE_ENV === 'development'
? {
public: fs.readFileSync('/etc/yunohost/current_host', 'utf8'),
https: false,
allowedHosts: 'all',
proxy: {
'^/yunohost': {
target: `http://${process.env.VUE_APP_IP}`,
ws: true,
logLevel: 'info'
}
},
static: {
watch: {
ignored: /node_modules/,
aggregateTimeout: 300,
poll: 1000
}
}
}
: {}
}