Skip to content

Commit

Permalink
Added support for .env files (#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
utement authored Apr 21, 2023
1 parent ca5593e commit 39595bb
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 43 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ media
/dynamicforms/vue/node_modules/
/dynamicforms/vue/package-lock.json
/dist/

# Local configuration
.env.local
1 change: 1 addition & 0 deletions vue/demo/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VITE_AXIOS_TARGET=http://localhost:8000
88 changes: 45 additions & 43 deletions vue/demo/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { resolve } from 'path';

import vue from '@vitejs/plugin-vue';
import { createProxyMiddleware } from 'http-proxy-middleware';
import { defineConfig } from 'vite';
import { ConfigEnv, defineConfig, loadEnv } from 'vite';
import eslint from 'vite-plugin-eslint';
import vuetify from 'vite-plugin-vuetify';

Expand All @@ -16,55 +16,57 @@ const axiosRedirectConfig = () => ({
server.middlewares.use(
'/',
createProxyMiddleware(filter, {
target: 'http://localhost:8000',
target: process.env.VITE_AXIOS_TARGET,
changeOrigin: false,
pathRewrite: (path) => (path),
}),
);
},
});

/** @type {import('vite').UserConfig} */
export default defineConfig({
plugins: [
vue(),
{
...eslint({
failOnWarning: false,
failOnError: false,
overrideConfig: { parserOptions: { project: '../../tsconfig.eslint.json' } },
}),
apply: 'serve',
enforce: 'post',
export default ({mode}: ConfigEnv) => {
process.env = {...process.env, ...loadEnv(mode, process.cwd())};
return defineConfig({
plugins: [
vue(),
{
...eslint({
failOnWarning: false,
failOnError: false,
overrideConfig: {parserOptions: {project: '../../tsconfig.eslint.json'}},
}),
apply: 'serve',
enforce: 'post',
},
vuetify({autoImport: true}),
axiosRedirectConfig(),
],
resolve: {
alias: {
dynamicforms: resolve(__dirname, '../dynamicforms/src/index'),
'@': resolve(__dirname, './src'),
'~': resolve(__dirname, '../../node_modules'),
},
extensions: [
'.js',
'.ts',
'.vue',
'.json',
'.css',
],
},
vuetify({ autoImport: true }),
axiosRedirectConfig(),
],
resolve: {
alias: {
dynamicforms: resolve(__dirname, '../dynamicforms/src/index'),
'@': resolve(__dirname, './src'),
'~': resolve(__dirname, '../../node_modules'),
server: {
port: 8080,
fs: {
// Allow serving files from one level up to the project root
allow: ['..'],
},
},
extensions: [
'.js',
'.ts',
'.vue',
'.json',
'.css',
],
},
server: {
port: 8080,
fs: {
// Allow serving files from one level up to the project root
allow: ['..'],
test: {
deps: {inline: ['vuetify']},
globals: true,
environment: 'jsdom',
useAtomics: true, // eliminates tests hang at the end (https://github.com/vitest-dev/vitest/issues/2008)
},
},
test: {
deps: { inline: ['vuetify'] },
globals: true,
environment: 'jsdom',
useAtomics: true, // eliminates tests hang at the end (https://github.com/vitest-dev/vitest/issues/2008)
},
});
});
};

0 comments on commit 39595bb

Please sign in to comment.