Repository navigation
[Experiment] Allow @apply-ing utility classes that aren't explicitly defined but would be generated - #516
Conversation
|
I'm trying to get this working with Laravel Mix, but without success. Is any additional setup required outside of adding the // ...
options: {
prefix: '',
important: false,
separator: ':',
},
experiments: {
shadowLookup: true,
},
};In a Vue component, I have this style block: <style lang="postcss">
.card-chart {
@apply rounded;
/* ... */
}
</style>The generated styles include the unprocessed I'm using Tailwind v0.6.3, and I tried adding the plugins key to the Webpack config. It seems like I should somehow pass the tailwind config to the // ...
mix
.webpackConfig({
plugins: [tailwindcss('./tailwind.js')],
resolve: {
modules: [
path.resolve(__dirname),
path.resolve('./resources/assets/js'),
path.resolve('./node_modules'),
],
},
})
.js('resources/assets/js/app.js', 'public/js').sourceMaps()
.postCss('resources/assets/css/main.css', 'public/css', [
postcssImport(),
tailwindcss('./tailwind.js'),
])
.sourceMaps()
.purgeCss();Before I added the |
|
@curtisblackwell The problem in this case is your mix configuration. If you use the To configure those PostCSS plugins for all processed CSS, use the // ...
mix
.webpackConfig({
plugins: [tailwindcss('./tailwind.js')],
resolve: {
modules: [
path.resolve(__dirname),
path.resolve('./resources/assets/js'),
path.resolve('./node_modules'),
],
},
})
.js('resources/assets/js/app.js', 'public/js').sourceMaps()
- .postCss('resources/assets/css/main.css', 'public/css', [
- postcssImport(),
- tailwindcss('./tailwind.js'),
- ])
+ .postCss('resources/assets/css/main.css', 'public/css')
+ .options({
+ postCss: [
+ postcssImport(),
+ tailwindcss('./tailwind.js'),
+ ]
+ })
.sourceMaps()
.purgeCss(); |
|
That fixed it, thanks! |
|
Stopping by, just to say this feature is great. I work with Vue, and it's exactly what I needed. Thanks! |
* No longer using external css component. * Found out that @apply directly can now be used inside <style> tags in Vue components. * tailwindlabs/tailwindcss#516
|
Is this still an experiment or is it production ready? I assume it is production ready as it was merged over 1 year ago but there's no documentation about it so I'm unsure if I should use it or not. |
|
It's on by default for a while now, don't need to configure it. |
Resolves #150.
This PR introduces a solution to the long-standing problem of wanting to use
@applywith classes that don't exist in the same CSS tree.This issue most commonly comes up when someone is working with Vue and wants to use
@applyin the<style>block of a single file Vue component. It seems like basically every Vue project is setup to run PostCSS on every<style>block independently instead of on the final concatenated CSS, which means if you have 100 components, Tailwind is run 100 independent times, and each run is isolated and can't see any of the classes in the other runs.This PR solves this by always generating all of Tailwind's utilities (including those registered by plugins) and using it as a fallback table for
@applyif the class can't be found.I'm not ready to fully commit to this without getting folks to try it out and report feedback, so this PR only enables this functionality if you add an
experimentskey to your Tailwind config file:Because this is an opt-in experiment, it's going to remain undocumented outside of this PR for now, and I reserve the right to yank it or break it without following semver, so please don't rely on this functionality for production sites right now, just test it out locally and give me your feedback.