Skip to content

Instantly share code, notes, and snippets.

@tranthaison1231
Created July 15, 2021 08:48
Show Gist options
  • Select an option

  • Save tranthaison1231/f86471a6956795c2077d3a77813f538b to your computer and use it in GitHub Desktop.

Select an option

Save tranthaison1231/f86471a6956795c2077d3a77813f538b to your computer and use it in GitHub Desktop.
Config build for vite + antd
import path from 'path';
import fs from 'fs';
import { defineConfig, loadEnv } from 'vite';
import reactRefresh from '@vitejs/plugin-react-refresh';
import vitePluginImp from 'vite-plugin-imp';
import { visualizer } from 'rollup-plugin-visualizer';
import lessToJS from 'less-vars-to-js';
import viteSentry from 'vite-plugin-sentry';
const themeVariables = lessToJS(
fs.readFileSync(
path.resolve(__dirname, './src/configs/theme/index.less'),
'utf8',
),
);
export default ({ mode }) => {
process.env = { ...process.env, ...loadEnv(mode, process.cwd()) };
return defineConfig({
esbuild: {
jsxInject: `import React from 'react'`,
},
plugins: [
reactRefresh(),
viteSentry({
url: process.env.SENTRY_URL,
authToken: process.env.SENTRY_AUTH_TOKEN,
org: process.env.SENTRY_ORG,
project: process.env.SENTRY_PROJECT,
release: '1.0',
deploy: {
env: 'staging',
},
setCommits: {
auto: true,
},
sourceMaps: {
include: ['./build/assets'],
ignore: ['node_modules'],
urlPrefix: '~/assets',
},
}),
vitePluginImp({
libList: [
{
libName: 'antd',
libDirectory: 'es',
style: name => `antd/es/${name}/style`,
},
],
}),
],
css: {
preprocessorOptions: {
less: {
javascriptEnabled: true,
modifyVars: themeVariables,
},
},
},
resolve: {
alias: [
{
find: './runtimeConfig',
replacement: './runtimeConfig.browser',
},
{
find: /^#/,
replacement: path.resolve(__dirname, 'src'),
},
{ find: /^~/, replacement: '' },
],
},
optimizeDeps: {
include: ['@ant-design/icons', 'antd'],
},
build: {
sourcemap: false,
outDir: 'build',
terserOptions: {
format: {
comments: false,
},
compress: {
keep_infinity: true,
drop_console: true,
},
},
rollupOptions: {
plugins: [visualizer()],
},
},
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment