Gathering detailed insights and metrics for postcss-assets
Gathering detailed insights and metrics for postcss-assets
Gathering detailed insights and metrics for postcss-assets
Gathering detailed insights and metrics for postcss-assets
postcss-import
PostCSS plugin to import CSS files
browserslist
Share target browsers between different front-end tools, like Autoprefixer, Stylelint and babel-env-preset
postcss-assets-rebase
PostCSS plugin to rebase assets to specified folder.
postcss-assets-webpack-plugin
Webpack plugin to apply postcss on webpack's emit event
npm install postcss-assets
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
537 Stars
327 Commits
32 Forks
10 Watching
6 Branches
9 Contributors
Updated on 06 Jul 2024
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-19.8%
5,555
Compared to previous day
Last week
-6.1%
28,621
Compared to previous week
Last month
-3.1%
128,011
Compared to previous month
Last year
3.8%
1,597,615
Compared to previous year
2
1
PostCSS Assets is an asset manager for CSS. It isolates stylesheets from environmental changes, gets image sizes and inlines files.
By using this project or its source code, for any purpose and in any shape or form, you grant your implicit agreement to all the following statements:
Glory to Ukraine! đŸ‡ºđŸ‡¦
1npm install postcss-assets --save-dev
1gulp.task('assets', function () { 2 var postcss = require('gulp-postcss'); 3 var assets = require('postcss-assets'); 4 5 return gulp.src('source/*.css') 6 .pipe(postcss([assets({ 7 loadPaths: ['images/'] 8 })])) 9 .pipe(gulp.dest('build/')); 10});
1var assets = require('postcss-assets'); 2 3grunt.initConfig({ 4 postcss: { 5 options: { 6 processors: [ 7 assets({ 8 loadPaths: ['images/'] 9 }) 10 ] 11 }, 12 dist: { src: 'build/*.css' } 13 }, 14});
Note: all of the listed options below are parameters for the assets
object, not the top level postcss options object.
These options isolate stylesheets from environmental changes.
To make PostCSS Assets search for files in specific directories, define load paths:
1var options = { 2 loadPaths: ['fonts/', 'media/patterns/', 'images/'] 3};
Example:
1body { 2 background: resolve('foobar.jpg'); 3 background: resolve('icons/baz.png'); 4}
PostCSS Assets would look for the files relative to the source file, then in load paths, then in the base path. If it succeed, it would resolve a true URL:
1body { 2 background: url('/media/patterns/foobar.jpg'); 3 background: url('/images/icons/baz.png'); 4}
If the root directory of your site is not where you execute PostCSS Assets, correct it:
1var options = { 2 basePath: 'source/' 3};
PostCSS Assets would treat source
directory as /
for all URLs and load paths would be relative to it.
If the URL of your base path is not /
, correct it:
1var options = { 2 baseUrl: 'http://example.com/wp-content/themes/' 3};
To make resolved paths relative to the input file, set a flag:
1var options = { 2 relative: true 3};
To relate to a particular directory, set it as a string:
1var options = { 2 relative: 'assets/css' 3};
PostCSS Assets can bust assets cache:
1var options = { 2 cachebuster: true 3};
Example:
1body { 2 background: resolve('/images/icons/baz.png'); 3}
PostCSS Assets will change urls depending on asset’s modification date:
1body { 2 background: url('/images/icons/baz.png?14a931c501f'); 3}
To define a custom cachebuster pass a function as an option:
1var options = { 2 cachebuster: function (filePath, urlPathname) { 3 return fs.statSync(filePath).mtime.getTime().toString(16); 4 } 5};
If the returned value is falsy, no cache busting is done for the asset.
If the returned value is an object the values of pathname
and/or query
are used to generate a cache busted path to the asset.
If the returned value is a string, it is added as a query string.
The returned values for query strings must not include the starting ?
.
Busting the cache via path:
1var options = { 2 cachebuster: function (filePath, urlPathname) { 3 var hash = fs.statSync(filePath).mtime.getTime().toString(16); 4 return { 5 pathname: path.dirname(urlPathname) 6 + '/' + path.basename(urlPathname, path.extname(urlPathname)) 7 + hash + path.extname(urlPathname), 8 query: false // you may omit this one 9 } 10 } 11};
PostCSS Assets calculates dimensions of PNG, JPEG, GIF, SVG and WebP images:
1body { 2 width: width('images/foobar.png'); /* 320px */ 3 height: height('images/foobar.png'); /* 240px */ 4 background-size: size('images/foobar.png'); /* 320px 240px */ 5}
To correct the dimensions for images with a high density, pass it as a second parameter:
1body { 2 width: width('images/foobar.png', 2); /* 160px */ 3 height: height('images/foobar.png', 2); /* 120px */ 4 background-size: size('images/foobar.png', 2); /* 160px 120px */ 5}
PostCSS inlines files to a stylesheet in Base64 encoding:
1body { 2 background: inline('images/foobar.png'); 3}
SVG files would be inlined unencoded, because then they benefit in size.
Option | Description | Default |
---|---|---|
basePath | Root directory of the project. | . |
baseUrl | URL of the project when running the web server. | / |
cachebuster | If cache should be busted. Pass a function to define custom busting strategy. | false |
loadPaths | Specific directories to look for the files. | [] |
relative | Directory to relate to when resolving URLs. When true , relates to the input file. When false , disables relative URLs. | false |
cache | When true , if the input file not been modifed, use the results before cached. | false |
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 3/16 approved changesets -- score normalized to 1
Reason
project is archived
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
22 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More