Skip to content

Commit

Permalink
copy preflight.css to dist/css folder
Browse files Browse the repository at this point in the history
When there is no local tailwind install in the workspace, the extension uses it's local copy to generate it's ordering. The built-in preflight tailwind plugin requires the preflight.css file to load and it expects it to be in the dist/css folder
  • Loading branch information
Trapfether committed Nov 29, 2023
1 parent 88c70ba commit 282ee1b
Showing 1 changed file with 13 additions and 28 deletions.
41 changes: 13 additions & 28 deletions build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -33,33 +33,18 @@ function patchRecast() {
/**
* @returns {import('esbuild').Plugin}
*/
function patchCjsInterop() {
return {
name: 'patch-cjs-interop',
setup(build) {
build.onEnd(async () => {
let outfile = './dist/index.js'

let content = await fs.promises.readFile(outfile)

// Prepend `createRequire`
let code = [
`import {createRequire} from 'module'`,
`import {dirname as __global__dirname__} from 'path'`,
`import {fileURLToPath} from 'url'`,

// CJS interop fixes
`const require=createRequire(import.meta.url)`,
`const __filename=fileURLToPath(import.meta.url)`,
`const __dirname=__global__dirname__(__filename)`,
]

content = `${code.join('\n')}\n${content}`

fs.promises.writeFile(outfile, content)
})
},
}
function copyPreflightFromDistToBaseDist() {
return {
name: 'copy-preflight',
setup(build) {
build.onEnd(() =>
fs.promises.copyFile(
path.resolve(__dirname, './dist/css/node_modules/tailwindcss/lib/css/preflight.css'),
path.resolve(__dirname, './dist/css/preflight.css'),
),
)
},
}
}

const __dirname = path.dirname(fileURLToPath(import.meta.url))
Expand All @@ -73,7 +58,7 @@ let context = await esbuild.context({
entryPoints: [path.resolve(__dirname, './src/loader.js')],
outfile: path.resolve(__dirname, './dist/index.js'),
format: 'cjs',
plugins: [patchRecast()],
plugins: [patchRecast(), copyPreflightFromDistToBaseDist()],
})

await context.rebuild()
Expand Down

0 comments on commit 282ee1b

Please sign in to comment.