@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user