Skip to content

Commit

Permalink
perf: Replace typescript plug-in with a faster esbuild plug-in
Browse files Browse the repository at this point in the history
  • Loading branch information
anncwb committed Sep 13, 2020
1 parent ae917df commit 58ad7cd
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vite-plugin-mock",
"version": "1.0.0",
"version": "1.0.1",
"description": "A mock plugin for vite",
"main": "dist/index.js",
"files": [
Expand Down Expand Up @@ -29,13 +29,13 @@
"homepage": "https://github.com/anncwb/vite-plugin-mock/tree/master/#readme",
"dependencies": {
"@rollup/plugin-node-resolve": "^9.0.0",
"rollup-plugin-typescript": "^1.0.1",
"chalk": "^4.1.0",
"chokidar": "^3.4.2",
"esbuild": "^0.7.1",
"glob": "^7.1.6",
"koa-bodyparser": "^4.3.0",
"rollup": "^2.26.11"
"rollup": "^2.26.11",
"rollup-plugin-esbuild": "^2.5.0"
},
"peerDependencies": {
"mockjs": ">=1.1.0",
Expand Down
5 changes: 2 additions & 3 deletions src/createMockServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ import Mock from 'mockjs';
import { isArray, isFunction, sleep, isRegExp } from './utils';
import { loadConfigFromBundledFile } from './loadConfigFromBundledFile';
import { rollup } from 'rollup';

import esbuildPlugin from 'rollup-plugin-esbuild';
const pathResolve = require('@rollup/plugin-node-resolve');
const typescript = require('rollup-plugin-typescript');

let mockData: MockMethod[] = [];
export async function createMockServer(
Expand Down Expand Up @@ -153,7 +152,7 @@ async function resolveModule(path: string): Promise<any> {
input: path,
treeshake: false,
plugins: [
typescript({
esbuildPlugin({
include: /\.[jt]sx?$/,
exclude: /node_modules/,
sourceMap: false,
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ export declare interface MockMethod {
url: string;
method?: MethodType;
timeout?: number;
response: ((opt: { [key: string]: string; body: any; query: any }) => any) | any;
response: ((opt: { [key: string]: string; body: any; query: any }) => any) | object;
}
19 changes: 19 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1246,6 +1246,11 @@ jest-worker@^24.9.0:
merge-stream "^2.0.0"
supports-color "^6.1.0"

joycon@^2.2.5:
version "2.2.5"
resolved "https://registry.npmjs.org/joycon/-/joycon-2.2.5.tgz#8d4cf4cbb2544d7b7583c216fcdfec19f6be1615"
integrity sha512-YqvUxoOcVPnCp0VU1/56f+iKSdvIRJYPznH22BdXV3xMk75SFXhWeJkZ8C9XxUWt1b5x2X1SxuFygW1U0FmkEQ==

js-tokens@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"
Expand Down Expand Up @@ -1848,6 +1853,15 @@ rollup-plugin-dynamic-import-variables@^1.0.1:
globby "^11.0.0"
magic-string "^0.25.7"

rollup-plugin-esbuild@^2.5.0:
version "2.5.0"
resolved "https://registry.npmjs.org/rollup-plugin-esbuild/-/rollup-plugin-esbuild-2.5.0.tgz#5748352d0b688743ac64fc85fa86939e00098524"
integrity sha512-Tfi8Zynux67j4h4xEp/OvP2EDrKk/nM9Eghe1sT2+Nw4s6ei9vsqO1ajU+Y8EFfizMk3KEfYCicBKX6QLTW33w==
dependencies:
"@rollup/pluginutils" "^3.1.0"
joycon "^2.2.5"
strip-json-comments "^3.1.1"

rollup-plugin-terser@^5.3.0:
version "5.3.0"
resolved "https://registry.yarnpkg.com/rollup-plugin-terser/-/rollup-plugin-terser-5.3.0.tgz#9c0dd33d5771df9630cd027d6a2559187f65885e"
Expand Down Expand Up @@ -1999,6 +2013,11 @@ strip-final-newline@^2.0.0:
resolved "https://registry.yarnpkg.com/strip-final-newline/-/strip-final-newline-2.0.0.tgz#89b852fb2fcbe936f6f4b3187afb0a12c1ab58ad"
integrity sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA==

strip-json-comments@^3.1.1:
version "3.1.1"
resolved "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz#31f1281b3832630434831c310c01cccda8cbe006"
integrity sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==

supports-color@^5.3.0:
version "5.5.0"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-5.5.0.tgz#e2e69a44ac8772f78a1ec0b35b689df6530efc8f"
Expand Down

0 comments on commit 58ad7cd

Please sign in to comment.