@@ -42,7 +42,7 @@ const unsafeInlineConfig = (inlineConfig: ModuleOptions['config']) => {
42
42
}
43
43
44
44
if ( inlineConfig . content ) {
45
- const invalidProperty = [ 'extract' , 'transform' ] . find ( ( i ) => i in inlineConfig . content ! && typeof inlineConfig . content ! [ i as keyof ModuleOptions [ 'config' ] [ 'content' ] ] === 'function' )
45
+ const invalidProperty = [ 'extract' , 'transform' ] . find ( i => i in inlineConfig . content ! && typeof inlineConfig . content ! [ i as keyof ModuleOptions [ 'config' ] [ 'content' ] ] === 'function' )
46
46
47
47
if ( invalidProperty ) {
48
48
return `content.${ invalidProperty } `
@@ -51,7 +51,7 @@ const unsafeInlineConfig = (inlineConfig: ModuleOptions['config']) => {
51
51
52
52
if ( inlineConfig . safelist ) {
53
53
// @ts -expect-error `s` is never
54
- const invalidIdx = inlineConfig . safelist . findIndex ( ( s ) => typeof s === 'object' && s . pattern instanceof RegExp )
54
+ const invalidIdx = inlineConfig . safelist . findIndex ( s => typeof s === 'object' && s . pattern instanceof RegExp )
55
55
56
56
if ( invalidIdx > - 1 ) {
57
57
return `safelist[${ invalidIdx } ]`
@@ -158,32 +158,34 @@ const createInternalContext = async (moduleOptions: ModuleOptions, nuxt = useNux
158
158
return tailwindConfig
159
159
}
160
160
161
- const generateConfig = ( ) => enableHMR ? addTemplate ( {
162
- filename : CONFIG_TEMPLATE_NAME ,
163
- write : true ,
164
- getContents : ( ) => {
165
- const serializeConfig = < T extends Partial < TWConfig > > ( config : T ) =>
166
- JSON . stringify (
167
- Array . isArray ( config . plugins ) && config . plugins . length > 0 ? configMerger ( { plugins : ( defaultPlugins : TWConfig [ 'plugins' ] ) => defaultPlugins ?. filter ( p => p && typeof p !== 'function' ) } , config ) : config ,
168
- ( _ , v ) => typeof v === 'function' ? `() => (${ JSON . stringify ( v ( ) ) } )` : v
169
- ) . replace ( / " ( \( \) = > \( .* \) ) " / g, ( _ , substr ) => substr . replace ( / \\ " / g, '"' ) )
170
-
171
- const layerConfigs = configPaths . map ( ( configPath ) => {
172
- const configImport = `require(${ JSON . stringify ( / [ / \\ ] n o d e _ m o d u l e s [ / \\ ] / . test ( configPath ) ? configPath : './' + relative ( nuxt . options . buildDir , configPath ) ) } )`
173
- return configUpdatedHook [ configPath ] ? configUpdatedHook [ configPath ] . startsWith ( 'return {};' ) ? '' : `(() => {const cfg=configMerger(undefined, ${ configImport } );${ configUpdatedHook [ configPath ] } ;return cfg;})()` : configImport
174
- } ) . filter ( Boolean )
175
-
176
- return [
161
+ const generateConfig = ( ) => enableHMR
162
+ ? addTemplate ( {
163
+ filename : CONFIG_TEMPLATE_NAME ,
164
+ write : true ,
165
+ getContents : ( ) => {
166
+ const serializeConfig = < T extends Partial < TWConfig > > ( config : T ) =>
167
+ JSON . stringify (
168
+ Array . isArray ( config . plugins ) && config . plugins . length > 0 ? configMerger ( { plugins : ( defaultPlugins : TWConfig [ 'plugins' ] ) => defaultPlugins ?. filter ( p => p && typeof p !== 'function' ) } , config ) : config ,
169
+ ( _ , v ) => typeof v === 'function' ? `() => (${ JSON . stringify ( v ( ) ) } )` : v ,
170
+ ) . replace ( / " ( \( \) = > \( .* \) ) " / g, ( _ , substr ) => substr . replace ( / \\ " / g, '"' ) )
171
+
172
+ const layerConfigs = configPaths . map ( ( configPath ) => {
173
+ const configImport = `require(${ JSON . stringify ( / [ / \\ ] n o d e _ m o d u l e s [ / \\ ] / . test ( configPath ) ? configPath : './' + relative ( nuxt . options . buildDir , configPath ) ) } )`
174
+ return configUpdatedHook [ configPath ] ? configUpdatedHook [ configPath ] . startsWith ( 'return {};' ) ? '' : `(() => {const cfg=configMerger(undefined, ${ configImport } );${ configUpdatedHook [ configPath ] } ;return cfg;})()` : configImport
175
+ } ) . filter ( Boolean )
176
+
177
+ return [
177
178
`// generated by the @nuxtjs/tailwindcss <https://github.com/nuxt-modules/tailwindcss> module at ${ ( new Date ( ) ) . toLocaleString ( ) } ` ,
178
179
`const configMerger = require(${ JSON . stringify ( createResolver ( import . meta. url ) . resolve ( './runtime/merger.mjs' ) ) } );` ,
179
180
`\nconst inlineConfig = ${ serializeConfig ( moduleOptions . config as Partial < TWConfig > ) } ;\n` ,
180
181
'const config = [' ,
181
182
layerConfigs . join ( ',\n' ) ,
182
183
`].reduce((prev, curr) => configMerger(curr, prev), configMerger(inlineConfig, { content: ${ JSON . stringify ( contentPaths ) } }));\n` ,
183
184
`module.exports = ${ configUpdatedHook [ 'main-config' ] ? `(() => {const cfg=config;${ configUpdatedHook [ 'main-config' ] } ;return cfg;})()` : 'config' } \n` ,
184
- ] . join ( '\n' )
185
- } ,
186
- } ) : { dst : '' }
185
+ ] . join ( '\n' )
186
+ } ,
187
+ } )
188
+ : { dst : '' }
187
189
188
190
const registerHooks = ( ) => {
189
191
if ( ! enableHMR ) return
0 commit comments