-
-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Metafile not working #188
Comments
Alright, so after spending some time trying to implement web cache busting, I've found a (convoluted) solution that does use the We can use a basic import {
BuildOptions,
IBuildProvider,
TypeScriptSource,
} from '@mrgrain/cdk-esbuild';
import {Metafile, buildSync} from 'esbuild';
let metafile: Metafile | undefined;
class MetafileEsbuild implements IBuildProvider {
buildSync(options: BuildOptions): void {
metafile = buildSync(options)?.metafile;
}
}
new BucketDeployment(this, 'deployment', {
sources: [
new TypeScriptSource('../src/index.tsx', {
buildProvider: new MetafileEsbuild(),
buildOptions: {
bundle: true,
entryNames: '[name]-[hash]',
metafile: true,
},
}),
],
destinationBucket,
}); For my use-case, this then gets pretty janky. By chaining another You would need to add a const getFilenamesFromMetafile = (metafile: Metafile) => {
const entryPoint = Object.entries(metafile?.outputs ?? {}).find(
([, {entryPoint}]) => entryPoint?.endsWith('index.tsx'),
);
if (!entryPoint) throw new Error('Missing entryPoint');
const [jsPath, {cssBundle: cssPath}] = entryPoint;
if (!cssPath) throw new Error('Missing cssBundle');
return {
js: basename(jsPath),
css: basename(cssPath),
};
};
const fileNames = getFilenamesFromMetafile(metafile!);
new BucketDeployment(this, 'secondary-deployment', {
sources: [
Source.data(
'index.html',
readFileSync('../template/index.html', 'utf8')
.replace('{{indexJsPath}}', fileNames.js)
.replace('{{indexCssPath}}', fileNames.css),
),
],
destinationBucket,
prune: false,
}); AFAIK, since the Another (somehow more reasonable solution) is to run const buildOptions: BuildOptions = {
bundle: true,
metafile: true,
entryNames: '[name]-[hash]',
};
const {metafile} = buildSync({
...buildOptions,
entryPoints: ['../template/src/index.tsx'],
absWorkingDir: resolve(__dirname, '..'),
outdir: FileSystem.mkdtemp('esbuild'),
});
const fileNames = getFilenamesFromMetafile(metafile!);
new BucketDeployment(this, 'deployment', {
sources: [
new TypeScriptSource('../src/index.tsx', {buildOptions}),
Source.data(
'index.html',
readFileSync('../template/index.html', 'utf8')
.replace('{{indexJsPath}}', fileNames.js)
.replace('{{indexCssPath}}', fileNames.css),
),
],
destinationBucket,
}); Unfortunately, I have not been able to get the same hashes between the two back-to-back builds, even whilst running the same I'm very open to suggestions here, both solutions are clearly unsatisfactory. The best thing I can think of is adding a |
This is pretty cool, thanks for investigating! Sound like the best option would be to have a new |
Another possibility would be another implementation that runs asynchronously and returns both a "static" |
The issue with async is that we can't use |
Describe the bug
The
metafile
option has no effect.To Reproduce
Expected behavior
I can access the metafile somehow.
Versions:
Additional context
The JS API does return the file as a variable instead of writing a file. I'm not sure if what would be possible here, but ideally I could do something like this:
or at least have it write a
metafile.json
.The text was updated successfully, but these errors were encountered: