-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathvite.config.js
150 lines (137 loc) · 3.46 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import path from 'path';
import dayjs from 'dayjs';
import utcPlugin from 'dayjs/plugin/utc.js';
import { defineConfig } from 'vite';
import browserslistToEsbuild from 'browserslist-to-esbuild';
import babel from 'vite-plugin-babel';
import eslint from 'vite-plugin-eslint';
import handlebars from './config/vite-plugin-handlebars-loader.js';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import stylelint from 'vite-plugin-stylelint';
import { VitePWA } from 'vite-plugin-pwa';
import yaml from './config/vite-plugin-yaml.js';
import getFaIconSymbols from './config/fontawesome.js';
dayjs.extend(utcPlugin);
const faIconSymbols = getFaIconSymbols();
const resolve = {
alias: {
'marionette': 'backbone.marionette',
'store': 'store/dist/store.modern',
},
mainFields: ['module', 'main', 'browser'],
};
const css = {
preprocessorOptions: {
scss: {
// remove this when we switch sass to use modern js api
api: 'legacy',
additionalData: `
@use 'sass:math';
@use 'sass:color';
@import 'src/scss/provider-variables.scss';
`,
},
},
};
const cypressConfig = defineConfig({
mode: 'test',
plugins: [
babel(),
nodeResolve({
modulePaths: [
path.resolve('./node_modules'),
path.resolve('./src'),
path.resolve('./test'),
],
}),
],
resolve,
css,
publicDir: false,
});
export {
cypressConfig,
};
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
const isProduction = mode === 'production';
const isTest = mode === 'test' || process.env.NODE_ENV === 'test';
const isCI = !!process.env.CI;
const datePrefix = dayjs.utc().format('YYYYMMDD');
const modulePaths = [
path.resolve('./node_modules'),
path.resolve('./src'),
];
if (isTest) {
process.env.NODE_ENV = 'test';
modulePaths.push(path.resolve('./test'));
}
return {
plugins: [
babel({
exclude: '**/formio.form.min*',
}),
eslint({
failOnWarning: isCI,
fix: !isCI,
}),
stylelint({
emitWarningAsError: isCI,
fix: !isCI,
}),
handlebars(),
yaml(),
nodeResolve({
modulePaths,
}),
isProduction && VitePWA({
strategies: 'injectManifest',
manifest: false,
injectRegister: false,
srcDir: 'src/js',
filename: 'sw.js',
injectManifest: {
globPatterns: [
'**/*.{html,js,css,woff2,webmanifest}',
],
globIgnores: [
'**/*.map',
'**/.DS_Store',
],
},
}),
],
define: {
'import.meta.env.faIconSymbols': JSON.stringify(faIconSymbols),
'_PRODUCTION_': JSON.stringify(isProduction),
'_DEVELOP_': JSON.stringify(mode === 'development'),
'_TEST_': JSON.stringify(isTest),
'_NOW_': JSON.stringify(Date.now()),
},
resolve,
css,
server: {
open: !isTest,
port: isTest ? 8090 : 8081,
proxy: {
'/api': {
target: 'http://localhost:8080',
rewrite: rewritePath => rewritePath.replace(/^\/api/, ''),
},
},
},
preview: {
port: isTest ? 8090 : 8081,
},
build: {
sourcemap: 'hidden',
target: browserslistToEsbuild(),
rollupOptions: {
output: {
entryFileNames: `${ datePrefix }-[name]-[hash].js`,
chunkFileNames: `${ datePrefix }-[name]-[hash].js`,
},
},
},
};
});