uni-app vite4打包小程序控制台警告

rdrgkggo  于 3个月前  发布在  uni-app
关注(0)|答案(5)|浏览(40)

问题描述
引用utils中的方法,小程序打包出现了 Generated an empty chunk: "utils/commaFormatted".​ 的warn

复现步骤
[复现问题的步骤]
// src/utils/index.js

export { default as dayjs } from './dayjs';
export { default as getType } from './getType';
export { default as decodeParams } from './decodeParams';
export { default as commaFormatted } from './commaFormatted';
export { default as paramsToString } from './paramsToString';

// src/utils/getType.js

export default function (target, type) {
	const _type = Object.prototype.toString.call(target).slice(8, -1).toLocaleLowerCase();

	if (type) {
		return type === _type;
	}
	return _type;
}
...

// main.js

import { createSSRApp } from 'vue';
import { dayjs } from '@/utils/index';
import App from './App.vue';

export function createApp() {
	const app = createSSRApp(App);
	// 全局方法挂载
	app.config.globalProperties.$dayjs = dayjs;
	return {
		app
	};
}

预期结果
控制台没有

实际结果

请注意运行模式下,因日志输出、sourcemap 以及未压缩源码等原因,性能和包体积,均不及发行模式。若要正式发布,请点击发行菜单或使用 cli 发布命令进行发布
正在编译中...
​Generated an empty chunk: "utils/commaFormatted".​
​Generated an empty chunk: "utils/decodeParams".​
​Generated an empty chunk: "utils/getType".​
​Generated an empty chunk: "utils/paramsToString".​
DONE  Build complete. Watching for changes...

系统信息:

  • 发行平台: [微信小程序]
  • uni-app版本 ["@dcloudio/uni-app": "3.0.0-3071120230427001"]

补充信息
打包后utils文件夹下未引用的方法文件为空
直接引用utils方法没有警告
使用utils/index存在警告

ykejflvf

ykejflvf1#

刚升级了,样式文件丢失

5vf7fwbs

5vf7fwbs2#

刚升级了,样式文件丢失

遇到同样问题,我在代码里导出了组件,将以下代码干掉后,样式文件有了内容

export { default as xxx } from './xxx.vue'

bfhwhh0e

bfhwhh0e3#

问题描述 引用utils中的方法,小程序打包出现了 Generated an empty chunk: "utils/commaFormatted".​ 的warn

复现步骤 [复现问题的步骤] // src/utils/index.js

export { default as dayjs } from './dayjs';
export { default as getType } from './getType';
export { default as decodeParams } from './decodeParams';
export { default as commaFormatted } from './commaFormatted';
export { default as paramsToString } from './paramsToString';

// src/utils/getType.js

export default function (target, type) {
	const _type = Object.prototype.toString.call(target).slice(8, -1).toLocaleLowerCase();

	if (type) {
		return type === _type;
	}
	return _type;
}
...

// main.js

import { createSSRApp } from 'vue';
import { dayjs } from '@/utils/index';
import App from './App.vue';

export function createApp() {
	const app = createSSRApp(App);
	// 全局方法挂载
	app.config.globalProperties.$dayjs = dayjs;
	return {
		app
	};
}

预期结果 控制台没有

实际结果

请注意运行模式下,因日志输出、sourcemap 以及未压缩源码等原因,性能和包体积,均不及发行模式。若要正式发布,请点击发行菜单或使用 cli 发布命令进行发布
正在编译中...
​Generated an empty chunk: "utils/commaFormatted".​
​Generated an empty chunk: "utils/decodeParams".​
​Generated an empty chunk: "utils/getType".​
​Generated an empty chunk: "utils/paramsToString".​
DONE  Build complete. Watching for changes...

系统信息:

  • 发行平台: [微信小程序]
  • uni-app版本 ["@dcloudio/uni-app": "3.0.0-3071120230427001"]

补充信息 打包后utils文件夹下未引用的方法文件为空 直接引用utils方法没有警告 使用utils/index存在警告

遇到了同样问题,我把引入处改为条件编译后就没有警告了,看样子是在小程序还不能使用 export { default as xx } from 'xx':

导出

export { default as homeSchema } from './home-schema'  
export { default as tab1Schema } from './tab-first-schema'  
export { default as tab2Schema } from './tab-second-schema'  
export { default as tab3Schema } from './tab-third-schema'

引入

// #ifdef H5  
import { homeSchema, tab1Schema, tab2Schema, tab3Schema } from './pages/index'  
// #endif
gdrx4gfi

gdrx4gfi4#

问题描述 引用utils中的方法,小程序打包出现了 Generated an empty chunk: "utils/commaFormatted".​ 的warn
复现步骤 [复现问题的步骤] // src/utils/index.js

export { default as dayjs } from './dayjs';
export { default as getType } from './getType';
export { default as decodeParams } from './decodeParams';
export { default as commaFormatted } from './commaFormatted';
export { default as paramsToString } from './paramsToString';

// src/utils/getType.js

