|
10 | 10 | // $FlowFixMe[module-missing]
|
11 | 11 | import {init, parse} from 'es-module-lexer';
|
12 | 12 | import MagicString from 'magic-string';
|
13 |
| -// $FlowFixMe[module-missing] |
14 |
| -import {normalizePath, transformWithEsbuild, createServer} from 'vite'; |
15 | 13 |
|
16 | 14 | import {promises as fs} from 'fs';
|
17 | 15 | import path from 'path';
|
18 | 16 |
|
| 17 | +// $FlowFixMe[module-missing] |
| 18 | +import * as vite from 'vite'; |
| 19 | +const {normalizePath, transformWithEsbuild, createServer} = vite; |
| 20 | +const isVite3 = vite.version && vite.version.startsWith('3.'); |
| 21 | + |
19 | 22 | type PluginOptions = {
|
20 | 23 | serverBuildEntries: string[],
|
21 | 24 | optimizeBoundaries: boolean | 'build',
|
@@ -351,7 +354,8 @@ async function findClientBoundariesForClientBuild(
|
351 | 354 | const server = await createServer({
|
352 | 355 | root,
|
353 | 356 | clearScreen: false,
|
354 |
| - server: {middlewareMode: 'ssr'}, |
| 357 | + server: {middlewareMode: isVite3 ? true : 'ssr', hmr: false}, |
| 358 | + appType: 'custom', |
355 | 359 | });
|
356 | 360 |
|
357 | 361 | try {
|
@@ -380,7 +384,8 @@ const hashImportsPlugin = {
|
380 | 384 | function(_, imports) {
|
381 | 385 | return imports
|
382 | 386 | .trim()
|
383 |
| - .replace(/"([^"]+?)":/gm, function(__, relativePath) { |
| 387 | + .replace(/"([^"]+?)":/gm, function(all, relativePath) { |
| 388 | + if (relativePath === '__VITE_PRELOAD__') return all; |
384 | 389 | const absolutePath = path.resolve(
|
385 | 390 | path.dirname(id.split('?')[0]),
|
386 | 391 | relativePath,
|
|
0 commit comments