Skip to content
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

plugin-vue doesn't respect configured loaders since 1.8 #7908

Closed
7 tasks done
jods4 opened this issue Apr 26, 2022 · 1 comment · Fixed by #7909
Closed
7 tasks done

plugin-vue doesn't respect configured loaders since 1.8 #7908

jods4 opened this issue Apr 26, 2022 · 1 comment · Fixed by #7909

Comments

@jods4
Copy link
Contributor

jods4 commented Apr 26, 2022

Describe the bug

plugin-vue merges inline TS scripts in SFC, and compiles them itself with ESBuild.
Doing so bypasses any loader configuration for TS, which is unexpected and creates problems (see below).

This is a regression that was introduced in 1.8 by this commit 93d9a2d#diff-50999b66ad3fff48fd315417d4f8c98741da9f85a0fa6bb4ba212cc8f8bac967L271-R267

Specifically, the new behavior is to always merge inline ts scripts (previously it was done only for devServer):

if ((!script.lang || script.lang === 'ts') && !script.src) {
scriptCode = rewriteDefault(script.content, '_sfc_main')

Once merged, the inlined ts scripts are converted to JS by esbuild directly, without regard for any specific loader / config:

// handle TS transpilation
let resolvedCode = output.join('\n')
if (
(descriptor.script?.lang === 'ts' ||
descriptor.scriptSetup?.lang === 'ts') &&
!descriptor.script?.src // only normal script can have src
) {
const { code, map } = await transformWithEsbuild(
resolvedCode,
filename,
{ loader: 'ts', sourcemap: options.sourceMap },
resolvedMap
)
resolvedCode = code
resolvedMap = resolvedMap ? (map as any) : resolvedMap
}

This breaks builds that have non-default configuration. Solving this will close the following issues:

The easiest fix is to go back to not inlining TS outside devServer.
A more complex fix is to apply loaders from config when building TS inside SFC. This is IMHO less preferred because it has a high impact on the performance of devServer.

Reproduction

See #5044 or #5795

System Info

System:
    OS: Windows 10 10.0.19042
    CPU: (12) x64 Intel(R) Core(TM) i7-9850H CPU @ 2.60GHz
    Memory: 7.69 GB / 15.79 GB
  Binaries:
    Node: 16.6.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.10 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 7.19.1 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.19041.1266.0), Chromium (100.0.1185.50), ChromiumDev (102.0.1227.0)
    Internet Explorer: 11.0.19041.1566

Used Package Manager

npm

Logs

No response

Validations

jods4 added a commit to jods4/vite that referenced this issue Apr 26, 2022
Partial revert of 93d9a2d
When building, TS scripts must not be inlined so that loaders (e.g. rollup-plugin-typescript2) are correctly applied.

Fixes vitejs#5044, vitejs#5795, vitejs#7908
@jods4
Copy link
Contributor Author

jods4 commented Apr 26, 2022

I made a PR for the simple fix (revert, don't inline during build): #7909

@github-actions github-actions bot locked and limited conversation to collaborators May 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants