Skip to content

Commit d35d855

Browse files
committed
feat: support esm
1 parent a32896a commit d35d855

File tree

2 files changed

+11
-21
lines changed

2 files changed

+11
-21
lines changed

build/build.js

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@ require('./check-versions')();
22

33
process.env.NODE_ENV = 'production';
44

5-
const fs = require('fs');
6-
const path = require('path');
75
const chalk = require('chalk');
86
const webpack = require('webpack');
9-
const { spawn } = require('child_process');
107
const webpackConfig = require('./webpack.prod.conf');
118

9+
const isEsm = process.env.ESM;
1210
const isExampleEnv = process.env.EXAMPLE_ENV;
1311

12+
const successText = {
13+
main: 'Build main sources complete.',
14+
esm: 'Build esm sources complete.',
15+
example: 'Build example page complete.',
16+
};
17+
1418
webpack(webpackConfig, (err, stats) => {
1519
if (err) throw err;
1620

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

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

3439
if (isExampleEnv) {
3540
console.log(
@@ -38,21 +43,5 @@ webpack(webpackConfig, (err, stats) => {
3843
"Opening index.html over file:// won't work.\n",
3944
),
4045
);
41-
} else {
42-
const buildEsmProcess = spawn('npm', ['run', 'build:esm'], {
43-
stdio: 'inherit',
44-
});
45-
46-
buildEsmProcess.on('close', () => {
47-
console.log(chalk.cyan('Build esm complete.\n'));
48-
});
49-
50-
const buildTypesProcess = spawn('npm', ['run', 'build:dts'], {
51-
stdio: 'inherit',
52-
});
53-
54-
buildTypesProcess.on('close', () => {
55-
console.log(chalk.cyan('Build types(.d.ts) complete.\n'));
56-
});
5746
}
5847
});

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"module": "esm/vue-json-pretty.js",
88
"scripts": {
99
"dev": "node build/dev-server.js",
10-
"build": "node build/build.js",
10+
"build": "npm run build:main && npm run build:esm && npm run build:dts",
11+
"build:main": "node build/build.js",
1112
"build:esm": "cross-env ESM=true node build/build.js",
1213
"build:example": "cross-env EXAMPLE_ENV=true node build/build.js",
1314
"build:dts": "tsc --p tsconfig.dts.json && tsc-alias -p ./tsconfig.dts.json",

0 commit comments

Comments
 (0)