chore: some more vite work

Signed-off-by: blam <ben@blam.sh>
This commit is contained in:
blam
2023-09-21 13:33:41 +02:00
parent 5c5a5a8207
commit 0e6fc26cbf
2 changed files with 46 additions and 1 deletions
+42 -1
View File
@@ -36,6 +36,10 @@ import { createConfig, resolveBaseUrl } from './config';
import { createDetectedModulesEntryPoint } from './packageDetection';
import { resolveBundlingPaths } from './paths';
import { ServeOptions } from './types';
import { nodePolyfills as viteNodePolyfills } from 'vite-plugin-node-polyfills';
import { esbuildCommonjs, viteCommonjs } from '@originjs/vite-plugin-commonjs';
import pluginSvgr from 'vite-plugin-svgr';
import vitePluginSvgr from 'vite-plugin-svgr';
export async function serveBundle(options: ServeOptions) {
const paths = resolveBundlingPaths(options);
@@ -159,11 +163,47 @@ export async function serveBundle(options: ServeOptions) {
if (process.env.EXPERIMENTAL_VITE) {
server = await vite.createServer({
plugins: [react()],
define: {
global: 'globalThis',
APP_CONFIG: JSON.stringify(cliConfig.frontendAppConfigs),
},
resolve: {
alias: {
'node-fetch': 'cross-fetch',
},
},
plugins: [
react(),
vitePluginSvgr(),
viteCommonjs(),
viteNodePolyfills(),
{
name: 'transform-index-html',
configureServer(s) {
s.middlewares.use(async (req, res, next) => {
if (req.url === '/') {
res.end(
await s.transformIndexHtml(
req.url,
await fs.readFile(paths.targetHtml, 'utf-8'),
),
);
} else {
next();
}
});
},
},
],
server: {
host,
port,
},
optimizeDeps: {
esbuildOptions: {
plugins: [esbuildCommonjs(['!nano-css'])],
},
},
build: {
commonjsOptions: {
include: ['*'],
@@ -171,6 +211,7 @@ export async function serveBundle(options: ServeOptions) {
},
},
publicDir: paths.targetPublic,
root: paths.targetPath,
});
} else {
const compiler = webpack(config);