This is the directory structure
├── src/codemirror/codemirror.min2.css
├── build.mjs
Content of build.mjs
:
import archiver from 'archiver'
import autoprefixer from 'autoprefixer'
import * as dotenv from 'dotenv'
import esbuild from 'esbuild'
import postcssPlugin from 'esbuild-style-plugin'
import fs from 'fs-extra'
import process from 'node:process'
import tailwindcss from 'tailwindcss'
dotenv.config()
const outdir = 'build'
async function deleteOldDir() {
await fs.remove(outdir)
}
async function runEsbuild() {
await esbuild.build({
entryPoints: [
'src/codemirror/codemirror.min2.css',
'src/codemirror/python.min.js',
],
bundle: true,
outdir: outdir,
treeShaking: true,
minify: true,
drop: ['console', 'debugger'],
legalComments: 'none',
define: {
'process.env.NODE_ENV': '"production"',
'process.env.AXIOM_TOKEN': JSON.stringify(process.env.AXIOM_TOKEN || 'UNDEFINED'),
},
jsxFactory: 'h',
jsxFragment: 'Fragment',
jsx: 'automatic',
loader: {
'.png': 'dataurl',
'.css': 'text',
},
plugins: [
postcssPlugin({
}),
],
})
}
async function zipFolder(dir) {
const output = fs.createWriteStream(`${dir}.zip`)
const archive = archiver('zip', {
zlib: { level: 9 },
})
archive.pipe(output)
archive.directory(dir, false)
await archive.finalize()
}
async function copyFiles(entryPoints, targetDir) {
await fs.ensureDir(targetDir)
await Promise.all(
entryPoints.map(async (entryPoint) => {
await fs.copy(entryPoint.src, `${targetDir}/${entryPoint.dst}`)
}),
)
}
async function build() {
await deleteOldDir()
await runEsbuild()
const commonFiles = [
{ src: 'build/codemirror', dst: 'codemirror' },
]
// chromium
await copyFiles(
[...commonFiles, { src: 'src/manifest.json', dst: 'manifest.json' }],
`./${outdir}/chromium`,
)
await zipFolder(`./${outdir}/chromium`)
}
build()
In the destination build
folder I am seeing a .js
file:
build/codemirror/
├── codemirror.min2.css
├── codemirror.min2.js
where is codemirror.min2.js
coming from , it didn't even exist?
How to prevent it being generated?