-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
54 lines (50 loc) · 1.89 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import fs from 'fs';
import path from 'path';
import dotenv from 'dotenv';
import svgo from 'vite-svg-loader';
import { defineConfig } from 'vite';
import tinify from './plugin/tinify.js';
import dotenvExpand from 'dotenv-expand';
import eslint from 'vite-plugin-eslint';
import { svelte } from '@sveltejs/vite-plugin-svelte';
import devManifest from 'vite-plugin-dev-manifest/dist/index.mjs';
const __home = process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE;
const pem = `${__home}/.config/valet/CA/LaravelValetCASelfSigned.pem`;
const certDir = `${__home}/.config/valet/Certificates`;
try {
dotenvExpand.expand(dotenv.config());
} catch (error) {
console.warn('No .env file');
}
export default (args = {}, handler) => {
const VITEPACK_HOST = process.env.VITEPACK_HOST || process.env.APP_HOST;
const VITEPACK_URL = process.env.VITEPACK_URL || process.env.APP_URL;
return handler(defineConfig({
base: args.base,
publicDir: (args.static ? args.static : false),
build: {
manifest: true,
outDir: args.outDir,
assetsInlineLimit: 0
},
plugins: [
svgo({ defaultImport: 'url' }),
devManifest(),
eslint(),
tinify(),
svelte()
],
server: {
host: (VITEPACK_HOST ? VITEPACK_HOST : 'localhost'),
https: args.https !== undefined ? args.https : (VITEPACK_URL && VITEPACK_URL.includes('https:') && fs.existsSync(pem) ? {
key: fs.readFileSync(`${certDir}/${VITEPACK_HOST}.key`),
cert: fs.readFileSync(`${certDir}/${VITEPACK_HOST}.crt`),
ca: fs.readFileSync(pem)
} : false)
},
resolve: {
extensions: [ '.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.svelte' ],
alias: { '@': path.resolve(process.cwd(), 'src') }
}
}));
};