feat: 支持 vue 的 template 与 js 分开定义的模式(非标准 vue 文件)#491
feat: 支持 vue 的 template 与 js 分开定义的模式(非标准 vue 文件)#491L-H-B-666 wants to merge 1 commit intozh-lx:nextfrom
Conversation
Review Summary by QodoSupport separated Vue template and script file patterns
WalkthroughsDescription• Support separated Vue template and script files via require('./xxx.html')
• Add standalone HTML template transformation with vue-html file type
• Detect and handle HTML files containing Vue template syntax
• Inject data-insp-path attributes into separated HTML templates
Diagramflowchart LR
A["HTML file via require"] --> B["Webpack loader detects standalone HTML"]
B --> C["transformCode with vue-html type"]
C --> D["transformVueHtml parses template"]
D --> E["Inject data-insp-path attributes"]
E --> F["Return transformed HTML"]
File Changes1. packages/webpack/src/index.ts
|
Code Review by Qodo
1. Match overridden when html
|
| test: matchIncludesHtml | ||
| ? /\.(vue|jsx|tsx|js|ts|mjs|mts|svelte)$/ | ||
| : matchPattern, |
There was a problem hiding this comment.
1. Match overridden when html 🐞 Bug ✓ Correctness
When options.match includes .html, the webpack plugin replaces the user-provided match regex with a hard-coded default for the main rule, which can silently stop transforming user-intended file types (or start transforming unintended ones). This breaks the documented contract that match controls which files participate in transformation.
Agent Prompt
## Issue description
When `options.match` includes `.html`, the webpack rules currently replace the user's `match` regex with a fixed default regex for the main transform rule. This breaks user configuration and can skip intended files.
## Issue Context
`CodeOptions.match` is documented as the controlling filter for which files participate in transformation.
## Fix Focus Areas
- packages/webpack/src/index.ts[40-84]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| // Determine the file match pattern, supporting both default and user-configured patterns | ||
| const matchPattern = options.match ?? /\.(vue|jsx|tsx|js|ts|mjs|mts|svelte)$/; | ||
| // Check if user's match pattern includes .html | ||
| const matchIncludesHtml = matchPattern instanceof RegExp && matchPattern.test('.html'); |
There was a problem hiding this comment.
2. Html detection uses test('.html') 🐞 Bug ⛯ Reliability
The code decides whether .html is included by running RegExp.test('.html'), which is unreliable
for path-scoped regexes (e.g. /src\/.*\.html$/) and can prevent enabling the standalone html rule
and/or the loader’s standalone branch. This can make the new feature silently not work for common
match patterns.
Agent Prompt
## Issue description
Determining whether HTML is enabled via `RegExp.test('.html')` is brittle for path-scoped `options.match` patterns and can disable the feature unexpectedly.
## Issue Context
Other bundlers in this repo apply `options.match` to the real file path. Webpack path matching should behave similarly.
## Fix Focus Areas
- packages/webpack/src/index.ts[40-44]
- packages/webpack/src/loader.ts[79-94]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
code-inspector-plugin 支持分离式 Vue HTML 模板文件
问题
某些项目中 Vue 代码采用
.js+.html分离式写法,HTML 模板通过require("./xxx.html")引入。code-inspector-plugin无法为这类 HTML 模板文件注入data-insp-path定位属性。根因
插件的 webpack loader 对
.html文件只处理带?vue&type=templatequery 的情况(通过 vue-loader 的 SFC 机制),直接require的 HTML 文件不会触发转换。修改文件
packages/webpack/src/index.ts- 新增独立.html文件的 loader 规则(enforce: 'pre')packages/webpack/src/loader.ts- 新增isStandaloneHtmlTemplate判断分支packages/core/src/server/transform/index.ts- 新增vue-html文件类型处理packages/core/src/server/transform/transform-vue.ts- 新增transformVueHtml函数