Go back to ESM

This commit is contained in:
Matthew Phillips 2021-12-02 11:54:22 -05:00
parent 530b77ed0a
commit 8f67687eef
6 changed files with 36 additions and 5 deletions

View file

@ -0,0 +1,4 @@
// @ts-check
export default /** @type {import('astro').AstroUserConfig} */ ({
renderers: [],
});

View file

@ -0,0 +1,14 @@
{
"name": "@example/cool-app",
"version": "0.0.1",
"private": true,
"scripts": {
"dev": "astro dev",
"start": "astro dev",
"build": "astro build",
"preview": "astro preview"
},
"devDependencies": {
"astro": "^0.21.6"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

View file

@ -0,0 +1,13 @@
---
import imgUrl from '../images/penguin.jpg';
---
<html>
<head>
<title>Demo app</title>
</head>
<body>
<h1>Penguins are cool</h1>
<img src={imgUrl} />
</body>
</html>

View file

@ -180,7 +180,7 @@ class AstroBuilder {
// The `input` will be populated in the build rollup plugin.
input: [],
output: {
format: 'cjs'
format: 'esm'
},
},
target: 'es2020', // must match an esbuild target
@ -255,7 +255,7 @@ class AstroBuilder {
let url = new URL('./' + out.fileName, this.config.dist);
let pageData = facadeIdToPageDataMap.get(out.facadeModuleId)!;
let compiledModule = await import(url.toString());
let Component = compiledModule.default.default;
let Component = compiledModule.default;
const [renderers, mod] = pageData.preload;

View file

@ -243,12 +243,12 @@ export function rollupPluginAstroBuildHTML(options: PluginOptions): VitePlugin {
if (!pageName) {
pageName = 'index';
}
return `assets/${pageName}.[hash].cjs`;
return `assets/${pageName}.[hash].mjs`;
}
return 'assets/[name].[hash].cjs';
return 'assets/[name].[hash].mjs';
},
chunkFileNames(chunk: PreRenderedChunk) {
return 'assets/[name].[hash].cjs';
return 'assets/[name].[hash].mjs';
}
});
return outputOptions;