
Security News
Frontier AI Is Now Critical Infrastructure
The Fable shutdown shows how quickly model access can become a business continuity risk for AI-dependent engineering teams.
@verve-kit/react-script
Advanced tools
优雅的 React + Webpack 开发工具包,支持 TypeScript、CSS Modules、热重载等现代化开发特性。
npm install @laconic/react-script
无需额外安装 webpack 相关依赖! 本包已内置所有必要的 webpack、babel、loader 等依赖。
安装后,你可以直接在项目中使用:
# 开发模式
npx react-script-crack start
# 生产构建
npx react-script-crack build
如果需要自定义配置,只需在项目根目录创建配置文件即可。
本工具包支持多种方式自定义 Webpack 配置,让你可以根据项目需求灵活调整构建行为。
工具包会自动读取以下环境变量文件(按优先级排序):
.env.${NODE_ENV} (如 .env.development, .env.production).envAPI_URL=$BASE_URL/api)# .env.development
NODE_ENV=development
REACT_APP_API_URL=http://localhost:3000/api
REACT_APP_DEBUG=true
API_PROXY_TARGET=http://localhost:8080
DEV_PORT=3000
AUTO_OPEN=true
# .env.production
NODE_ENV=production
REACT_APP_API_URL=https://api.example.com
REACT_APP_DEBUG=false
USE_CDN=true
ANALYZE=false
在项目根目录创建以下任一配置文件(按优先级排序):
webpack.config.ts (推荐,支持 TypeScript)webpack.config.jswebpack.config.mjswebpack.config.mts注意:用户项目中无需安装 webpack 相关依赖,所有依赖已内置在
@laconic/react-script中。配置文件中不要导入 webpack 相关模块。
// webpack.config.ts
import path from 'path';
export default {
// 路径别名配置
resolve: {
alias: {
'@': path.resolve(__dirname, 'src'),
'@components': path.resolve(__dirname, 'src/components'),
},
},
// 自定义入口文件(可选)
entry: './src/main.tsx',
// 输出配置(可选)
output: {
filename: 'bundle.[contenthash].js',
},
};
函数式配置更加灵活,可以根据环境动态生成配置:
// webpack.config.ts
import path from 'path';
import type { ConfigContext } from '@laconic/react-script';
export default ({ isDevelopment, env }: ConfigContext) => ({
// 路径别名
resolve: {
alias: {
'@': path.resolve(__dirname, 'src'),
'@components': path.resolve(__dirname, 'src/components'),
},
},
// 开发服务器代理
...(isDevelopment && {
devServer: {
proxy: {
'/api': {
target: env.API_PROXY_TARGET ?? 'http://localhost:8080',
changeOrigin: true,
},
},
},
}),
});
支持异步函数配置,可以动态加载配置:
// webpack.config.ts
import type { ConfigContext } from '@laconic/react-script';
export default async ({ isDevelopment }: ConfigContext) => {
// 异步加载配置
const dynamicConfig = await import('./config/webpack.dynamic.js');
return {
...dynamicConfig.default,
// 根据环境动态配置
devtool: isDevelopment ? 'eval-source-map' : 'source-map',
};
};
函数式配置会接收一个上下文对象,包含以下属性:
interface ConfigContext {
/** 当前模式:'development' | 'production' */
mode: string | undefined;
/** 是否为开发环境 */
isDevelopment: boolean;
/** 环境变量对象(包含用户的 .env 文件和系统环境变量) */
env: Record<string, string | undefined>;
}
webpack-merge 智能合并用户配置和默认配置Q: 配置文件不生效?
A: 确保配置文件在项目根目录,文件名正确(如 webpack.config.ts)
Q: 能否在配置文件中导入 webpack?
A: 不可以!用户项目中没有 webpack 依赖。所有 webpack 功能已内置,配置文件中只需导出配置对象即可
Q: TypeScript 类型错误?
A: 配置文件使用普通对象即可,无需 webpack 类型。如需类型提示可安装 @types/webpack(可选)
Q: 修改配置后不生效?
A: 开发环境下修改配置文件需要重启开发服务器
MIT
FAQs
Configuration and scripts for Create Crack.
We found that @verve-kit/react-script demonstrated a healthy version release cadence and project activity because the last version was released less than 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
The Fable shutdown shows how quickly model access can become a business continuity risk for AI-dependent engineering teams.

Security News
AI agents are pulling packages into environments no scanner is watching, creating exposure before security teams can see it.

Security News
GitHub Actions checkout now blocks risky pull_request_target checkouts by default to help prevent pwn request supply chain attacks.