@csstools/sass-import-resolve

中文文档
1.0.0发布于 2017/12/07CC0-1.0ESM + CJS零依赖近 30 天下载 76万

An algorithm for resolving imports in Sass

原始使用文档

Sass Import Resolve Sass Logo

NPM Version Linux Build Status Windows Build Status Gitter Chat

Sass Import Resolve resolves the path and contents of Sass imports, following the Sass Import Resolve Specification.

npm install @csstools/sass-import-resolve

The Resolve Method

The resolve method takes any path and returns its absolute path, as resolved by the Sass Import Resolve Specification.

import resolve from '@csstools/sass-import-resolve';

const { file } = resolve('path/to/sass-file');

The resolve method may also return the contents of the resolved file.

const { file, contents } = resolve('path/to/sass-file', {
  readFile: true
});

The resolve method may also resolve the path from a specific directory.

const { file } = resolve('sass-file', {
  cwd: 'path/to'
});

The resolve method may also share its resolved cache.

const sharedCache = {};

const { file } = resolve('path/to/sass-file', {
  cache: sharedCache
});

/* sharedCache {
  "/absolute/path/to/sass-file": Promise {
    file,
    contents (when `readFile` is true)
  }
} */

The Resolve Algorithm

When @import is called, the following high-level algorithm is used to resolve the location of a file within url(id) from cwd:

  1. if id begins with /
    1. cwd is the filesystem root
  2. file is cwd/id
  3. base is base path of file
  4. dir is directory path of file
  5. if base ends with .sass, .scss, or .css
    1. test whether file exists
    2. if base does not start with _
      1. test whether dir/_base exists
  6. otherwise
    1. test whether dir/base.scss exists
    2. test whether dir/base.sass exists
    3. test whether dir/base.css exists
    4. if base does not start with _
      1. test whether dir/_base.scss exists
      2. test whether dir/_base.sass exists
      3. test whether dir/_base.css exists
  7. if the length of existing files is 1
    1. return the existing file
  8. otherwise, if the length of existing files is greater than 1
    1. throw "It's not clear which file to import"
  9. otherwise, if base does not end with .css
    1. throw "File to import not found or unreadable"

See the Sass Import Resolve Specification for more details.

版本与发布记录

@csstools/sass-import-resolve 共发布 2 个版本,首次发布于 2017/12/07;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.0.0latest2017/12/078 年前
0.0.02017/12/078 年前

关于 @csstools/sass-import-resolve 的常见问题

@csstools/sass-import-resolve 是什么?

An algorithm for resolving imports in Sass

如何安装 @csstools/sass-import-resolve?

在项目目录运行 npm install @csstools/sass-import-resolve,或使用 pnpm add / yarn add / bun add。

@csstools/sass-import-resolve 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/csstools__sass-import-resolve 是否存在。

@csstools/sass-import-resolve 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@csstools/sass-import-resolve 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=4.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@csstools/sass-import-resolve 可以商用吗?

@csstools/sass-import-resolve 使用 CC0-1.0 许可。作者放弃著作权,可不受限制地使用。以上为概括,不构成法律意见,请以许可原文为准。

@csstools/sass-import-resolve 的下载量有多少?

根据 npm 官方下载统计,@csstools/sass-import-resolve 在 2026/10/11 – 2026/11/09 这 30 天内被下载 760,191 次,日均约 25,340 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@csstools/sass-import-resolve 还在维护吗?

最新版本 1.0.0 发布于 2017/12/07(8 年前);至今共发布 2 个版本,其中过去 12 个月发布了 0 个;首次发布于 2017/12/07。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。