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(core)!: add content
option
#2503
Conversation
✅ Deploy Preview for unocss ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
I am ok with this refactoring to make options more scoped. But I think we need to make it clear that UnoCSS works differently from Tailwind, that we read "content" from the build pipeline, not from the filesystem manually. So I'd suggest we drop the shorthand of providing an array directly, and name {
content: {
filesystem: ['**/foo/**.vue'],
pipeline: {
include: [],
exclude: []
}
}
} {
content: {
filesystem: {
glob: ['**/foo/**.vue'],
exclude: [] // tho I doubt if this is necessary
},
pipeline: false // disable reading from pipeline, relying on fs solely,
text: [`some content to extra`]
}
} |
This is only true for Vite plugin,
We should make it clear only on documentation. I don't think end users will ever need to know that until they have to deal with query parameters that passed along paths. For example:
These patterns will not be matched by any glob patterns. Because glob patterns compiled to something like that: Also, I would like the mention one thing I did that may not be obvious from the changes. Glob patterns also passed to
I'm strongly against that suggestion. Most of the time people will not ever need to configure this option. When they have to, simply providing an array of glob patterns seems pleasing to me as a user. And Tailwind team thinking of making My goals with these changes were:
|
Actually, this is part of the design phoilshpy of UnoCSS, is that we could do that whenever possible. I understand it's not possible for PostCSS plugin, and I think that makes sense. But in that sense, it's actually "This is only false for PostCSS plugin".
So you see I am trying to make the interface generic for both cases. You could say
If we say most of ppl don't need it, then it actually makes less sense to me to make it "easier". My question is that if we put
Either way, I think they will have different semantic meanings across Vite and PostCSS. I admit that "extraContent" can be a bit not fair to PostCSS, so I agree with this renaming to make it general.
Maybe we are biased? People would ask simple questions without looking into the docs anyway, they would keep asking why |
c99e9d0
to
009d9bd
Compare
@antfu I updated PR with your suggestions. There is still some work to do. I just want to finalize the API. This is the current type of export type FilterPattern = ReadonlyArray<string | RegExp> | string | RegExp | null
export interface ConfigBase<Theme extends {} = {}> {
content?: {
filesystem?: string[]
plain?: (string | { content: string; extension: string })[]
pipeline?: {
include?: FilterPattern
exclude?: FilterPattern
}
}
} |
// @ts-expect-error private | ||
if (config.__postcss) | ||
content.filesystem ||= defaultIncludeGlobs |
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.
Could this be outside of the core? Or maybe the entire content
config could be outside and up to the integrations to resolve
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.
Yes, I will move it to the PostCSS plugin.
/** | ||
* Patterns that filter the files being extracted. | ||
*/ | ||
include?: FilterPattern |
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.
We better keep those types, but make as deprecated to say "use xxx instead"
export const defaultInclude: Exclude<FilterPattern, null> = [/\.(vue|svelte|[jt]sx|mdx?|astro|elm|php|phtml|html)($|\?)/] | ||
|
||
// micromatch patterns, used in postcss plugin and createFilter | ||
export const defaultIncludeGlobs = ['./**/*.{html,js,ts,jsx,tsx,vue,svelte,astro,elm,php,phtml,mdx,md}'] |
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.
I feel they are better to live in shared-integrations
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.
I was getting an error during the production build. This is why I moved them there. I will give it a look again.
/** | ||
* Plain text to be extracted | ||
*/ | ||
plain?: (string | { content: string; extension: string })[] |
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.
plain?: (string | { content: string; extension: string })[] | |
plain?: (string | { content: string; id: string })[] |
Maybe we could name it id
to align with the pipeline and allow to pass a path
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.
I wouldn't suggest doing that. It would be confusing in many ways. Let's say we have 2 plain content objects with id
property. What id
should be? A path, relative or absolute, should it exist in fs or just an extension? And most importantly id
s should be unique, This will force people to think of a unique name for their id
s. We somewhat forcing them to overthink. extension
name clearly shows all we need is an extension.
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.
It's sometimes about extensions. Extractors can check the module id and apply conditionally based on it (under certain folders, or conventions). For example, in Vue we will have
foo.vue
foo.vue?vue&type=template&lang=pug
foo.vue?vue&type=style&lang=css
If I want to apply transformation before passing the extractor, I will need to compile the pug template to HTML, in this case, extension
can be limited.
Maybe this would not be used often, but being able to pass the full path (it's always named as id
in other places) would make it extendable in the future and more consistent across the pipeline.
If you are concerned about the understanding, I think we could document to explain it in jsdocs or the docs site.
plain?: (string | { content: string; extension: string })[] | ||
|
||
/** | ||
* Options used by Vite to filter processing files. |
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.
* Options used by Vite to filter processing files. | |
* Filter to determine whether to extract certain modules from the build tools' transformation pipeline |
/** | ||
* Glob patterns to extract th classes from. | ||
* | ||
* In Vite plugin, this patterns only used to extract classes | ||
* from the files that is not part of the build pipeline. | ||
* | ||
* In PostCSS plugin, files to be scanned are determined by | ||
* the glob patterns defined in this option. | ||
*/ |
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.
/** | |
* Glob patterns to extract th classes from. | |
* | |
* In Vite plugin, this patterns only used to extract classes | |
* from the files that is not part of the build pipeline. | |
* | |
* In PostCSS plugin, files to be scanned are determined by | |
* the glob patterns defined in this option. | |
*/ | |
/** | |
* Glob patterns to extract from the file system. | |
*/ |
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.
IMO we should clarify its behavior in Vite. Otherwise, people will be confused about why transform plugins are not working on those files.
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.
What I am thinking it that the content
itself indicates multiple sources to read from. We could say pipeline
source is only supported in Vite and Webpack but not in PostCSS, etc.
@@ -313,6 +313,39 @@ export type Postprocessor = (util: UtilObject) => void | |||
export type ThemeExtender<T> = (theme: T) => T | void | |||
|
|||
export interface ConfigBase<Theme extends {} = {}> { | |||
content?: { |
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.
content?: { | |
/** | |
* Sources of the content of UnoCSS to extract from. | |
* The support of the sources depends on the integration you are using. | |
* Please refer to their documentation to learn the usage. | |
*/ | |
content?: { |
I would love to help moving this forward, let me how I can help on it. |
Todos:
By extracting the changes in the |
content
optioncontent
option
TODO:
Breaking changes:
content
option removedcontent
option added (similar to https://tailwindcss.com/docs/content-configuration)include
andexclude
options moved to content optionextraContent
removed, functionality moved tocontent
option