buildmind
v3.0.5
Published
Shared Vite build scripts for frontend projects
Readme
buildmind
Configurable Vite development and build commands, supporting Vue, React, and multi sub-app builds.
Requirements
- Node.js 20 or higher
- pnpm 9
Installation
pnpm add -D buildmind viteThe application's package.json can use the buildmind command directly:
{
"scripts": {
"dev": "buildmind dev --mode dev",
"build": "buildmind build --mode prod"
}
}buildmind.config.ts
The configuration file goes in the project root. Minimum configuration example:
import { defineConfig } from 'buildmind'
export default defineConfig({
framework: 'vue',
})Multi sub-app example:
import { defineConfig } from 'buildmind'
export default defineConfig({
framework: 'vue',
main: false,
apps: ['admin', 'portal'],
options: {
admin: {
viteBase: '/admin/',
routes: ['*'],
},
portal: {
viteBase: '/portal/',
routes: ['Home'],
},
},
})Route Generation Plugins
The buildmind core does not assume a project's router directory or manifest format. When routes need to be trimmed per sub-app, enable the corresponding plugin explicitly.
The Vue module routes plugin scans src/router/modules by default and generates
src/router/router.modules.generated.js:
import { defineConfig, vueRouterModules } from 'buildmind'
export default defineConfig({
framework: 'vue',
apps: ['portal'],
options: {
portal: { routes: ['Home'] },
},
buildmindPlugins: [vueRouterModules()],
})The React registry plugin reads src/config/route-registry.manifest.json by default and generates
src/config/route-registry.generated.[subapp].ts:
import { defineConfig, reactRouteRegistry } from 'buildmind'
export default defineConfig({
framework: 'react',
apps: ['portal'],
options: {
portal: { routes: ['Home'] },
},
buildmindPlugins: [reactRouteRegistry()],
})The manifest can use the generic only, exclude, and subapps overrides:
{
"Home": {
"defaultPath": "/",
"importPath": "@/views/home",
"subapps": {
"portal": {
"importPath": "@/views/portal/home"
}
}
},
"PortalSettings": {
"defaultPath": "/settings",
"importPath": "@/views/portal/settings",
"only": ["portal"]
}
}Both plugins' input and output paths can be overridden via plugin parameters. buildmindPlugins is for buildmind lifecycle plugins; plugins is still used for regular Vite plugins.
Alias
Relative paths in alias are resolved from the project root. Apart from @ pointing to src, no project-specific aliases are included:
import { defineConfig } from 'buildmind'
export default defineConfig({
framework: 'vue',
alias: {
'@shared': '../../packages/shared/src',
},
})When an application needs to read apps and options in browser code, use virtual:buildmind/config. This virtual module only exposes serializable runtime configuration and will not bundle aliases, plugins, or Node code into the browser:
import config from 'virtual:buildmind/config'TypeScript projects can add /// <reference types="buildmind/client" /> to their environment declarations.
Custom CLI options
Projects can declare custom command-line options without adding project-specific behavior to buildmind. Consumed options are available in the buildmind context, and can optionally be injected as Vite defines:
import { defineConfig } from 'buildmind'
export default defineConfig({
cli: {
options: {
login: {
type: 'string',
define: '__APP_LOGIN_WAY__',
},
},
},
define: {
__APP_LOGIN_WAY__: null,
},
})buildmind dev --mode dev --login jg --base jgHere --login is consumed by buildmind and overrides the project define default, while the undeclared
Vite option --base is preserved. The same custom options are supported by both dev and build.
Commands
buildmind dev [Vite args]
buildmind build [Vite args]
buildmind --helpBuild all sub-apps:
buildmind build --mode prod -- --subapps allPublishing
pnpm build obfuscates all JavaScript files in dist after TypeScript compilation; type declaration files are left untouched.
pnpm install
pnpm run pack:check
npm publish --access public