build.ts 966 字节
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
/* eslint-disable no-console */

import builder, {projectRoot} from '@visualdl/core/build';
import {cp, mkdir, rm} from 'shelljs';

import config from './webpack.config';
import path from 'path';
import webpack from 'webpack';

const dist = path.resolve(__dirname, 'dist');
console.log('Building server');
console.log(`Source: ${projectRoot}`);
console.log(`Destination: ${dist}`);

async function start() {
    try {
        await builder('build');
        rm('-rf', dist);
        mkdir('-p', dist);
        cp(
            '-Rf',
            ['dist', 'pages', 'public', 'next.config.js', 'package.json'].map(file => path.join(projectRoot, file)),
            dist
        );
    } catch (e) {
        process.exit(e);
    }
    console.log('Webpack building...');
    const compiler = webpack(config as webpack.Configuration);
    compiler.run(err => {
        if (err) {
            console.error(err);
            process.exit(1);
        }
    });
}

start();