borodean / postcss-assets

An asset manager for PostCSS
MIT License
537 stars 32 forks source link

loadPaths should be able to handle glob #40

Closed aegyed91 closed 8 years ago

aegyed91 commented 8 years ago

Hi @borodean, I think the loadPaths option does not handle glob patterns. It would be an useful feature i think.

assets({
  basePath: config.SRC_DIR,
  loadPaths: [path.join(config.DEST_DIR, '**/*')],
  relativeTo: 'public/css'
})
[21:54:48] Starting 'css'...

events.js:141
      throw er; // Unhandled 'error' event
      ^
Error: postcss-assets: /Users/tsm/Sites/__projects/gulp-starter/src/css/main.css:2:3: Asset not found or unreadable: sample.jpeg
Load paths:
  /Users/tsm/Sites/__projects/gulp-starter/src
  /Users/tsm/Sites/__projects/gulp-starter/public/**/*
.sample-bg-image {
  background-image: resolve("sample.jpeg"); }
borodean commented 8 years ago

@tsm91 whats the use case of this?

aegyed91 commented 8 years ago

@borodean if you have an asset-pipeline which is project-structure agnostic like this.

In my case it doesn't cause any problems because the images gulp task will copy the image from anywhere to public/images but only because i use gulp-flatten and because of the file watcher.

But i am sure there will be scenarios for other people when they would like to do something like src/**/* or dist/**/*.

dan-gamble commented 8 years ago

I've just hit this myself as well, since we break things out into small modules we don't have a single root of assets anymore.

Being able to use: name/apps/*/img/ would be sweet :)

borodean commented 8 years ago

@tsm91 @dan-gamble here you go: introduced in 4.0.0.

dan-gamble commented 8 years ago

Awesome <3

aegyed91 commented 8 years ago

cool, thanks

borodean commented 8 years ago

@tsm91 @dan-gamble btw, the plugin now accepts a single string as a loadPaths option, so instead of this:

loadPaths: ['assets/**/img']

You can also write this:

loadPaths: 'assets/**/img'
dan-gamble commented 8 years ago

Thanks for the heads up :)

anotherWill commented 6 years ago

Hi @borodean, how to write the options about this url. appName/src/assets/images/test.png and css in appName/src/assets/css/main.css resolve('test.png') I try it a long time and throw error. Assets not found or unreadable

borodean commented 6 years ago

@anotherWill well, I assume something like this should work:

loadPaths: 'appName/src/assets/images'