-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
css-post plugins crashes when using transformRequest without first starting a server #3798
Comments
not sure we should directly use transformRequest, if so, we can do null check on this line
|
It's documented here https://vitejs.dev/guide/api-javascript.html so I would expect it to be supported |
@Pajn where is it documented that you can use |
@patak-js Not explicitly without starting the server, but it says "Programmatically resolve, load and transform a URL and get the result without going through the http request pipeline.". It seems weird to start a server and consume a port that you'll never use. It also works great with js and ts files, as long as no css files are imported making it more seem like a bug in the css plugin instead of a limitation of the API. EDIT: Missed your final question
I'm trying to make an integration with |
The issue is that the rollup plugins are intended to be used in the context of the server running. As with rollup, plugins uses
This looks like a valid use case though. I think it would be complex to introduce a feature to avoid the server connection. In your case, with respect to this comment material-svelte/vite-web-test-runner-plugin#11 (comment), couldn't you create a plugin for Vite that would take care of not transforming that file? |
Maybe there should be a way to start a build without also starting the server?
I was planning to propose diff --git a/packages/vite/src/node/config.ts b/packages/vite/src/node/config.ts
index 5ef64be1..274dbc27 100644
--- a/packages/vite/src/node/config.ts
+++ b/packages/vite/src/node/config.ts
@@ -111,7 +111,7 @@ export interface UserConfig {
/**
* Configure resolver
*/
- resolve?: ResolveOptions & { alias?: AliasOptions }
+ resolve?: ResolveOptions & { alias?: AliasOptions, external?: string[] }
/**
* CSS related options (preprocessors and CSS modules)
*/
diff --git a/packages/vite/src/node/plugins/importAnalysis.ts b/packages/vite/src/node/plugins/importAnalysis.ts
index a1ad68c4..d2a63acf 100644
--- a/packages/vite/src/node/plugins/importAnalysis.ts
+++ b/packages/vite/src/node/plugins/importAnalysis.ts
@@ -176,6 +176,10 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin {
url = url.replace(base, '/')
}
+ if (config.resolve.external?.includes(url)) {
+ return [url, url]
+ }
+
const resolved = await this.resolve(url, importer)
if (!resolved) { This would to my understanding make it equal to packageOptions.external in snowpack. With that and my custom test runner plugin I have |
Re-checking our discussion, this is already the case in middleware mode. You can init your server using and it will properly call buildStart and optimizeDeps, so you can use transformRequest after that const server = await vite.createServer({
clearScreen: false,
server: {
middlewareMode: 'ssr'
}
}) |
Do you have an example of this you could share? I am currently running into the same issue. |
A workaround: Instead for const server = await vite.createServer(serverConfig)
await server.pluginContainer.buildStart({}) Refer:
|
Describe the bug
While using the JS API, transformRequest can be used to get transformed versions of js/ts files without starting a server, but when doing the same on css files the css-post plugin crashes with:
Reproduction
https://github.com/Pajn/vite-transformRequest-css-crash-repro
System Info
Output of
npx envinfo --system --npmPackages vite,@vitejs/plugin-vue --binaries --browsers
:Used package manager: yarn
Logs
See Repro
Before submitting the issue, please make sure you do the following
The text was updated successfully, but these errors were encountered: