Gathering detailed insights and metrics for postcss-import
Gathering detailed insights and metrics for postcss-import
Gathering detailed insights and metrics for postcss-import
Gathering detailed insights and metrics for postcss-import
postcss-import-resolver
Customize postcss-import resolve with enhanced-resolve
@types/postcss-import
TypeScript definitions for postcss-import
postcss-import-ext-glob
A PostCSS plugin to extend postcss-import path resolver to allow glob usage as path
postcss-import-alias-resolver
A tool to easily create custom alias resolver for postcss-import
PostCSS plugin to inline at-import rules content
npm install postcss-import
Module System
Unable to determine the module system for this package.
Min. Node Version
Typescript Support
Node Version
NPM Version
1,378 Stars
458 Commits
115 Forks
18 Watching
4 Branches
47 Contributors
Updated on 26 Nov 2024
Minified
Minified + Gzipped
JavaScript (99.07%)
CSS (0.72%)
HTML (0.21%)
Cumulative downloads
Total Downloads
Last day
-1.5%
2,609,678
Compared to previous day
Last week
2.9%
13,773,226
Compared to previous week
Last month
10.2%
57,329,741
Compared to previous month
Last year
29.5%
586,234,611
Compared to previous year
3
1
PostCSS plugin to transform
@import
rules by inlining content.
This plugin can consume local files, node modules or web_modules.
To resolve path of an @import
rule, it can look into root directory
(by default process.cwd()
), web_modules
, node_modules
or local modules.
When importing a module, it will look for index.css
or file referenced in
package.json
in the style
or main
fields.
You can also provide manually multiples paths where to look at.
Notes:
url()
(or
even inline them) after inlining imported files.skipDuplicates
optiondataUrls
plugin option to extend postcss-import.options.filter
or because they are remote
imports) are moved to the top of the output.@import
spec; @import
statements must precede all other statements (besides @charset
).1$ npm install -D postcss-import
Unless your stylesheet is in the same place where you run postcss
(process.cwd()
), you will need to use from
option to make relative imports
work.
1// dependencies 2const fs = require("fs") 3const postcss = require("postcss") 4const atImport = require("postcss-import") 5 6// css to be processed 7const css = fs.readFileSync("css/input.css", "utf8") 8 9// process css 10postcss() 11 .use(atImport()) 12 .process(css, { 13 // `from` option is needed here 14 from: "css/input.css" 15 }) 16 .then((result) => { 17 const output = result.css 18 19 console.log(output) 20 })
css/input.css
:
1/* remote urls are preserved */ 2@import "https://example.com/styles.css"; 3 4/* can consume `node_modules`, `web_modules` or local modules */ 5@import "cssrecipes-defaults"; /* == @import "../node_modules/cssrecipes-defaults/index.css"; */ 6@import "normalize.css"; /* == @import "../node_modules/normalize.css/normalize.css"; */ 7 8@import "foo.css"; /* relative to css/ according to `from` option above */ 9 10/* all standard notations of the "url" value are supported */ 11@import url(foo-1.css); 12@import url("foo-2.css"); 13 14@import "bar.css" (min-width: 25em); 15 16@import 'baz.css' layer(baz-layer); 17 18body { 19 background: black; 20}
will give you:
1@import "https://example.com/styles.css"; 2 3/* ... content of ../node_modules/cssrecipes-defaults/index.css */ 4/* ... content of ../node_modules/normalize.css/normalize.css */ 5 6/* ... content of css/foo.css */ 7 8/* ... content of css/foo-1.css */ 9/* ... content of css/foo-2.css */ 10 11@media (min-width: 25em) { 12/* ... content of css/bar.css */ 13} 14 15@layer baz-layer { 16/* ... content of css/baz.css */ 17} 18 19body { 20 background: black; 21}
Checkout the tests for more examples.
filter
Type: Function
Default: () => true
Only transform imports for which the test function returns true
. Imports for
which the test function returns false
will be left as is. The function gets
the path to import as an argument and should return a boolean.
root
Type: String
Default: process.cwd()
or dirname of
the postcss from
Define the root where to resolve path (eg: place where node_modules
are).
Should not be used that much.
Note: nested @import
will additionally benefit of the relative dirname of
imported files.
path
Type: String|Array
Default: []
A string or an array of paths in where to look for files.
plugins
Type: Array
Default: undefined
An array of plugins to be applied on each imported files.
resolve
Type: Function
Default: null
You can provide a custom path resolver with this option. This function gets
(id, basedir, importOptions, astNode)
arguments and should return a path, an array of
paths or a promise resolving to the path(s). If you do not return an absolute
path, your path will be resolved to an absolute path using the default
resolver.
You can use resolve for this.
load
Type: Function
Default: null
You can overwrite the default loading way by setting this option.
This function gets (filename, importOptions)
arguments and returns content or
promised content.
skipDuplicates
Type: Boolean
Default: true
By default, similar files (based on the same content) are being skipped.
It's to optimize output and skip similar files like normalize.css
for example.
If this behavior is not what you want, just set this option to false
to
disable it.
addModulesDirectories
Type: Array
Default: []
An array of folder names to add to Node's resolver.
Values will be appended to the default resolve directories:
["node_modules", "web_modules"]
.
This option is only for adding additional directories to default resolver. If
you provide your own resolver via the resolve
configuration option above, then
this value will be ignored.
warnOnEmpty
Type: Boolean
Default: true
By default postcss-import
warns when an empty file is imported.
Set this option to false
to disable this warning.
1const postcss = require("postcss") 2const atImport = require("postcss-import") 3 4postcss() 5 .use(atImport({ 6 path: ["src/css"], 7 })) 8 .process(cssString) 9 .then((result) => { 10 const { css } = result 11 })
dependency
Message Supportpostcss-import
adds a message to result.messages
for each @import
. Messages are in the following format:
{
type: 'dependency',
file: absoluteFilePath,
parent: fileContainingTheImport
}
This is mainly for use by postcss runners that implement file watching.
$ npm test
).No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 13/22 approved changesets -- score normalized to 5
Reason
dependency not pinned by hash detected -- score normalized to 2
Details
Reason
0 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-18
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