Compass helpers for node platforms
    Preparing search index...

    Function importCJS

    • Type Parameters

      • T = unknown

      Parameters

      • filePath: string

        文件路径或模块名

      • Optionaloptions: ImportOptions

        配置项

        • cwd

          工作目录,默认为 process.cwd()

        • fallback

          是否在失败时尝试其他导入方式,默认为 true

      Returns T

      模块导出内容

      动态导入 CommonJS 模块(同步)

      // 导入本地模块
      const config = importCJS<Config>('./config.json');

      // 导入 npm 包
      const lodash = importCJS<typeof import('lodash')>('lodash');

      // 指定工作目录
      const data = importCJS('./data.js', { cwd: '/custom/path' });