-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: library mode does not include preload (#4097)
- Loading branch information
Showing
8 changed files
with
138 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// @ts-check | ||
// this is automtically detected by scripts/jestPerTestSetup.ts and will replace | ||
// the default e2e test serve behavior | ||
|
||
const path = require('path') | ||
const http = require('http') | ||
const sirv = require('sirv') | ||
|
||
const port = (exports.port = 9527) | ||
|
||
/** | ||
* @param {string} root | ||
* @param {boolean} isBuildTest | ||
*/ | ||
exports.serve = async function serve(root, isBuildTest) { | ||
// build first | ||
|
||
if (!isBuildTest) { | ||
const { createServer } = require('vite') | ||
process.env.VITE_INLINE = 'inline-serve' | ||
let viteServer = await ( | ||
await createServer({ | ||
root: root, | ||
logLevel: 'silent', | ||
server: { | ||
watch: { | ||
usePolling: true, | ||
interval: 100 | ||
}, | ||
host: true, | ||
fs: { | ||
strict: !isBuildTest | ||
} | ||
}, | ||
build: { | ||
target: 'esnext' | ||
} | ||
}) | ||
).listen() | ||
// use resolved port/base from server | ||
const base = viteServer.config.base === '/' ? '' : viteServer.config.base | ||
const url = | ||
(global.viteTestUrl = `http://localhost:${viteServer.config.server.port}${base}`) | ||
await page.goto(url) | ||
|
||
return viteServer | ||
} else { | ||
const { build } = require('vite') | ||
await build({ | ||
root, | ||
logLevel: 'silent', | ||
configFile: path.resolve(__dirname, '../vite.config.js') | ||
}) | ||
|
||
await build({ | ||
root, | ||
logLevel: 'silent', | ||
configFile: path.resolve(__dirname, '../vite.dyimport.config.js') | ||
}) | ||
|
||
// start static file server | ||
const serve = sirv(path.resolve(root, 'dist')) | ||
const httpServer = http.createServer((req, res) => { | ||
if (req.url === '/ping') { | ||
res.statusCode = 200 | ||
res.end('pong') | ||
} else { | ||
serve(req, res) | ||
} | ||
}) | ||
|
||
return new Promise((resolve, reject) => { | ||
try { | ||
const server = httpServer.listen(port, async () => { | ||
await page.goto(`http://localhost:${port}`) | ||
resolve({ | ||
// for test teardown | ||
async close() { | ||
await new Promise((resolve) => { | ||
server.close(resolve) | ||
}) | ||
} | ||
}) | ||
}) | ||
} catch (e) { | ||
reject(e) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export default async function message(sel) { | ||
const message = await import('./message.js') | ||
document.querySelector(sel).textContent = message.default | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default 'hello vite' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const fs = require('fs') | ||
const path = require('path') | ||
|
||
/** | ||
* @type {import('vite').UserConfig} | ||
*/ | ||
module.exports = { | ||
build: { | ||
minify: false, | ||
lib: { | ||
entry: path.resolve(__dirname, 'src/main2.js'), | ||
formats: ['es'], | ||
name: 'message', | ||
fileName: () => 'dynamic-import-message.js' | ||
}, | ||
outDir: 'dist/lib' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters