Update build script to avoid bundling (#304)
* fix: simplify astro-scripts build * fix: remove source-map-support, add missing `.js` extensions * refactor: use `module` for `@astrojs/markdown-support` * fix: missing `.js` extension * fix: missed @astrojs/parser * fix: remove old file * fix: merge conflict * fix: CJS weirdness
This commit is contained in:
parent
9859f53903
commit
7583a8b42a
16 changed files with 16 additions and 28 deletions
|
@ -34,7 +34,7 @@
|
|||
"astro.mjs"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "astro-scripts build \"src/*.ts\" \"src/compiler/index.ts\" \"src/frontend/**/*.ts\" \"src/internal/**/*.ts\" && tsc",
|
||||
"build": "astro-scripts build \"src/**/*.ts\" && tsc",
|
||||
"postbuild": "astro-scripts copy \"src/**/*.astro\"",
|
||||
"dev": "astro-scripts dev \"src/**/*.ts\"",
|
||||
"benchmark": "node test/benchmark/dev.bench.js && node test/benchmark/build.bench.js",
|
||||
|
@ -87,7 +87,6 @@
|
|||
"shorthash": "^0.0.2",
|
||||
"slash": "^4.0.0",
|
||||
"snowpack": "^3.8.1",
|
||||
"source-map-support": "^0.5.19",
|
||||
"string-width": "^5.0.0",
|
||||
"tiny-glob": "^0.2.8",
|
||||
"unified": "^9.2.1",
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import 'source-map-support/register.js';
|
||||
import type { Attribute } from '@astrojs/parser';
|
||||
|
||||
// AST utility functions
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import 'source-map-support/register.js';
|
||||
import type { AstroConfig, BundleMap, BuildOutput, RuntimeMode, PageDependencies } from './@types/astro';
|
||||
import type { LogOptions } from './logger';
|
||||
|
||||
|
@ -13,7 +12,7 @@ import { bold, green, yellow, red, dim, underline } from 'kleur/colors';
|
|||
import mime from 'mime';
|
||||
import glob from 'tiny-glob';
|
||||
import { bundleCSS } from './build/bundle/css.js';
|
||||
import { bundleJS, collectJSImports } from './build/bundle/js';
|
||||
import { bundleJS, collectJSImports } from './build/bundle/js.js';
|
||||
import { buildCollectionPage, buildStaticPage, getPageType } from './build/page.js';
|
||||
import { generateSitemap } from './build/sitemap.js';
|
||||
import { logURLStats, collectBundleStats, mapBundleStatsToURLStats } from './build/stats.js';
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import type { BuildOutput } from '../@types/astro';
|
||||
|
||||
import { canonicalURL } from './util';
|
||||
import { canonicalURL } from './util.js';
|
||||
|
||||
/** Construct sitemap.xml given a set of URLs */
|
||||
export function generateSitemap(buildState: BuildOutput, site: string): string {
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import 'source-map-support/register.js';
|
||||
/* eslint-disable no-console */
|
||||
import type { AstroConfig } from './@types/astro';
|
||||
|
||||
|
|
|
@ -3,11 +3,10 @@ import type { CompileOptions } from '../../@types/compiler';
|
|||
import type { AstroConfig, AstroMarkdownOptions, TransformResult, ComponentInfo, Components } from '../../@types/astro';
|
||||
import type { ImportDeclaration, ExportNamedDeclaration, VariableDeclarator, Identifier, ImportDefaultSpecifier } from '@babel/types';
|
||||
|
||||
import 'source-map-support/register.js';
|
||||
import eslexer from 'es-module-lexer';
|
||||
import esbuild from 'esbuild';
|
||||
import path from 'path';
|
||||
import { parse, FEATURE_CUSTOM_ELEMENT } from '@astrojs/parser';
|
||||
import astroParser from '@astrojs/parser';
|
||||
import { walk, asyncWalk } from 'estree-walker';
|
||||
import _babelGenerator from '@babel/generator';
|
||||
import babelParser from '@babel/parser';
|
||||
|
@ -26,6 +25,7 @@ import { nodeBuiltinsSet } from '../../node_builtins.js';
|
|||
import { readFileSync } from 'fs';
|
||||
import { pathToFileURL } from 'url';
|
||||
|
||||
const { parse, FEATURE_CUSTOM_ELEMENT } = astroParser;
|
||||
const traverse: typeof babelTraverse.default = (babelTraverse.default as any).default;
|
||||
|
||||
// @ts-ignore
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import 'source-map-support/register.js';
|
||||
import type { CompileResult, TransformResult } from '../@types/astro';
|
||||
import type { CompileOptions } from '../@types/compiler.js';
|
||||
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
import type { AstroConfig } from './@types/astro';
|
||||
|
||||
import 'source-map-support/register.js';
|
||||
import path from 'path';
|
||||
import { existsSync } from 'fs';
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import 'source-map-support/register.js';
|
||||
import type { AstroConfig } from './@types/astro';
|
||||
import type { LogOptions } from './logger.js';
|
||||
|
||||
|
@ -8,7 +7,7 @@ import path from 'path';
|
|||
import { performance } from 'perf_hooks';
|
||||
import { defaultLogDestination, defaultLogLevel, debug, error, info, parseError } from './logger.js';
|
||||
import { createRuntime } from './runtime.js';
|
||||
import { stopTimer } from './build/util';
|
||||
import { stopTimer } from './build/util.js';
|
||||
|
||||
const hostname = '127.0.0.1';
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import 'source-map-support/register.js';
|
||||
import type { CompileError } from '@astrojs/parser';
|
||||
import { bold, blue, red, grey, underline, yellow } from 'kleur/colors';
|
||||
import { Writable } from 'stream';
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import 'source-map-support/register.js';
|
||||
import type { LogOptions } from './logger';
|
||||
import type { AstroConfig, CollectionResult, CollectionRSS, CreateCollection, Params, RuntimeMode } from './@types/astro';
|
||||
import type { CompileError as ICompileError } from '@astrojs/parser';
|
||||
|
||||
import resolve from 'resolve';
|
||||
import { existsSync, promises as fs } from 'fs';
|
||||
|
@ -16,7 +16,8 @@ import {
|
|||
SnowpackConfig,
|
||||
startServer as startSnowpackServer,
|
||||
} from 'snowpack';
|
||||
import { CompileError } from '@astrojs/parser';
|
||||
import parser from '@astrojs/parser';
|
||||
const { CompileError } = parser;
|
||||
import { canonicalURL, getSrcPath, stopTimer } from './build/util.js';
|
||||
import { debug, info } from './logger.js';
|
||||
import { configureSnowpackLogger } from './snowpack-logger.js';
|
||||
|
@ -49,9 +50,9 @@ type LoadResultSuccess = {
|
|||
type LoadResultNotFound = { statusCode: 404; error: Error; collectionInfo?: CollectionInfo };
|
||||
type LoadResultRedirect = { statusCode: 301 | 302; location: string; collectionInfo?: CollectionInfo };
|
||||
type LoadResultError = { statusCode: 500 } & (
|
||||
| { type: 'parse-error'; error: CompileError }
|
||||
| { type: 'parse-error'; error: ICompileError }
|
||||
| { type: 'ssr'; error: Error }
|
||||
| { type: 'not-found'; error: CompileError }
|
||||
| { type: 'not-found'; error: ICompileError }
|
||||
| { type: 'unknown'; error: Error }
|
||||
);
|
||||
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
import type { AstroConfig } from './@types/astro';
|
||||
|
||||
import 'source-map-support/register.js';
|
||||
import { existsSync } from 'fs';
|
||||
import path from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
},
|
||||
"scripts": {
|
||||
"prepublish": "yarn build",
|
||||
"build": "astro-scripts build --format cjs \"src/**/*.ts\" && tsc -p tsconfig.json",
|
||||
"build": "astro-scripts build \"src/**/*.ts\" && tsc -p tsconfig.json",
|
||||
"dev": "astro-scripts dev \"src/**/*.ts\""
|
||||
},
|
||||
"dependencies": {
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
"compilerOptions": {
|
||||
"allowJs": true,
|
||||
"target": "ES2020",
|
||||
"module": "CommonJS",
|
||||
"module": "ES2020",
|
||||
"outDir": "./dist"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,11 +7,10 @@ import glob from 'tiny-glob';
|
|||
|
||||
/** @type {import('esbuild').BuildOptions} */
|
||||
const defaultConfig = {
|
||||
bundle: true,
|
||||
minify: false,
|
||||
format: 'esm',
|
||||
platform: 'node',
|
||||
target: 'node14',
|
||||
target: 'node14.16.1',
|
||||
sourcemap: 'inline',
|
||||
sourcesContent: false,
|
||||
};
|
||||
|
@ -26,16 +25,15 @@ export default async function build(...args) {
|
|||
|
||||
const { type = 'module', dependencies = {} } = await fs.readFile('./package.json').then((res) => JSON.parse(res.toString()));
|
||||
const format = type === 'module' ? 'esm' : 'cjs';
|
||||
const external = [...Object.keys(dependencies), '@astrojs/language-server/bin/server.js', 'source-map-support', 'source-map-support/register.js', 'vscode'];
|
||||
const outdir = 'dist';
|
||||
await clean(outdir);
|
||||
|
||||
if (!isDev) {
|
||||
await esbuild.build({
|
||||
...config,
|
||||
bundle: entryPoints.length === 1, // Note: only use `bundle` with a single entrypoint!
|
||||
entryPoints,
|
||||
outdir,
|
||||
external,
|
||||
format,
|
||||
plugins: [svelte({ isDev })],
|
||||
});
|
||||
|
|
|
@ -9895,7 +9895,7 @@ source-map-js@^0.6.2:
|
|||
resolved "https://registry.npmjs.org/source-map-js/-/source-map-js-0.6.2.tgz"
|
||||
integrity sha512-/3GptzWzu0+0MBQFrDKzw/DvvMTUORvgY6k6jd/VS6iCR4RDTKWH6v6WPwQoUO8667uQEf9Oe38DxAYWY5F/Ug==
|
||||
|
||||
source-map-support@^0.5.19, source-map-support@~0.5.19:
|
||||
source-map-support@~0.5.19:
|
||||
version "0.5.19"
|
||||
resolved "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.19.tgz"
|
||||
integrity sha512-Wonm7zOCIJzBGQdB+thsPar0kYuCIzYvxZwlBa87yi/Mdjv7Tip2cyVbLj5o0cFPN4EVkuTwb3GDDyUx2DGnGw==
|
||||
|
|
Loading…
Reference in a new issue