
Security News
New React Server Components Vulnerabilities: DoS and Source Code Exposure
New DoS and source code exposure bugs in React Server Components and Next.js: whatâs affected and how to update safely.
vite-plugin-es6-mock
Advanced tools
Support vite mock data, use es6-mock to mock data.
Install with npm:
$ npm install --save-dev vite-plugin-es6-mock
// es6-mock config default param: { path: '/mock', dir: './mock' }
import vitePluginMock from 'vite-plugin-es6-mock';
export default defineConfig({
server: {
port: 8088,
},
plugins: [vitePluginMock()]
});
// es6-mock config dir and path
import vitePluginMock from 'vite-plugin-es6-mock';
export default defineConfig({
plugins: [vitePluginMock({ path: '/mockjs', dir: './mockjs'})]
});
Make a new file test.js in the config dir.
// Import lib
import path from 'path';
import fs from 'fs';
import { delay, validate, request } from 'es6-mock';
// Import other mock datas
import test1 from './test1';
import test2 from './test2';
// Delay response 500ms
delay(500);
// Validate request ďźIf validate failed, will return validate messages as responseďź
validate({
// Validate header required
header: {
'Cache-Control': 'required|equals:no-cache',
cookie: {
_gid: 'required'
},
},
// Validate param requiredă type or format
param: {
name: 'required|string',
id: 'required|integer'
},
// Validate request method
method: 'get|post'
});
// Export mock dataďźif validate pass
export default {
// Use mockjs data template
'code|1-10': '0',
data: {
"switch|1-2": true,
name: 'test03.js',
// Use other mock data. This will very useful in large data content
test1,
test2,
// Get request get param
param: request.query,
// Get request post param
param2: request.body,
// Support node various operations
existTest1: fs.existsSync(path.join(__dirname, 'test1.js')),
existTest0: fs.existsSync(path.join(__dirname, 'no-exist.js'))
}
};
Start your vite, then you can get the mock content through the URL: http://localhost:8088/test
FAQs
vite mock data
We found that vite-plugin-es6-mock demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
New DoS and source code exposure bugs in React Server Components and Next.js: whatâs affected and how to update safely.

Security News
Socket CEO Feross Aboukhadijeh joins Software Engineering Daily to discuss modern software supply chain attacks and rising AI-driven security risks.

Security News
GitHub has revoked npm classic tokens for publishing; maintainers must migrate, but OpenJS warns OIDC trusted publishing still has risky gaps for critical projects.