Skip to content

Commit

Permalink
feat: support esm
Browse files Browse the repository at this point in the history
  • Loading branch information
leezng committed Mar 13, 2024
1 parent a32896a commit d35d855
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 21 deletions.
29 changes: 9 additions & 20 deletions build/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@ require('./check-versions')();

process.env.NODE_ENV = 'production';

const fs = require('fs');
const path = require('path');
const chalk = require('chalk');
const webpack = require('webpack');
const { spawn } = require('child_process');
const webpackConfig = require('./webpack.prod.conf');

const isEsm = process.env.ESM;
const isExampleEnv = process.env.EXAMPLE_ENV;

const successText = {
main: 'Build main sources complete.',
esm: 'Build esm sources complete.',
example: 'Build example page complete.',
};

webpack(webpackConfig, (err, stats) => {
if (err) throw err;

Expand All @@ -29,7 +33,8 @@ webpack(webpackConfig, (err, stats) => {
process.exit(1);
}

console.log(chalk.cyan('Build sources complete.\n'));
const text = isExampleEnv ? successText.example : isEsm ? successText.esm : successText.main;
console.log(chalk.cyan(`${text}\n`));

if (isExampleEnv) {
console.log(
Expand All @@ -38,21 +43,5 @@ webpack(webpackConfig, (err, stats) => {
"Opening index.html over file:// won't work.\n",
),
);
} else {
const buildEsmProcess = spawn('npm', ['run', 'build:esm'], {
stdio: 'inherit',
});

buildEsmProcess.on('close', () => {
console.log(chalk.cyan('Build esm complete.\n'));
});

const buildTypesProcess = spawn('npm', ['run', 'build:dts'], {
stdio: 'inherit',
});

buildTypesProcess.on('close', () => {
console.log(chalk.cyan('Build types(.d.ts) complete.\n'));
});
}
});
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"module": "esm/vue-json-pretty.js",
"scripts": {
"dev": "node build/dev-server.js",
"build": "node build/build.js",
"build": "npm run build:main && npm run build:esm && npm run build:dts",
"build:main": "node build/build.js",
"build:esm": "cross-env ESM=true node build/build.js",
"build:example": "cross-env EXAMPLE_ENV=true node build/build.js",
"build:dts": "tsc --p tsconfig.dts.json && tsc-alias -p ./tsconfig.dts.json",
Expand Down

0 comments on commit d35d855

Please sign in to comment.