Skip to content

Commit

Permalink
Update plugin script
Browse files Browse the repository at this point in the history
  • Loading branch information
invaders-xx committed Apr 25, 2024
1 parent b6a92a1 commit c0b9bdf
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 73 deletions.
53 changes: 22 additions & 31 deletions bin/build.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import esbuild from 'esbuild';
import * as esbuild from 'esbuild'

const isDev = process.argv.includes('--dev');
const isDev = process.argv.includes('--dev')

async function compile(options) {
const context = await esbuild.context(options);
const context = await esbuild.context(options)

if (isDev) {
await context.watch();
await context.watch()
} else {
await context.rebuild();
await context.dispose();
await context.rebuild()
await context.dispose()
}
}

Expand All @@ -25,32 +25,23 @@ const defaultOptions = {
treeShaking: true,
target: ['es2020'],
minify: !isDev,
plugins: [
{
name: 'watchPlugin',
setup: function (build) {
build.onStart(() => {
console.log(
`Build started at ${new Date(Date.now()).toLocaleTimeString()}: ${build.initialOptions.outfile}`,
);
});
plugins: [{
name: 'watchPlugin',
setup: function (build) {
build.onStart(() => {
console.log(`Build started at ${new Date(Date.now()).toLocaleTimeString()}: ${build.initialOptions.outfile}`)
})

build.onEnd((result) => {
if (result.errors.length > 0) {
console.log(
`Build failed at ${new Date(Date.now()).toLocaleTimeString()}: ${build.initialOptions.outfile}`,
result.errors,
);
} else {
console.log(
`Build finished at ${new Date(Date.now()).toLocaleTimeString()}: ${build.initialOptions.outfile}`,
);
}
});
},
},
],
};
build.onEnd((result) => {
if (result.errors.length > 0) {
console.log(`Build failed at ${new Date(Date.now()).toLocaleTimeString()}: ${build.initialOptions.outfile}`, result.errors)
} else {
console.log(`Build finished at ${new Date(Date.now()).toLocaleTimeString()}: ${build.initialOptions.outfile}`)
}
})
}
}],
}

compile({
...defaultOptions,
Expand Down
Loading

0 comments on commit c0b9bdf

Please sign in to comment.