Skip to content

Commit 20e63e4

Browse files
committed
chore: build method update
affects: @vue-async/resource-manager, @vue-async/utils umd,iife build 时能过 babel 编译 移除build commonjs min 文件
1 parent fb57208 commit 20e63e4

File tree

5 files changed

+51
-35
lines changed

5 files changed

+51
-35
lines changed

packages/resource-manager/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
"types/*.d.ts"
2424
],
2525
"scripts": {
26-
"build": "rollup -c",
27-
"build:es": "cross-env TARGET=es rollup -c",
26+
"build": "rollup -c --environment BUILD:production",
27+
"build:es": "rollup -c --environment TARGET:es,BUILD:production",
2828
"release": "bash scripts/release.sh",
29-
"test": "cd ../../ && cross-env NODE_ENV=test jest --passWithNoTests --config packages/resource-manager/jest.config.json",
29+
"test": "cross-env NODE_ENV=test jest --passWithNoTests --config jest.config.json",
3030
"lint": "eslint . --cache --report-unused-disable-directives --ignore-path=../../.eslintignore",
3131
"lint:fix": "eslint . --cache --fix --ignore-path=../../.eslintignore"
3232
},

packages/resource-manager/rollup.config.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import clear from 'rollup-plugin-clear';
1111
import lisence from 'rollup-plugin-license';
1212
import { DEFAULT_EXTENSIONS } from '@babel/core';
1313

14+
const isProd = process.env.BUILD === 'production';
1415
const packageConfig = require('./package.json');
1516
const extensions = [...DEFAULT_EXTENSIONS, '.ts', '.tsx'];
1617

