记录Rollup打包vue项目过程中,出现的问题

301 阅读1分钟

1.@rollup/plugin-node-resolve

装了此插件,并在rollup.config.js中引用,会报错

[Vue warn]: onMounted is called when there is no active component instance to be associated with. Lifecycle injection APIs can only be used during execution of setup().

import resolve from '@rollup/plugin-node-resolve';

image.png

2. @rollup/plugin-node-resolve和@rollup/plugin-commonjs 慎重安装

3. @rollup/plugin-typescript 编译ts文件

如果引用了ts文件,需要安装该依赖,在rollup.config.js中引用,不然会报错

[!] Error: Could not resolve '../../../model/border-size-data' from src/package/img/src/index.ts

import typescript from '@rollup/plugin-typescript';

image.png

4. 图片编译 打包编译后 文件没有引入 --

问题:require('../../../assets/logo.png');没有编译

配置文件需要改成 module要设为commonjs,target要设为es5,require才会编译。

require是commjs标准,esnext都是用的模块了