Files
payload/src/bin/build.ts
Jacob Fletcher 9f30553813 feat: async plugins (#2030)
* feat: async plugins

* wip: async config

* fix: async config
2023-02-13 10:46:55 -05:00

40 lines
1.0 KiB
TypeScript
Executable File

/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable global-require */
import webpack from 'webpack';
import getWebpackProdConfig from '../webpack/getProdConfig';
import findConfig from '../config/find';
import loadConfig from '../config/load';
const rawConfigPath = findConfig();
export const build = async (): Promise<void> => {
try {
const config = await loadConfig();
const webpackProdConfig = getWebpackProdConfig(config);
webpack(webpackProdConfig, (err, stats) => { // Stats Object
if (err || stats.hasErrors()) {
// Handle errors here
if (stats) {
console.error(stats.toString({
chunks: false,
colors: true,
}));
} else {
console.error(err.message);
}
}
});
} catch (err) {
console.error(err);
throw new Error(`Error: can't find the configuration file located at ${rawConfigPath}.`);
}
};
// when build.js is launched directly
if (module.id === require.main.id) {
build();
}