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

Ability to pass dependency when styles are being processed #417

Closed
1 of 3 tasks
gavinmcfarland opened this issue Sep 13, 2019 · 5 comments · Fixed by #448
Closed
1 of 3 tasks

Ability to pass dependency when styles are being processed #417

gavinmcfarland opened this issue Sep 13, 2019 · 5 comments · Fixed by #448

Comments

@gavinmcfarland
Copy link

gavinmcfarland commented Sep 13, 2019

Proposal

Allow dependencies to be set, so the styles being processed have access to things like global variables, class names, mixins etc.

Use Case

I’m using VuePress with PostCSS which uses postcss-loader. I want to avoid having to @import the same file in each of my components when using libraries like TailwindCSS. I've had the same use case with other frameworks. I can't find the documentation but I've heard this being known as a dependency inside a webpack loader.

Implementation

  • I'm open to work on this
  • I need help/mentorship
  • I'm unable to work on this
@alexander-akait
Copy link
Member

@limitlessloop can you provide minimum reproducible test repo to ensure all logic will implement?

@gavinmcfarland
Copy link
Author

Yeah I'll try my best. I'll put one together now.

@gavinmcfarland
Copy link
Author

@evilebottnawi I've uploaded an example the best I can at https://github.com/limitlessloop/vuepress-postcss-example

VuePress has a config file /site/.vuepress/config.js where you can specify information for different loaders. I believe there are two ways to specify preprocessors, I've tried to show any documentation I know of that describes this in the readme of the repo. I'm using just the simpler method currently.

// config.js
module.exports = {
	postcss: {
		plugins: [
			require('postcss-import'),
			require('postcss-extend-rule')
		]
	}
}

@alexander-akait
Copy link
Member

alexander-akait commented Aug 14, 2020

There are two way to add dependencies:

  1. postcss plugin should emit message https://github.com/webpack-contrib/postcss-loader/blob/master/src/index.js#L193:
result.messages.push({ type: 'dependency', file: '/path/to/file.ext' })
  1. use this.webpack inside config (it is loader context) and pass this.webpack.addDependency as function to plugin
require('postcss-plugin')({ addDependecy: this.webpack.addDependency });

In both cases you need to do some work on a plugin side

@alexander-akait
Copy link
Member

We should document it

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

Successfully merging a pull request may close this issue.

2 participants