export default function (target, type) {
	const _type = Object.prototype.toString.call(target).slice(8, -1).toLocaleLowerCase();

	if (type) {
		return type === _type;
	}
	return _type;
}
...

// main.js

import { createSSRApp } from 'vue';
import { dayjs } from '@/utils/index';
import App from './App.vue';

export function createApp() {
	const app = createSSRApp(App);
	// 全局方法挂载
	app.config.globalProperties.$dayjs = dayjs;
	return {
		app
	};
}

预期结果 控制台没有
实际结果

请注意运行模式下,因日志输出、sourcemap 以及未压缩源码等原因,性能和包体积,均不及发行模式。若要正式发布,请点击发行菜单或使用 cli 发布命令进行发布
正在编译中...
​Generated an empty chunk: "utils/commaFormatted".​
​Generated an empty chunk: "utils/decodeParams".​
​Generated an empty chunk: "utils/getType".​
​Generated an empty chunk: "utils/paramsToString".​
DONE  Build complete. Watching for changes...

系统信息:

  • 发行平台: [微信小程序]
  • uni-app版本 ["@dcloudio/uni-app": "3.0.0-3071120230427001"]

补充信息 打包后utils文件夹下未引用的方法文件为空 直接引用utils方法没有警告 使用utils/index存在警告

遇到了同样问题,我把引入处改为条件编译后就没有警告了,看样子是在小程序还不能使用 export { default as xx } from 'xx':

导出

export { default as homeSchema } from './home-schema' export { default as tab1Schema } from './tab-first-schema' export { default as tab2Schema } from './tab-second-schema' export { default as tab3Schema } from './tab-third-schema'

引入

// #ifdef H5 import { homeSchema, tab1Schema, tab2Schema, tab3Schema } from './pages/index' // #endif

import dayjs  from './dayjs';
import getType from './getType';
import decodeParams from './decodeParams';
import commaFormatted from './commaFormatted';
import paramsToString from './paramsToString';

export {dayjs,getType,decodeParams,commaFormatted,paramsToString}

这么写跑微信小程序还是会有这个问题

zed5wv10

zed5wv105#

问题描述 引用utils中的方法,小程序打包出现了 Generated an empty chunk: "utils/commaFormatted".​ 的warn
复现步骤 [复现问题的步骤] // src/utils/index.js

export { default as dayjs } from './dayjs';
export { default as getType } from './getType';
export { default as decodeParams } from './decodeParams';
export { default as commaFormatted } from './commaFormatted';
export { default as paramsToString } from './paramsToString';

// src/utils/getType.js

export default function (target, type) {
	const _type = Object.prototype.toString.call(target).slice(8, -1).toLocaleLowerCase();

	if (type) {
		return type === _type;
	}
	return _type;
}
...

// main.js

import { createSSRApp } from 'vue';
import { dayjs } from '@/utils/index';
import App from './App.vue';

export function createApp() {
	const app = createSSRApp(App);
	// 全局方法挂载
	app.config.globalProperties.$dayjs = dayjs;
	return {
		app
	};
}

预期结果 控制台没有
实际结果

请注意运行模式下,因日志输出、sourcemap 以及未压缩源码等原因,性能和包体积,均不及发行模式。若要正式发布,请点击发行菜单或使用 cli 发布命令进行发布
正在编译中...
​Generated an empty chunk: "utils/commaFormatted".​
​Generated an empty chunk: "utils/decodeParams".​
​Generated an empty chunk: "utils/getType".​
​Generated an empty chunk: "utils/paramsToString".​
DONE  Build complete. Watching for changes...

系统信息:

  • 发行平台: [微信小程序]
  • uni-app版本 ["@dcloudio/uni-app": "3.0.0-3071120230427001"]

补充信息 打包后utils文件夹下未引用的方法文件为空 直接引用utils方法没有警告 使用utils/index存在警告

遇到了同样问题,我把引入处改为条件编译后就没有警告了,看样子是在小程序还不能使用 export { default as xx } from 'xx':
导出
export { default as homeSchema } from './home-schema' export { default as tab1Schema } from './tab-first-schema' export { default as tab2Schema } from './tab-second-schema' export { default as tab3Schema } from './tab-third-schema'
引入
// #ifdef H5 import { homeSchema, tab1Schema, tab2Schema, tab3Schema } from './pages/index' // #endif

import dayjs  from './dayjs';
import getType from './getType';
import decodeParams from './decodeParams';
import commaFormatted from './commaFormatted';
import paramsToString from './paramsToString';

export {dayjs,getType,decodeParams,commaFormatted,paramsToString}

这么写跑微信小程序还是会有这个问题

1、如果是组件使用了 export { default as xx } from 'xx.vue' 导出,这会导致运行的时候该组件的wxss文件内容为空,建议使用easycom作为替代方案。
2、如果是函数、变量使用了 export { default as xx } from 'xx.js' 导出,这将导致控制台 Generated an empty chunk警告,建议采用其他替换方案如:

xx.js

export const fn = () => {};
export const obj = {}
...

index.js

export * from 'xx.js'

相关问题