generated from tooooools/boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.js
70 lines (61 loc) · 1.82 KB
/
vite.config.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import path from 'path'
import { defineConfig, loadEnv } from 'vite'
import { viteCommonjs } from '@originjs/vite-plugin-commonjs'
// If a backend is needed, see https://vitejs.dev/guide/backend-integration.html
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), '')
return {
root: path.join(__dirname, 'src'),
publicDir: path.join(__dirname, 'public'),
envDir: path.join(__dirname),
base: env.BASE || '/',
build: {
outDir: path.join(__dirname, 'build'),
commonjsOptions: { include: [/shared/, /node_modules/] }
},
define: {
__NAME__: JSON.stringify(process.env.npm_package_name),
__VERSION__: JSON.stringify(process.env.npm_package_version)
},
resolve: {
alias: { '/shared': path.join(__dirname, 'shared') }
},
plugins: [
viteCommonjs(),
{ // Replace index.jsx by test/test.jsx as entry in test mode
name: 'html-inject-test',
transformIndexHtml: html => mode === 'test' ? html.replace('/index.jsx', '/test/test.jsx') : html,
config: () => ({
resolve: {
alias: { '/test': path.join(__dirname, 'test') }
}
})
},
{ // Replace %SEMVER% in HTML
name: 'html-inject-version',
transformIndexHtml: html =>
html.replace('%SEMVER%', process.env.npm_package_version + (mode !== 'production' ? `@${mode}` : ''))
}
],
server: {
port: 8080,
host: true
},
css: {
devSourcemap: true,
preprocessorOptions: {
scss: {
additionalData: `
@use '/style/_helpers' as *;
@use '/style/_devices' as *;
$env: ${mode};
`
}
}
},
esbuild: {
jsxInject: "import h from '/utils/jsx/h'",
jsxFactory: 'h'
}
}
})