forked from vitejs/vite
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: use async fs + expose createServer API
- Loading branch information
Showing
10 changed files
with
170 additions
and
7,540 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
#!/usr/bin/env node | ||
require('../lib/server') | ||
const { createServer } = require('../lib/server') | ||
|
||
// TODO pass cli args | ||
createServer() |
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 |
---|---|---|
@@ -1,23 +1,24 @@ | ||
const fs = require('fs') | ||
const path = require('path') | ||
const { sendJS } = require('./utils') | ||
const resolve = require('resolve-cwd') | ||
const { sendJSStream } = require('./utils') | ||
|
||
exports.moduleMiddleware = (id, res) => { | ||
let modulePath | ||
// try node resolve first | ||
// TODO support custom imports map e.g. for snowpack web_modules | ||
|
||
// fallback to node resolve | ||
try { | ||
modulePath = require.resolve(id) | ||
modulePath = resolve(id) | ||
if (id === 'vue') { | ||
modulePath = path.join( | ||
path.dirname(modulePath), | ||
'dist/vue.runtime.esm-browser.js' | ||
) | ||
} | ||
} catch (e) { | ||
res.setStatus(404) | ||
res.end() | ||
} | ||
|
||
// TODO resolve snowpack web_modules | ||
|
||
if (id === 'vue') { | ||
// modulePath = path.relative(modulePath, 'dist/vue.runtime.esm-browser.js') | ||
modulePath = path.resolve(__dirname, 'vue.js') | ||
} | ||
|
||
sendJS(res, fs.readFileSync(modulePath)) | ||
sendJSStream(res, modulePath) | ||
} |
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
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
Oops, something went wrong.