Skip to content
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

feat(exposeConfig): nested properties #583

Merged
merged 12 commits into from Jan 25, 2023
Merged

feat(exposeConfig): nested properties #583

merged 12 commits into from Jan 25, 2023

Conversation

ineshbose
Copy link
Collaborator

@ineshbose ineshbose commented Dec 20, 2022

While working on #582, I've also looked into how to create exports for nested properties in the large tailwind configuration, and these properties can be accessed using exports in camelCase. There have been use-cases (for me at least) where I need a small part of the configuration, such as theme.screens or theme.colors.neutral instead of all of theme (which is quite big), so I can just do

import { themeScreens, themeColorsNeutral } from '#tailwind-config'

and that should do it!

I believe this isn't a major requirement right now, and may need feedback as well (hence I'm also putting this as a draft PR).

Edit: see changes at this point through - main...ineshbose:nuxt-tailwindcss-module:ba8bf7e2f3e1d907e0ab7b1a29a03dfd6d0bcde7

@ineshbose
Copy link
Collaborator Author

If this approach isn't desirable, potentially this can be altered to have each object as a module (eg #tailwind-config/theme)?

nuxt.options.alias['#tailwind-config'] = template.dst

@ineshbose
Copy link
Collaborator Author

ineshbose commented Dec 21, 2022

Refactored to use templates instead (still need to look into type declarations). Example usage would be:

import screens from '#tailwind-config/theme/screens' // or import { _screens } from '#tailwind-config/theme'
import neutral from '#tailwind-config/theme/colors/neutral' // or import { _neutral } from '#tailwind-config/theme/colors'

Admittedly, these are a lot of files, so the previous approach can be considered if required.

Note: import { theme, content, /* etc */ } from '#tailwind-config' remain valid.

@ineshbose
Copy link
Collaborator Author

Updated function to allow developers to choose how deep they want the templates to go. There's also a commented-out condition that can give the option to not create exports for single non-object values if required (tried to merge it with the previous condition using Object.entries(value) but doesn't work).

src/module.ts Outdated Show resolved Hide resolved
@Atinux
Copy link
Collaborator

Atinux commented Jan 16, 2023

Sorry for the late answer, updated the level to start a 1 (which makes sense IMO, 0 being the whole tailwind.config).

This means tat exposeLevel: 2 will expose
CleanShot 2023-01-16 at 17 30 56@2x

And more, easy to check with http://localhost:3000/_vfs

I am happy with current state, could you please update the documentation to explain those changes and the benefits of it please?

@Atinux Atinux marked this pull request as ready for review January 16, 2023 16:31
@nuxt-studio-dev
Copy link

nuxt-studio-dev bot commented Jan 16, 2023

Deploy Preview for tailwindcss ready!

Name Link
🔨 Latest commit f1296b3
😎 Deploy Preview https://tailwindcss.nuxt.dev?preview=d5eb868da46c169cefff2d0db0b5c38f

@ineshbose
Copy link
Collaborator Author

ineshbose commented Jan 16, 2023

Updated docs (also for inclusive language), and added a test. My concern is still with type definitions I feel!

Edit: I've reverted the changes to the .d.ts file contents, so the nested imports would be untyped - adding type support for them could be a separate PR if you'd like.

Also want to confirm about #tailwind-config/* pointing to .nuxt/tailwind.config/* rather than .nuxt/tailwind.config.mjs (for eg, test import { _slate } from '#tailwind-config/theme/colors' in playground/pages/index.vue and see if you get an error).

test/basic.test.ts Outdated Show resolved Hide resolved
@Atinux Atinux merged commit e88c23a into nuxt-modules:main Jan 25, 2023
@Atinux
Copy link
Collaborator

Atinux commented Jan 25, 2023

Beautiful work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants