ship bare module specifiers for prod

pull/561/head
Cory LaViska 2021-10-08 10:11:12 -04:00
rodzic 2ba5fb9820
commit 92dedf3386
1 zmienionych plików z 20 dodań i 20 usunięć

Wyświetl plik

@ -1,6 +1,3 @@
//
// Builds the project. To spin up a dev server, pass the --serve flag.
//
import browserSync from 'browser-sync'; import browserSync from 'browser-sync';
import chalk from 'chalk'; import chalk from 'chalk';
import commandLineArgs from 'command-line-args'; import commandLineArgs from 'command-line-args';
@ -13,11 +10,14 @@ import glob from 'globby';
import path from 'path'; import path from 'path';
import { execSync } from 'child_process'; import { execSync } from 'child_process';
const packageData = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
const externalDependencies = Object.keys(packageData.dependencies);
const build = esbuild.build; const build = esbuild.build;
const bs = browserSync.create(); const bs = browserSync.create();
const { dev } = commandLineArgs({ name: 'dev', type: Boolean }); const { dev } = commandLineArgs({ name: 'dev', type: Boolean });
del.sync('./dist'); del.sync(['./dist', './docs/dist']);
try { try {
if (!dev) execSync('tsc', { stdio: 'inherit' }); // for type declarations if (!dev) execSync('tsc', { stdio: 'inherit' }); // for type declarations
@ -32,22 +32,20 @@ try {
} }
(async () => { (async () => {
const entryPoints = [
// The whole shebang dist
'./src/shoelace.ts',
// Components
...(await glob('./src/components/**/!(*.(style|test)).ts')),
// Public utilities
...(await glob('./src/utilities/**/!(*.(style|test)).ts')),
// Theme stylesheets
...(await glob('./src/themes/**/!(*.test).ts'))
];
const buildResult = await esbuild const buildResult = await esbuild
.build({ .build({
format: 'esm', format: 'esm',
target: 'es2017', target: 'es2017',
entryPoints, entryPoints: [
// The whole shebang dist
'./src/shoelace.ts',
// Components
...(await glob('./src/components/**/!(*.(style|test)).ts')),
// Public utilities
...(await glob('./src/utilities/**/!(*.(style|test)).ts')),
// Theme stylesheets
...(await glob('./src/themes/**/!(*.test).ts'))
],
outdir: './dist', outdir: './dist',
chunkNames: 'chunks/[name].[hash]', chunkNames: 'chunks/[name].[hash]',
incremental: dev, incremental: dev,
@ -55,6 +53,7 @@ try {
// Popper.js expects this to be set // Popper.js expects this to be set
'process.env.NODE_ENV': '"production"' 'process.env.NODE_ENV': '"production"'
}, },
external: dev ? undefined : externalDependencies,
bundle: true, bundle: true,
splitting: true, splitting: true,
plugins: [] plugins: []
@ -66,13 +65,14 @@ try {
// Create the docs distribution by copying dist into the docs folder. This is what powers the website. It doesn't need // Create the docs distribution by copying dist into the docs folder. This is what powers the website. It doesn't need
// to exist in dev because Browser Sync routes it virtually. // to exist in dev because Browser Sync routes it virtually.
await del('./docs/dist');
if (!dev) { if (!dev) {
await del('./docs/dist');
await Promise.all([copy('./dist', './docs/dist')]); await Promise.all([copy('./dist', './docs/dist')]);
} }
console.log(chalk.green('The build has finished! 📦\n')); console.log(chalk.green('The build has finished! 📦\n'));
// Dev server
if (dev) { if (dev) {
const port = await getPort({ const port = await getPort({
port: getPort.makeRange(4000, 4999) port: getPort.makeRange(4000, 4999)
@ -128,8 +128,8 @@ try {
execSync('node scripts/make-search.js', { stdio: 'inherit' }); execSync('node scripts/make-search.js', { stdio: 'inherit' });
bs.reload(); bs.reload();
}); });
// Cleanup on exit
process.on('SIGTERM', () => buildResult.rebuild.dispose());
} }
// Cleanup on exit
process.on('SIGTERM', () => buildResult.rebuild.dispose());
})(); })();