Skip to content

Commit

Permalink
build options without import
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick committed Dec 7, 2023
1 parent aec5f9e commit f66f3ac
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 75 deletions.
74 changes: 0 additions & 74 deletions scripts/build-options.ts

This file was deleted.

78 changes: 77 additions & 1 deletion scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import chalk from 'chalk';
import { execSync } from 'child_process';
import { existsSync, promises as fsPromises } from 'fs';
import tsup, { Options } from 'tsup';
import { buildOptions, completeOptions, debugOptions, watchOptions } from './build-options.js';
import { InlineCSSPlugin } from './inline-css-plugin.js';

const command = process.argv[2];
const buildType = command === 'watch' ? 'watch' : 'build';
Expand All @@ -11,6 +11,82 @@ console.log('Building the project...');

const outdir = 'dist';

import pkgJson from '../package.json' assert { type: 'json' };

const peerdependencies: string[] = [];
for (const property in pkgJson.peerdependencies) {
peerdependencies.push(property);
}

// ---- the options ----

const options = {
clean: false,
target: 'es2017',
dts: true,
format: ['esm'],
entryPoints: [
// NOTE: Entry points must be mapped in package.json > exports, otherwise users won't be able to import them!
'./src/lib/qti-components/index.ts',
'./src/lib/qti-transformers/index.ts'
],
// external: peerdependencies, // ['@lit/react', '@lit/context', 'react', 'lit'],
splitting: true,
esbuildPlugins: [InlineCSSPlugin],
outDir: 'dist'
} as Options;

export const watchOptions = {
...options,
clean: true,
sourcemap: 'inline',
define: {
'process.env.NODE_ENV': '"development"',
DEBUG: 'true'
}
} as Options;

export const buildOptions = {
...options,
format: [...options.format!, 'cjs'],
minify: true,
bundle: true,
pure: ['console.log'],
define: {
'process.env.NODE_ENV': '"production"'
}
} as Options;

export const debugOptions = {
...options,
pure: [],
bundle: true,
define: {
'process.env.NODE_ENV': '"production"',
DEBUG: 'true'
},
outDir: 'dist/debug'
} as Options;

// Make a build purely for enjoying creating qti-items in a plain HTML file
export const completeOptions = {
...options,
dts: false,
external: [],
noExternal: [/(.*)/],
splitting: false,
sourcemap: false,
minify: true,
bundle: true,
entryPoints: ['./src/index.ts'],
pure: ['console.log'],
define: {
'process.env.NODE_ENV': '"production"'
}
} as Options;

// ---- the build ----

(async () => {
try {
// make sure the folder is clean
Expand Down

0 comments on commit f66f3ac

Please sign in to comment.