npm.io
0.14.6 • Published 8 months ago

vite-plugin-blocklet

Licence
ISC
Version
0.14.6
Deps
15
Size
74 kB
Vulns
0
Weekly
0

vite-plugin-blocklet

The Vite library plugin, which enhanced development of ArcBlock blocklet

Use examples

Example of front-end project

import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import { createBlockletPlugin } from 'vite-plugin-blocklet';
import { nodePolyfills } from 'vite-plugin-node-polyfills';

// https://vitejs.dev/config/
export default defineConfig(async () => {
  return {
    plugins: [react(), createBlockletPlugin(), nodePolyfills({ protocolImports: true })],
  };
});
Example of back-end project

api/index.js

const express = require('express');
const app = express();

module.exports = { app };

api/dev.js

const { setupClient } = require('vite-plugin-blocklet');
const { app } = require('./index');

setupClient(app);

package.json

"start": "NODE_ENV=development nodemon api/dev.js -w api",

Basically, you vite.config.js file should be in the root of project folders, if you need setup a custom vite config file, you should change your npm scripts, like:

package.json

"start": "NODE_ENV=development nodemon api/dev.js -w api -- --config=./config/vite.config.js",

Or you can just pass vite config file path to setupClient function, like this:

const { setupClient } = require('vite-plugin-blocklet');
const { app } = require('./index');

setupClient(app, { configFile: './config/vite.config.js'});