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

Pug support #17

Closed
kaangokdemir opened this issue Apr 28, 2020 · 13 comments
Closed

Pug support #17

kaangokdemir opened this issue Apr 28, 2020 · 13 comments

Comments

@kaangokdemir
Copy link

Is there anyway to write templates with pug language? npm i pug pug-plain-loader didn't worked for myself.

@zzetao
Copy link
Contributor

zzetao commented Apr 29, 2020

I tried to add the parameter: preprocessLang: template.lang, to SFC compileTemplate and the pug is working.
Wait for @yyx990803 to support this feature. 😋

https://github.com/vuejs/vite/blob/1b0b4ba340b5d552abd7fa0457f9b2de55fc1647/src/node/serverPluginVue.ts#L208-L217

@yyx990803
Copy link
Member

@zzetao PR welcome!

@mccxiv
Copy link

mccxiv commented Jun 4, 2020

Hmm not working for me with npm i pug pug-plain-loader

<template lang="pug">
  div test
</template>
[vite] SFC template compilation error: 

  TypeError: Cannot read property 'start' of undefined
      at C:\Users\<redacted>\node_modules\vite\dist\server\serverPluginVue.js:241:78
      at Array.forEach (<anonymous>)
      at compileSFCTemplate (C:\Users\<redacted>\node_modules\vite\dist\server\serverPluginVue.js:236
:16)
      at C:\Users\<redacted>\node_modules\vite\dist\server\serverPluginVue.js:63:24
      at processTicksAndRejections (internal/process/task_queues.js:97:5)

@yyx990803
Copy link
Member

  1. pug doesn't allow leading whitespace because it's indentation-based
  2. Vue 3 SFC doesn't de-indent <template> content
  3. There's a bug when reporting the error

The following should work

<template lang="pug">
div test
</template>

Also, you don't need pug-plain-loader, just pug is enough

@kaangokdemir
Copy link
Author

Not a big deal I believe but I'm sure in Vue 2 you were able to use Pug with leading whitespace(s). Is the difference between them coming from pug-plain-loader?

@yyx990803
Copy link
Member

yyx990803 commented Jun 4, 2020

This is a behavior change in Vue 3's SFC compiler. Preserving the raw indent avoids the extra cost of de-indenting which can be costly when source map is enabled.

pug-plain-loader is only for webpack and is not needed when using Vite.

@stuta
Copy link

stuta commented Jul 8, 2020

Small bug: div(v-else) fails during vite build, div(v-else-if='true') works.

@kaangokdemir
Copy link
Author

Small bug: div(v-else) fails during vite build, div(v-else-if='true') works.

You can use div(v-else='') instead else-if right now. However div(v-else) is not work currently (except the statements are on root indentation)

And I think the problem is not about vite, it's about @vue/compiler-sfc instead. Maybe @yyx990803 should clarify.

@zeroby0
Copy link

zeroby0 commented Jul 15, 2020

For those who come here via Google,

As of vite v1.0.0-beta.11, run npm install pug --save-dev and that should be enough. Make sure the root element in each SFC is unindented though.

@asmimo
Copy link

asmimo commented Jul 17, 2020

does it effect performance and/or bundle size on production build?

@zeroby0
Copy link

zeroby0 commented Jul 17, 2020

In theory, it shouldn't. But I imagine sourcemaps might be affected.

@seanaye
Copy link

seanaye commented Dec 10, 2020

With a fresh yarn create vite-app my-app cd my-app yarn add pug yarn dev I get the following

[vite] Dep optimization failed with error:  
Could not load path (imported by node_modules/pug/lib/index.js): ENOENT: no such file or directory, open 'path'

@piboistudios
Copy link

piboistudios commented Dec 28, 2020

With a fresh yarn create vite-app my-app cd my-app yarn add pug yarn dev I get the following

[vite] Dep optimization failed with error:  
Could not load path (imported by node_modules/pug/lib/index.js): ENOENT: no such file or directory, open 'path'

Same here:

[vite] Dep optimization failed with error:
Could not load path (imported by node_modules\pug\lib\index.js): ENOENT: no such file or directory, open '<project path>\path'
[Error: Could not load path (imported by node_modules\pug\lib\index.js): ENOENT: no such file or directory, open '<project path>\path'] {
  errno: -4058,
  code: 'ENOENT',
  syscall: 'open',
  path: '<project path>\\path', // this of course does not exist
  watchFiles: [
    // ...watched files...
  ]
}

EDIT:

Actually, this was resolved by uninstalling pug and reinstalling it with the --save-dev flag for me.

@seanaye if its still an issue for you, give that a shot.

@github-actions github-actions bot locked and limited conversation to collaborators Jul 16, 2021
antfu pushed a commit that referenced this issue Oct 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants