-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.js
139 lines (119 loc) · 4.32 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
import { defineConfig } from 'vite';
import path from 'path';
// Vite Plugins
import ReactPlugin from '@vitejs/plugin-react';
import EslintPlugin from 'vite-plugin-eslint';
import AnalyzePlugin from 'rollup-plugin-analyzer';
import CompressionPlugin from 'vite-plugin-compression';
// PostCSS Plugins
import tailwindcss from 'tailwindcss';
import prefixer from 'postcss-prefix-selector';
import autoprefixer from 'autoprefixer';
export default ({ command }) => defineConfig({
// Set the root to our source folder
root: './src/web/assets',
// When building update the destination base
base: command === 'serve' ? '' : '/dist/',
build: {
outDir: './dist',
emptyOutDir: true,
manifest: 'manifest.json',
sourcemap: true,
rollupOptions: {
input: {
'metrix-cp': path.resolve('./src/web/assets/src/apps/cp/metrix-cp.js'),
'metrix-dashboard': path.resolve('./src/web/assets/src/apps/dashboard/metrix-dashboard.js'),
'metrix-presets': path.resolve('./src/web/assets/src/apps/presets/metrix-presets.js'),
'metrix-sources': path.resolve('./src/web/assets/src/apps/sources/metrix-sources.js'),
},
output: {
sourcemapExcludeSources: true,
manualChunks: {
chartjs: ['chart.js'],
react: ['react', 'react-dom'],
dndkit: ['@dnd-kit/core', '@dnd-kit/sortable'],
},
},
},
},
server: {
origin: 'http://localhost:4040',
hmr: {
// Using the default `wss` doesn't work on https
protocol: 'ws',
},
},
plugins: [
// Keep JS looking good with eslint
// https://github.com/gxmari007/vite-plugin-eslint
EslintPlugin({
cache: false,
fix: true,
include: './src/web/assets/src/**/*.{js,jsx}',
}),
// React support
// https://github.com/vitejs/vite-plugin-react
ReactPlugin(),
// Analyze bundle size
// https://github.com/doesdev/rollup-plugin-analyzer
AnalyzePlugin({
summaryOnly: true,
limit: 15,
}),
// Gzip assets
// https://github.com/vbenjs/vite-plugin-compression
CompressionPlugin({
filter: /\.(js|mjs|json|css|map)$/i,
}),
],
css: {
postcss: {
plugins: [
tailwindcss,
// Ensure that we can only use Tailwind in `.metrix-ui` parent containers
// This prevents style bleed both to and from Craft
prefixer({
prefix: '.metrix-ui',
transform: function (prefix, selector, prefixedSelector, filePath, rule) {
if (filePath.includes('assets/src/apps/cp/')) {
return selector;
}
return prefixedSelector;
}
}),
autoprefixer,
],
},
preprocessorOptions: {
// Fix Sass 2.0 deprecation issues
scss: {
api: 'modern-compiler',
silenceDeprecations: ['legacy-js-api'],
},
},
},
resolve: {
alias: {
// Reference Tailwind config so we can use in components
'tailwind.config.js': path.resolve('tailwind.config.js'),
'@shared': path.resolve('./src/web/assets/src/shared'),
'@components': path.resolve('./src/web/assets/src/shared/components'),
'@utils': path.resolve('./src/web/assets/src/shared/utils'),
// Allow shortcuts in JS, CSS and Twig for ease of development.
'@cp': path.resolve('./src/web/assets/src/apps/cp'),
'@dashboard': path.resolve('./src/web/assets/src/apps/dashboard'),
'@presets': path.resolve('./src/web/assets/src/apps/presets'),
'@sources': path.resolve('./src/web/assets/src/apps/sources'),
},
},
// Add in any components to optimise them early.
optimizeDeps: {
include: [
'lodash-es',
'tailwind.config.js',
'chart.js',
'react',
'react-dom',
],
},
});