File tree Expand file tree Collapse file tree 1 file changed +27
-16
lines changed Expand file tree Collapse file tree 1 file changed +27
-16
lines changed Original file line number Diff line number Diff line change 11import MagicString from 'magic-string'
22import { createUnplugin } from 'unplugin'
33
4+ const ID_INCLUDE = / \. v u e $ /
5+ const ID_EXCLUDE = / n o d e _ m o d u l e s /
46export const InjectHydrationPlugin = createUnplugin ( ( ) => {
57 return {
68 name : '@nuxt/hints:inject-hydration-check' ,
79 enforce : 'pre' ,
810 transformInclude ( id ) {
911 return id . endsWith ( '.vue' ) && ! id . includes ( 'node_modules' )
1012 } ,
11- transform ( code ) {
12- const m = new MagicString ( code )
13- const re = / < s c r i p t \s + s e t u p [ ^ > ] * > / g
14- const match = re . exec ( code )
15- if ( ! match ) {
16- return code
17- }
13+ transform : {
14+ filter : {
15+ id : {
16+ include : ID_INCLUDE ,
17+ exclude : ID_EXCLUDE ,
18+ } ,
19+ } ,
1820
19- // Add useHydrationCheck after the <script setup> tag
20- m . appendRight (
21- match . index + match [ 0 ] . length ,
22- `\nimport { useHydrationCheck } from '@nuxt/hints/runtime/hydration/composables'\nuseHydrationCheck();` ,
23- )
21+ handler ( code ) {
22+ const m = new MagicString ( code )
23+ const re = / < s c r i p t \s + s e t u p [ ^ > ] * > / g
24+ const match = re . exec ( code )
25+ if ( ! match ) {
26+ return code
27+ }
2428
25- return {
26- code : m . toString ( ) ,
27- map : m . generateMap ( { hires : true } ) ,
28- }
29+ // Add useHydrationCheck after the <script setup> tag
30+ m . appendRight (
31+ match . index + match [ 0 ] . length ,
32+ `\nimport { useHydrationCheck } from '@nuxt/hints/runtime/hydration/composables'\nuseHydrationCheck();` ,
33+ )
34+
35+ return {
36+ code : m . toString ( ) ,
37+ map : m . generateMap ( { hires : true } ) ,
38+ }
39+ } ,
2940 } ,
3041 }
3142} )
You can’t perform that action at this time.
0 commit comments