front end develop toolkit, which support multi bundler(ex: webpack/vite/...) and multi framework(ex: react/vue/...)
Note: This project is still under development, and is not ready for production use.
- 📦 Multi Bundler Support
- 🛠 Multi Framework Support
- 🚀 Open API Support: support generate request client code with open api spec, both v2 and v3, see DTS
- ⚙️ Dynamic Configuration: support dynamic configuration, see Dynamic Configuration
npm install -D @pixas/cli
Note: you need to install the corresponding bundler package, such as @pixas/bundler-webpack
.
Currently Supported Bundlers:
-
webpack
npm install -D @pixas/bundler-webpack
-
vite
npm install -D @pixas/bundler-vite
-
mako
npm install -D @pixas/bundler-mako
- start dev server
pixas dev
- build project
pixas build
- generate request client code
pixas dts
- generate specific environment configuration file
pixas env
pixas
can run with zero configuration, but you can also configure it to meet your needs.
pixas
use cosmiconfig
to load configuration, you can configure it in the following ways:
pixas.config.js
pixas.config.ts
pixas
field inpackage.json
- etc.
export default {
name: 'pixas',
};
You can use defineConfig
to define the configuration with type checking and code completion:
import { defineConfig } from '@pixas/cli';
export default defineConfig({
name: 'pixas',
});
For typescript users, you can use pixas.config.ts
:
import { AppConfig } from '@pixas/cli';
const config: AppConfig = {
name: 'pixas',
};
export default config;
name
: project nameversion
: project versiondescription
: project descriptionlogo
: project logo image path, used in the html template and faviconglobals
: global environment variables, see Dynamic Configurationbundler
: bundler to use, default iswebpack
type
: project type, currently supportspa
onlydts
: dts configuration, see DTS
All the configuration options are optional, you can use the default configuration.
pixas
support generate request client code with open api spec, both v2 and v3 are supported, it is based on opas
, for more details, see opas
, or you can use opas
directly.
pixas dts
the generated code will be output to the src
directory, it contains follow modules:
apis
: request functionsinterfaces
: request request and response type definitionsservices
: request service for each module
// pixas.config.ts
import { defineConfig } from '@pixas/cli';
export default defineConfig({
dts: {
modules: [
{
namespace: 'pet-store',
url: 'https://petstore.swagger.io/v2/swagger.json',
},
],
},
});
modules
: open api modules to generate, each module contains the following options:namespace
: module namespaceurl
: open api spec urlbasePath
: base path of the api, default extract from the open api specextractField
: extract field from the response data, supportstring
|string[]
consider the following scenario:
- you have a project which contains multiple runtime configurations, such as
development
,staging
,production
, etc. - if you want to switch the runtime configuration, you need to rebuild the project, which is not convenient.
- you want to switch the runtime configuration at runtime or just restart, without rebuilding the project.
pixas
provides a solution to this problem, which is to support dynamic configuration at runtime.
we split the configuration into two parts:
-
static configuration
: the configuration that is determined at build time, such asNODE_ENV
,APP_VERSION
, etc. -
dynamic configuration
: the configuration that is determined at runtime, such asAPP_NAME
and what we want to make dynamic.
pixas
support configuration environment variables by using .env
file. you can define the dynamic configuration in the .env
file, and use it in your code. as the same usage as before, all the environment variables defined in the .env
file will be injected into the process.env
object, and we use prefix to distinguish the dynamic configuration from the static configuration, all the dynamic configuration will be prefixed with APP_
and others are static configuration.
For example:
# .env
# static configuration
NODE_ENV=development
APP_VERSION=1.0.0
# dynamic configuration
APP_NAME=pixas
// src/index.js
console.log(process.env.NODE_ENV); // development
console.log(process.env.APP_VERSION); // 1.0.0
console.log(process.env.APP_NAME); // pixas
In addition to the above methods, you can also explicitly configure it in pixas.config.ts
// pixas.config.ts
export default {
globals: {
compile: ['NODE_ENV', 'APP_VERSION'],
runtime: ['APP_NAME'],
},
};
There are some internal environment variables that are always be treated as static configuration:
NODE_ENV
: node environmentAPP_VERSION
: project versionBIZ_ENV
: business environment, such asdevelopment
,staging
,production
, etc.