webdiscus / pug-plugin

Renders Pug template to HTML or template function. Resolves source files of scripts, styles, images in Pug . Uses Pug template as entry point.
https://webdiscus.github.io/pug-plugin/hello-world
ISC License
74 stars 8 forks source link

pretty option seems to be messing around with inline JS #57

Closed YUCLing closed 1 year ago

YUCLing commented 1 year ago

As I mentioned in https://github.com/webdiscus/pug-plugin/issues/56#issuecomment-1384360526, the inline JS was not working.

By looking through the process that HTML code being processed, I found that Pretty.format turned <script>I:/ulr-loading/test/config.ts</script> into <script>\n I: /ulr-loading/test / config.ts\n </script>.

https://github.com/webdiscus/pug-plugin/blob/29aa357fbf5f0877da5f36e34c41659c60241211/src/AssetScript.js#L146

This is where the JS code being inserted into HTML, but after prettify, the text used to replace was no longer existed.

YUCLing commented 1 year ago

This is the output of inline-script-query test after adding pretty: true

  ● inline style & script › inline script using URL query `?inline`                                                                                                                         

    expect(received).toEqual(expected) // deep equality

    - Expected  -  1
    + Received  + 14

    - <!DOCTYPE html><html><head><title>Test</title><script src="assets/js/main.992ba657.js" defer="defer"></script><script>(()=>{"use strict";console.log(">> inline script from inline-main.js",7)})();</script></head><body><h1>Home</h1></body></html>
    + <!DOCTYPE html>
    + <html>
    +   <head>
    +     <title>Test</title>
    +     <script src="assets/js/main.992ba657.js" defer="defer"></script>
    +     <script>
    +       F: /pug-plugin-master/test / cases / inline - script - query / src / assets / scripts / inline - main.js
    +     </script>
    +   </head>
    +   <body>
      at test (index.test.js:341:3)
      at Object.describe (index.test.js:340:1)

Test Suites: 1 failed, 1 total
Tests:       1 failed, 114 passed, 115 total
Snapshots:   0 total
Time:        22.352 s
webdiscus commented 1 year ago

@YUCLing

thank you for the bug report! I wil fix it.

webdiscus commented 1 year ago

@YUCLing

the issue is fixed in v4.9.1

Thank You!

YUCLing commented 1 year ago

Confirmed. Works perfectly 😄