cx-chat 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/vite.config.ts +88 -80
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cx-chat",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "dev": "vite",
package/vite.config.ts CHANGED
@@ -126,6 +126,17 @@ export default defineConfig(({ mode }) => {
126
126
  const enableObfuscate =
127
127
  isProd && String(fileEnv.BUILD_OBFUSCATE || '').trim() === 'true'
128
128
 
129
+ /** npm 库入口(与 build.lib 同开);库模式会 inlineDynamicImports,不可再用 manualChunks */
130
+ const buildAsLib = true
131
+ const libConfig = buildAsLib
132
+ ? {
133
+ entry: path.resolve(__dirname, 'src/index.js'),
134
+ name: 'CxChat',
135
+ fileName: (format: string) => `cx-chat.${format}.js`,
136
+ formats: ['es', 'umd'] as ('es' | 'umd')[],
137
+ }
138
+ : undefined
139
+
129
140
  return {
130
141
  base,
131
142
  plugins: [
@@ -166,12 +177,7 @@ export default defineConfig(({ mode }) => {
166
177
  },
167
178
  },
168
179
  build: {
169
- lib: {
170
- entry: path.resolve(__dirname, 'src/index.js'),
171
- name: 'CxChat',
172
- fileName: (format) => `cx-chat.${format}.js`,
173
- formats: ['es', 'umd'],
174
- },
180
+ ...(libConfig ? { lib: libConfig } : {}),
175
181
  sourcemap: false,
176
182
  /**
177
183
  * 生产默认用 esbuild 压缩(CI 上比 Terser 快一个数量级)。
@@ -184,81 +190,83 @@ export default defineConfig(({ mode }) => {
184
190
  drop: ['console', 'debugger'],
185
191
  }
186
192
  : undefined,
187
- rollupOptions: {
188
- output: {
189
- entryFileNames: 'assets/js/[name]-[hash].js',
190
- chunkFileNames(chunkInfo) {
191
- const n = String(chunkInfo.name ?? '')
192
- return n.startsWith('vendor-')
193
- ? 'assets/lib/[name]-[hash].js'
194
- : 'assets/js/[name]-[hash].js'
195
- },
196
- assetFileNames(assetInfo) {
197
- const n = (
198
- assetInfo.names?.[0] ??
199
- assetInfo.name ??
200
- ''
201
- ).toLowerCase()
202
- if (n.endsWith('.css')) {
203
- return 'assets/css/[name]-[hash][extname]'
204
- }
205
- if (/\.(woff2?|ttf|otf|eot)$/.test(n)) {
206
- return 'assets/font/[name]-[hash][extname]'
207
- }
208
- if (/\.(png|apng|jpe?g|gif|svg|webp|ico|avif)$/.test(n)) {
209
- return 'assets/img/[name]-[hash][extname]'
210
- }
211
- return 'assets/media/[name]-[hash][extname]'
212
- },
213
- manualChunks(id) {
214
- if (!id.includes('node_modules')) return
215
- if (
216
- id.includes('/react/') ||
217
- id.includes('/react-dom/') ||
218
- id.includes('/scheduler/')
219
- ) {
220
- return 'vendor-react'
221
- }
222
- if (id.includes('/react-router/')) {
223
- return 'vendor-router'
224
- }
225
- if (id.includes('/@emotion/')) {
226
- return 'vendor-emotion'
227
- }
228
- if (
229
- id.includes('/rc-table/') ||
230
- id.includes('/rc-tree/') ||
231
- id.includes('/rc-picker/') ||
232
- id.includes('/rc-field-form/')
233
- ) {
234
- return 'vendor-rc-heavy'
235
- }
236
- if (id.includes('/rc-')) {
237
- return 'vendor-rc'
238
- }
239
- if (
240
- id.includes('/antd/') ||
241
- id.includes('/@ant-design/')
242
- ) {
243
- return 'vendor-antd'
244
- }
245
- if (
246
- id.includes('/i18next/') ||
247
- id.includes('/react-i18next/')
248
- ) {
249
- return 'vendor-i18n'
250
- }
251
- if (
252
- id.includes('/crypto-js/') ||
253
- id.includes('/axios/') ||
254
- id.includes('/dayjs/')
255
- ) {
256
- return 'vendor-utils'
257
- }
258
- return
193
+ rollupOptions: buildAsLib
194
+ ? {}
195
+ : {
196
+ output: {
197
+ entryFileNames: 'assets/js/[name]-[hash].js',
198
+ chunkFileNames(chunkInfo) {
199
+ const n = String(chunkInfo.name ?? '')
200
+ return n.startsWith('vendor-')
201
+ ? 'assets/lib/[name]-[hash].js'
202
+ : 'assets/js/[name]-[hash].js'
203
+ },
204
+ assetFileNames(assetInfo) {
205
+ const n = (
206
+ assetInfo.names?.[0] ??
207
+ assetInfo.name ??
208
+ ''
209
+ ).toLowerCase()
210
+ if (n.endsWith('.css')) {
211
+ return 'assets/css/[name]-[hash][extname]'
212
+ }
213
+ if (/\.(woff2?|ttf|otf|eot)$/.test(n)) {
214
+ return 'assets/font/[name]-[hash][extname]'
215
+ }
216
+ if (/\.(png|apng|jpe?g|gif|svg|webp|ico|avif)$/.test(n)) {
217
+ return 'assets/img/[name]-[hash][extname]'
218
+ }
219
+ return 'assets/media/[name]-[hash][extname]'
220
+ },
221
+ manualChunks(id) {
222
+ if (!id.includes('node_modules')) return
223
+ if (
224
+ id.includes('/react/') ||
225
+ id.includes('/react-dom/') ||
226
+ id.includes('/scheduler/')
227
+ ) {
228
+ return 'vendor-react'
229
+ }
230
+ if (id.includes('/react-router/')) {
231
+ return 'vendor-router'
232
+ }
233
+ if (id.includes('/@emotion/')) {
234
+ return 'vendor-emotion'
235
+ }
236
+ if (
237
+ id.includes('/rc-table/') ||
238
+ id.includes('/rc-tree/') ||
239
+ id.includes('/rc-picker/') ||
240
+ id.includes('/rc-field-form/')
241
+ ) {
242
+ return 'vendor-rc-heavy'
243
+ }
244
+ if (id.includes('/rc-')) {
245
+ return 'vendor-rc'
246
+ }
247
+ if (
248
+ id.includes('/antd/') ||
249
+ id.includes('/@ant-design/')
250
+ ) {
251
+ return 'vendor-antd'
252
+ }
253
+ if (
254
+ id.includes('/i18next/') ||
255
+ id.includes('/react-i18next/')
256
+ ) {
257
+ return 'vendor-i18n'
258
+ }
259
+ if (
260
+ id.includes('/crypto-js/') ||
261
+ id.includes('/axios/') ||
262
+ id.includes('/dayjs/')
263
+ ) {
264
+ return 'vendor-utils'
265
+ }
266
+ return
267
+ },
268
+ },
259
269
  },
260
- },
261
- },
262
270
  },
263
271
  }
264
272
  })