Skip to content

Commit

Permalink
Add support for ESM tailwind config file
Browse files Browse the repository at this point in the history
  • Loading branch information
rogden committed Mar 29, 2024
1 parent 66dd260 commit 4c5f9e3
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
4 changes: 2 additions & 2 deletions cli/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ const crypto = require('crypto')
const replace = require('replace-in-file')
const { resolveConfigToJson } = require('../lib/tailwindConfigUtils')

module.exports = function (outputDir, configPath) {
module.exports = async function (outputDir, configPath) {
outputDir = path.resolve(process.cwd(), outputDir)

fs.removeSync(outputDir)
fs.mkdirSync(outputDir)

const configJson = resolveConfigToJson(configPath)
const configJson = await resolveConfigToJson(configPath)
const configFileName = generateConfigFileNameFromJson(configJson)

fs.writeFileSync(path.resolve(outputDir, configFileName), configJson)
Expand Down
5 changes: 3 additions & 2 deletions cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ program
.action(args => {
require('../server')({
port: args.port,
tailwindConfigProvider: () => {
tailwindConfigProvider: async () => {
const configPath = resolveConfigPath(program.config)
delete require.cache[configPath]
return require(configPath)
const config = await import(configPath)
return config.default || config
},
shouldOpen: args.open
}).start()
Expand Down
6 changes: 3 additions & 3 deletions lib/tailwindConfigUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ const resolveConfig = config => {
return transformConfig(resolveTailwindConfig(config))
}

const resolveConfigToJson = configPath => {
const tailwindConfig = require(configPath)
return JSON.stringify(resolveConfig(tailwindConfig))
const resolveConfigToJson = async (configPath) => {
const config = await import(configPath)
return JSON.stringify(resolveConfig(config.default || config))
}

const transformConfig = config => {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"lib"
],
"engines": {
"node": ">=8"
"node": ">=13"
},
"dependencies": {
"@koa/router": "^12.0.1",
Expand Down

0 comments on commit 4c5f9e3

Please sign in to comment.