Skip to content

Commit 6726d57

Browse files
committed
更新 package.json 文件:将版本号从 1.0.4 升级到 1.0.5,新增 exports 配置以支持模块导出。更新 src/index.ts 文件,确保样式依赖正确加载并添加组件类型声明。修改 vite.config.ts 文件,禁用 CSS 代码分割并直接指定 CSS 文件名。
--------------------------- 修改样式导入方式
1 parent 69c0ff8 commit 6726d57

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

package.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
{
22
"name": "vue-expression-editor",
3-
"version": "1.0.4",
3+
"version": "1.0.5",
44
"description": "A powerful Vue 3 mathematical expression editor component",
55
"main": "dist/index.js",
66
"module": "dist/index.mjs",
77
"types": "dist/types/index.d.ts",
88
"style": "dist/index.css",
9+
"exports": {
10+
".": {
11+
"types": "./dist/types/index.d.ts",
12+
"import": "./dist/index.mjs",
13+
"require": "./dist/index.js"
14+
},
15+
"./dist/index.css": {
16+
"import": "./dist/index.css",
17+
"require": "./dist/index.css"
18+
}
19+
},
920
"files": [
1021
"dist",
1122
"README.md",

src/index.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
import { App } from 'vue'
22
import ExpressionEditor from './components/ExpressionEditor.vue'
3-
// 引入基础样式
3+
4+
// 确保样式依赖被正确加载,注意引入顺序
5+
import './components/styles/variables.scss'
46
import './components/styles/base.scss'
57
import './components/styles/buttons.scss'
68
import './components/styles/input.scss'
79
import './components/styles/layout.scss'
810
import './components/styles/theme.scss'
911

12+
// 添加组件类型声明
13+
declare module 'vue' {
14+
export interface GlobalComponents {
15+
ExpressionEditor: typeof ExpressionEditor
16+
}
17+
}
18+
1019
const install = (app: App) => {
1120
app.component('ExpressionEditor', ExpressionEditor)
1221
}
1322

14-
// 直接导出组件
1523
ExpressionEditor.install = install
1624

1725
export { ExpressionEditor }

vite.config.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ export default defineConfig(({ mode }) => {
1212
vue(),
1313
!isDemo && dts({
1414
include: ['src/**/*.ts', 'src/**/*.vue'],
15+
copyDtsFiles: true,
1516
})
1617
].filter(Boolean),
1718
build: {
1819
outDir: isDemo ? 'demo-dist' : 'dist',
19-
cssCodeSplit: true,
20+
cssCodeSplit: false, // 禁用 CSS 代码分割,将所有 CSS 打包到一个文件
2021
...(isDemo ? {
2122
// 演示页面构建配置
2223
rollupOptions: {
@@ -38,10 +39,7 @@ export default defineConfig(({ mode }) => {
3839
vue: 'Vue',
3940
'element-plus': 'ElementPlus'
4041
},
41-
assetFileNames: (assetInfo) => {
42-
if (assetInfo.name === 'style.css') return 'index.css';
43-
return assetInfo.name;
44-
}
42+
assetFileNames: 'index.css' // 直接指定 CSS 文件名
4543
}
4644
}
4745
})

0 commit comments

Comments
 (0)