@@ -20,11 +21,11 @@ const builds = {
2021
format: 'cjs',
2122
mode: 'development',
2223
},
23-
'cjs-prod': {
24-
outFile: 'resource-manager.common.min.js',
25-
format: 'cjs',
26-
mode: 'production',
27-
},
24+
// 'cjs-prod': {
25+
// outFile: 'resource-manager.common.min.js',
26+
// format: 'cjs',
27+
// mode: 'production',
28+
// },
2829
'umd-dev': {
2930
outFile: 'resource-manager.umd.js',
3031
format: 'umd',
@@ -54,7 +55,6 @@ const builds = {
5455

5556
// polyfill in iife mode
5657
function genConfig({ outFile, format, mode }, clean = false) {
57-
const isProd = mode === 'production';
5858
return {
5959
input: './src/index.ts',
6060
output: {
@@ -67,7 +67,7 @@ function genConfig({ outFile, format, mode }, clean = false) {
6767
exports: 'named',
6868
name: format === 'umd' || format === 'iife' ? 'VueAsyncResourceManager' : undefined,
6969
},
70-
external: ['vue', '@vue-async/utils'],
70+
external: ['vue', !(format === 'iife' || format === 'umd') && '@vue-async/utils'].filter(Boolean),
7171
plugins: [
7272
clean &&
7373
clear({
@@ -92,7 +92,7 @@ function genConfig({ outFile, format, mode }, clean = false) {
9292
}),
9393
// commonjs => es6
9494
commonjs(),
95-
format === 'iife' &&
95+
(format === 'iife' || format === 'umd') &&
9696
babel({
9797
// https://babeljs.io/docs/en/options#rootMode
9898
rootMode: 'upward', // 向上级查找 babel.config.js
@@ -102,11 +102,15 @@ function genConfig({ outFile, format, mode }, clean = false) {
102102
}),
103103
json(),
104104
replace({
105-
'process.env.NODE_ENV': JSON.stringify(isProd ? 'production' : 'development'),
105+
...(format === 'iife' || format === 'umd'
106+
? {
107+
'process.env.NODE_ENV': JSON.stringify(isProd ? 'production' : 'development'),
108+
}
109+
: null),
106110
__VERSION__: packageConfig.version,
107111
}),
108112
// minimize files
109-
isProd && terser(),
113+
mode === 'production' && terser(),
110114
// add banner
111115
lisence({
112116
banner: {

packages/utils/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "1.0.5",
44
"author": "Hubert<yi.xiang@live.com>",
55
"description": "Utils.",
6-
"main": "dist/utils.common.ts",
6+
"main": "dist/utils.common.js",
77
"umd:main": "dist/utils.umd.js",
88
"module": "dist/utils.esm.js",
99
"unpkg": "dist/utils.js",
@@ -23,10 +23,10 @@
2323
"types/*.d.ts"
2424
],
2525
"scripts": {
26-
"build": "rollup -c",
27-
"build:es": "cross-env TARGET=es rollup -c",
26+
"build": "rollup -c --environment BUILD:production",
27+
"build:es": "rollup -c --environment TARGET:es,BUILD:production",
2828
"release": "bash scripts/release.sh",
29-
"test": "cd ../../ && cross-env NODE_ENV=test jest --passWithNoTests --config packages/utils/jest.config.json",
29+
"test": "cross-env NODE_ENV=test jest --passWithNoTests --config jest.config.json",
3030
"lint": "eslint . --cache --report-unused-disable-directives --ignore-path=../../.eslintignore",
3131
"lint:fix": "eslint . --cache --fix --ignore-path=../../.eslintignore"
3232
},

packages/utils/rollup.config.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import lisence from 'rollup-plugin-license';
1313
// import dts from 'rollup-plugin-dts';
1414
import { DEFAULT_EXTENSIONS } from '@babel/core';
1515

16+
const isProd = process.env.BUILD === 'production';
1617
const packageConfig = require('./package.json');
1718
const extensions = [...DEFAULT_EXTENSIONS, '.ts', '.tsx'];
1819

@@ -22,11 +23,11 @@ const builds = {
2223
format: 'cjs',
2324
mode: 'development',
2425
},
25-
'cjs-prod': {
26-
outFile: 'utils.common.min.js',
27-
format: 'cjs',
28-
mode: 'production',
29-
},
26+
// 'cjs-prod': {
27+
// outFile: 'utils.common.min.js',
28+
// format: 'cjs',
29+
// mode: 'production',
30+
// },
3031
'umd-dev': {
3132
outFile: 'utils.umd.js',
3233
format: 'umd',
@@ -55,7 +56,6 @@ const builds = {
5556
};
5657

5758
function genConfig({ outFile, format, mode }, clean = false) {
58-
const isProd = mode === 'production';
5959
return {
6060
input: ['./src/*.ts', './src/*/index.ts'],
6161
output: {
@@ -96,7 +96,7 @@ function genConfig({ outFile, format, mode }, clean = false) {
9696
}),
9797
// commonjs => es6
9898
commonjs(),
99-
format === 'iife' &&
99+
(format === 'iife' || format === 'umd') &&
100100
babel({
101101
// https://babeljs.io/docs/en/options#rootMode
102102
rootMode: 'upward', // 向上级查找 babel.config.js
@@ -106,11 +106,15 @@ function genConfig({ outFile, format, mode }, clean = false) {
106106
}),
107107
json(),
108108
replace({
109-
'process.env.NODE_ENV': JSON.stringify(isProd ? 'production' : 'development'),
109+
...(format === 'iife' || format === 'umd'
110+
? {
111+
'process.env.NODE_ENV': JSON.stringify(isProd ? 'production' : 'development'),
112+
}
113+
: null),
110114
__VERSION__: packageConfig.version,
111115
}),
112116
// minimize files
113-
isProd && terser(),
117+
mode === 'production' && terser(),
114118
// add banner
115119
lisence({
116120
banner: {

packages/utils/src/tools.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
/**
22
* tools
33
*/
4-
5-
import _Vue from 'vue';
6-
4+
import { isUndef } from './types';
75
export const hasSymbol = typeof Symbol === 'function' && Symbol.for;
86

97
export const noop: any = (_: any) => _;
@@ -54,17 +52,27 @@ export function assert(condition: any, msg: string) {
5452
}
5553
}
5654

57-
export function warn(condition: boolean, msg: string, vm?: _Vue) {
55+
export function warn(condition: boolean, msg: string, vm?: any) {
5856
if (!condition) {
59-
// eslint-disable-next-line no-console
60-
console.warn(`warning: ${msg}`, vm);
57+
if (isUndef(vm)) {
58+
// eslint-disable-next-line no-console
59+
console.warn(`warning: ${msg}`);
60+
} else {
61+
// eslint-disable-next-line no-console
62+
console.warn(`warning: ${msg}`, vm);
63+
}
6164
}
6265
}
6366

64-
export function error(condition: boolean, msg: string, vm?: _Vue) {
67+
export function error(condition: boolean, msg: string, vm?: any) {
6568
if (!condition) {
66-
// eslint-disable-next-line no-console
67-
console.error(`error: ${msg}`, vm);
69+
if (isUndef(vm)) {
70+
// eslint-disable-next-line no-console
71+
console.error(`error: ${msg}`);
72+
} else {
73+
// eslint-disable-next-line no-console
74+
console.error(`error: ${msg}`, vm);
75+
}
6876
}
6977
}
7078

0 commit comments

Comments
 (0)