-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use esbuild for css and add multi-layout support
BREAKING CHANGE: postcss transforms are removed in favor of esbuild css transforms. PCSS transforms will be re-added later.
- Loading branch information
Showing
15 changed files
with
297 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
import { join, relative, basename } from 'path' | ||
import esbuild from 'esbuild' | ||
import { resolveVars } from '../build-pages/resolve-vars.js' | ||
|
||
/** | ||
* Build all of the bundles | ||
* @param {string} src Path string of the site src | ||
* @param {string} dest Path string of the site build dest | ||
* @param {[type]} siteData [description] | ||
* @return {[type]} [description] | ||
*/ | ||
export async function buildEsbuild (src, dest, siteData, opts) { | ||
const entryPoints = [] | ||
if (siteData.globalClient) entryPoints.push(join(src, siteData.globalClient.relname)) | ||
if (siteData.globalStyle) entryPoints.push(join(src, siteData.globalStyle.relname)) | ||
|
||
for (const page of siteData.pages) { | ||
if (page.clientBundle) entryPoints.push(join(src, page.clientBundle.relname)) | ||
if (page.pageStyle) entryPoints.push(join(src, page.pageStyle.relname)) | ||
} | ||
|
||
const browserVars = await resolveVars(siteData?.globalVars?.filepath, 'browser') | ||
|
||
const define = {} | ||
|
||
if (browserVars) { | ||
for (const [k, v] of Object.entries(browserVars)) { | ||
define[k] = JSON.stringify(v) | ||
} | ||
} | ||
|
||
const mapOutputToEntry = { | ||
name: 'mapOutputToEntry', | ||
setup (build) { | ||
build.onEnd(result => { | ||
const ob = {} | ||
Object.keys(result?.metafile?.outputs || {}).forEach(file => { | ||
const { entryPoint } = result.metafile.outputs[file] | ||
if (entryPoint) { | ||
ob[relative(src, entryPoint)] = relative(dest, file) | ||
} | ||
}) | ||
result.outputMap = ob | ||
}) | ||
} | ||
} | ||
|
||
const buildOpts = { | ||
entryPoints, | ||
logLevel: 'silent', | ||
bundle: true, | ||
write: true, | ||
format: 'esm', | ||
splitting: true, | ||
sourcemap: true, | ||
outdir: dest, | ||
target: [ | ||
'esnext' | ||
], | ||
define, | ||
metafile: true, | ||
entryNames: '[dir]/[name]-[hash]', | ||
chunkNames: 'chunks/[ext]/[name]-[hash]', | ||
plugins: [mapOutputToEntry] | ||
} | ||
|
||
try { | ||
// esbuild returns { errors:[], warnings: [] } already | ||
const { outputMap, ...buildResults } = await esbuild.build(buildOpts) | ||
|
||
// Add output names to siteData | ||
for (const page of siteData.pages) { | ||
if (page.pageStyle) { | ||
const outputRelname = outputMap[page.pageStyle.relname] | ||
if (outputRelname) { | ||
page.pageStyle.outputRelname = outputRelname | ||
page.pageStyle.outputName = basename(outputRelname) | ||
} | ||
} | ||
|
||
if (page.clientBundle) { | ||
const outputRelname = outputMap[page.clientBundle.relname] | ||
if (outputRelname) { | ||
page.clientBundle.outputRelname = outputRelname | ||
page.clientBundle.outputName = basename(outputRelname) | ||
} | ||
} | ||
} | ||
|
||
if (siteData.globalClient) { | ||
const outputRelname = outputMap[siteData.globalClient.relname] | ||
if (outputRelname) { | ||
siteData.globalClient.outputRelname = outputRelname | ||
siteData.globalClient.outputName = basename(outputRelname) | ||
} | ||
} | ||
|
||
if (siteData.globalStyle) { | ||
const outputRelname = outputMap[siteData.globalStyle.relname] | ||
if (outputRelname) { | ||
siteData.globalStyle.outputRelname = outputRelname | ||
siteData.globalStyle.outputName = basename(outputRelname) | ||
} | ||
} | ||
|
||
return { ...buildResults, buildOpts, type: 'esbuild' } | ||
} catch (err) { | ||
const report = { | ||
type: 'esbuild', | ||
errors: [], | ||
warnings: [], | ||
buildOpts | ||
} | ||
const buildError = new Error('Error building JS+CSS with esbuild', { cause: err }) | ||
buildError.buildOpts = buildOpts | ||
report.errors.push(buildError) | ||
return report | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// import { Worker } from 'worker_threads' | ||
// import desm from 'desm' | ||
// import { join } from 'path' | ||
|
||
// import { resolveVars } from './resolve-vars.js' | ||
// import { resolveLayout } from './resolve-layout.js' | ||
|
||
// const __dirname = desm(import.meta.url) | ||
|
||
/** | ||
* Page builder glue. Most of the magic happens in the builders. | ||
* @param {[type]} src [description] | ||
* @param {[type]} dest [description] | ||
* @param {[type]} siteData [description] | ||
* @return {[type]} [description] | ||
*/ | ||
export function buildTemplates (src, dest, siteData, opts) { | ||
throw new Error('Not Implemented') | ||
} |
Oops, something went wrong.