Skip to content
/ dora Public

Dora is a deps precompile utils (esm to cjs)

License

Notifications You must be signed in to change notification settings

xn-sakina/dora

Repository files navigation

@xn-sakina/dora

Dora is a deps precompile utils

Usage

  # 1. install dep
  pnpm i -D @xn-sakina/dora

  # 2. create config file

  # 3. precompile deps
  pnpm dora build

Config

Simple

// dora.config.ts
import { defineConfig } from '@xn-sakina/dora'

export default defineConfig({
  deps: ['chalk'],
})

Complex

// dora.config.ts
import { defineConfig } from '@xn-sakina/dora'
import fs from 'fs'
import path from 'path'

export default defineConfig({
  deps: [
    {
      name: 'sass-loader',
      hooks: {
        onRunTaskBefore(opts) {
          const sassLoaderPath = require.resolve('sass-loader')
          const utilsPath = path.join(path.dirname(sassLoaderPath), 'utils.js')
          const originalContent = fs.readFileSync(utilsPath, 'utf-8')

          fs.writeFileSync(
            utilsPath,
            originalContent.replace(
              /require\.resolve\(["'](sass|node-sass)["']\)/g,
              'eval("require").resolve("$1")'
            ),
            'utf-8'
          )

          opts.externals = {
            ...opts.externals,
            'node-sass': 'node-sass',
            sass: 'sass',
            fibers: 'fibers',
          }
          console.log('opts: ', opts)
        },
      },
    },
  ],
})

License

MIT