-
Notifications
You must be signed in to change notification settings - Fork 228
feat: 支持 vue 的 template 与 js 分开定义的模式(非标准 vue 文件) #491
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
Open
L-H-B-666
wants to merge
1
commit into
zh-lx:next
Choose a base branch
from
L-H-B-666:next
base: next
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,11 @@ | ||
| import { EscapeTags } from '../../shared'; | ||
| export declare function transformVue(content: string, filePath: string, escapeTags: EscapeTags): string; | ||
| /** | ||
| * Transform standalone HTML template files used as Vue templates. | ||
| * These are .html files that contain Vue template syntax and are loaded via | ||
| * require('./xxx.html') rather than through vue-loader's SFC mechanism. | ||
| * | ||
| * Unlike transformVue which handles full .vue SFC files, this function | ||
| * directly parses the HTML content as a Vue template fragment. | ||
| */ | ||
| export declare function transformVueHtml(content: string, filePath: string, escapeTags: EscapeTags): string; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,6 +37,11 @@ const applyLoader = (options: LoaderOptions, compiler: any) => { | |
| const module = _compiler?.options?.module; | ||
| /* v8 ignore next -- fallback for legacy webpack versions with module.loaders */ | ||
| const rules = module?.rules || module?.loaders || []; | ||
| // 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'); | ||
|
|
||
| rules.push( | ||
| { | ||
| test: options.match ?? /\.html$/, | ||
|
|
@@ -49,8 +54,26 @@ const applyLoader = (options: LoaderOptions, compiler: any) => { | |
| ], | ||
| ...(options.enforcePre === false ? {} : { enforce: 'pre' }), | ||
| }, | ||
| // If user's match pattern includes .html, add a separate rule for standalone .html files | ||
| // These are HTML template files used as Vue templates via require('./xxx.html') | ||
| ...(matchIncludesHtml | ||
| ? [ | ||
| { | ||
| test: /\.html$/, | ||
| use: [ | ||
| { | ||
| loader: path.resolve(compatibleDirname, `./loader.js`), | ||
| options, | ||
| }, | ||
| ], | ||
| ...(options.enforcePre === false ? {} : { enforce: 'pre' }), | ||
| }, | ||
| ] | ||
| : []), | ||
| { | ||
| test: /\.(vue|jsx|tsx|js|ts|mjs|mts|svelte)$/, | ||
| test: matchIncludesHtml | ||
| ? /\.(vue|jsx|tsx|js|ts|mjs|mts|svelte)$/ | ||
| : matchPattern, | ||
|
Comment on lines
+74
to
+76
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1. Match overridden when html 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
|
||
| use: [ | ||
| { | ||
| loader: path.resolve(compatibleDirname, `./loader.js`), | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2. Html detection uses test('.html')
🐞 Bug⛯ ReliabilityThe 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
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools