AABBbaby

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

Web开发者福音!创建第一个Vite支持的Web应用(1/2)

在这篇文章中,我们将解决前端 Web 开发人员的需求,并向您展示如何使用 Vite 库来显着提高 Javascript 客户端应用程序的启动/更新速度。

Vite 是一个基于开发服务器的构建工具,它在启动应用程序之前组装 JavaScript 代码,同时Vite还有助于在进行更改时减少加载速度,并允许您几乎可以立即查看结果。

Vite将代码创建为ES模块——现代浏览器可以用来加载JavaScript的模块,在依赖较大的情况下,Vite 会预先捆绑这些模块,以减少浏览器对 Web 服务器的请求数量。在以下部分中,我们将向您展示如何将Vite添加到由DevExtreme提供支持的React Reporting应用程序中。

DevExtreme v22.1正式版下载

创建示例DevExtreme应用程序

首先,使用DevExtreme CLI 从模板生成一个新应用程序:

npx -p devextreme-cli devextreme new react-app devextreme-react-sample --template="typescript"
cd devextreme-react-sample

DevExpress文档查看器添加一个视图:

npx devextreme add view document-viewer

DevExpress Report Designer添加一个视图:

npx devextreme add view report-designer

配置应用程序来使用Vite和DevExpress Reports

首先,修改 package.json 文件:

1. 添加dependencies:

"@devexpress/analytics-core": "^22.1.2",
"devexpress-reporting": "^22.1.2",
"jquery-ui-dist": "1.13.1"

2. 添加devDependencies:

"@vitejs/plugin-react": "^1.3.0",
"vite": "^2.9.9"

3. 将脚本部分替换为以下内容:

"scripts": {
"start": "vite",
"build": "vite build",
"preview": "vite preview",
"build-themes": "devextreme build",
"postinstall": "npm run build-themes"
},

然后,修改 index.html 文件:

1. 将 index.html 文件从 public 文件夹移动到项目根文件夹。

2. 从 index.html 文件中删除 %PUBLIC_URL% 字符串。

3. 向 index.html 文件添加入口点:

<body class="dx-viewport">
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<script type="module" src="/src/jquery.js"></script>
<script type="module" src="/src/jquery-ui.js"></script>
<script type="module" src="/src/index.tsx"></script>
</body>

4. 添加具有以下内容的文件 src/jquery-ui.js:

import "jquery-ui-dist/jquery-ui";

5. 添加具有以下内容的文件 src/jquery.js:

import jQuery from "jquery";
Object.assign(window, { $: jQuery, jQuery })

6. 在根文件夹中添加一个 vite.config.js 文件,内容如下:

import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'

// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
build: {
rollupOptions: {
treeshake: false
}
}
})

DevExpress Reporting | 下载试用

DevExpress Reporting是.NET Framework下功能完善的报表平台,它附带了易于使用的Visual Studio报表设计器和丰富的报表控件集,包括数据透视表、图表,因此您可以构建无与伦比、信息清晰的报表。


DevExpress技术交流群6:600715373      欢迎一起进群讨论

更多DevExpress线上公开课、中文教程资讯请上中文网获取

posted on   AABBbaby  阅读(64)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
历史上的今天:
2019-08-15 DevExpress ASP.NET Core v19.1版本亮点:Rich Text Editor
点击右上角即可分享
微信分享提示