首页 > 其他分享 >Pag动画:umi+libpag+copy-webpack-plugin实现及问题解决

Pag动画:umi+libpag+copy-webpack-plugin实现及问题解决

时间:2024-07-26 15:07:00浏览次数:7  
标签:node plugin modules js webpack libpag workspace jenkins

1、package.json添加如下,安装依赖:

"libpag": "^4.2.84",
"copy-webpack-plugin": "9.1.0",  为什么是写死的旧版本,后面解释

2、使用的方法,这里只是一个小示例,具体如何使用看个人(这里主要是想记录过程中出现的问题及解决方式):


  const init = async () => {       const PagInfo = await LibpagUtils.init() as any; // LibpagUtils为封装好的方法       playPag(PagInfo)   }

const playPag = (PagInfo: any) => { const { url, repeatCount } = props || {} const { PAGFile, PAGView } = PagInfo fetch(url).then((response) => { (window as any).globalThis = window; return response.arrayBuffer() }).then(async (buffer) => { const pagFile = await PAGFile.load(buffer); const pagView = await PAGView.init(pagFile, canvasRef.current); // 判定监听事件 pagViewAddListener(pagView); setPagView(pagView); // 0 表示无限次 pagView.setRepeatCount(repeatCount || 0); await pagView.play(); }); }

3、copy-webpack-plugin的使用,我这里是umi项目,在config/config.ts目录中添加如下:

const CopyPlugin = require('copy-webpack-plugin');
const path = require('path');  // 这个插件没有的话先安装

chainWebpack: (memo: WebpackChain) => {
    ...... // 其他的插件使用
    memo.plugin('CopyPlugin').use(
      new CopyPlugin({
        patterns: [{ from: path.resolve(__dirname, '../node_modules/libpag/lib/libpag.wasm'), to: '../dist' }], // dist为打包后的静态文件路径
      })
    )
  }

4、到这里都是很顺利的,本地调试播放也很顺利,但当在jenkins部署到测试时出现如下错误:

HookWebpackError: Invalid host defined options
    at makeWebpackError (/data/jenkins/workspace/。。。(隐私处理)/node_modules/@umijs/deps/compiled/webpack/5/bundle5.js:108568:9)
    at /data/jenkins/workspace/。。。/node_modules/@umijs/deps/compiled/webpack/5/bundle5.js:93433:12
    at eval (eval at create (/data/jenkins/workspace/。。。/node_modules/@umijs/deps/compiled/webpack/5/bundle5.js:50186:10), <anonymous>:99:1)
    at /data/jenkins/workspace/。。。/node_modules/@umijs/deps/compiled/webpack/5/bundle5.js:91405:26
    at /data/jenkins/workspace/。。。/node_modules/copy-webpack-plugin/dist/index.js:710:13
-- inner error --
TypeError: Invalid host defined options
    at /data/jenkins/workspace/。。。/node_modules/copy-webpack-plugin/dist/index.js:706:13
    at fn (/data/jenkins/workspace/。。。/node_modules/@umijs/deps/compiled/webpack/5/bundle5.js:91404:9)
    at _next0 (eval at create (/data/jenkins/workspace/。。。/node_modules/@umijs/deps/compiled/webpack/5/bundle5.js:50186:10), <anonymous>:96:1)
    at eval (eval at create (/data/jenkins/workspace/。。。/node_modules/@umijs/deps/compiled/webpack/5/bundle5.js:50186:10), <anonymous>:113:1)
    at Hook.eval [as callAsync] (eval at create (/data/jenkins/workspace/。。。/node_modules/@umijs/deps/compiled/webpack/5/bundle5.js:50186:10), <anonymous>:6:1)
    at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/data/jenkins/workspace/。。。/node_modules/@umijs/deps/compiled/webpack/5/bundle5.js:49988:14)
    at /data/jenkins/workspace/。。。/node_modules/@umijs/deps/compiled/webpack/5/bundle5.js:91410:46
    at /data/jenkins/workspace/。。。/node_modules/@umijs/deps/compiled/copy-webpack-plugin/cjs.js:1:279358
caused by plugins in Compilation.hooks.processAssets
TypeError: Invalid host defined options
    at /data/jenkins/workspace/。。。/node_modules/copy-webpack-plugin/dist/index.js:706:13
    at fn (/data/jenkins/workspace/。。。/node_modules/@umijs/deps/compiled/webpack/5/bundle5.js:91404:9)
    at _next0 (eval at create (/data/jenkins/workspace/。。。/node_modules/@umijs/deps/compiled/webpack/5/bundle5.js:50186:10), <anonymous>:96:1)
    at eval (eval at create (/data/jenkins/workspace/。。。/node_modules/@umijs/deps/compiled/webpack/5/bundle5.js:50186:10), <anonymous>:113:1)
    at Hook.eval [as callAsync] (eval at create (/data/jenkins/workspace/。。。/node_modules/@umijs/deps/compiled/webpack/5/bundle5.js:50186:10), <anonymous>:6:1)
    at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/data/jenkins/workspace/。。。/node_modules/@umijs/deps/compiled/webpack/5/bundle5.js:49988:14)
    at /data/jenkins/workspace/。。。/node_modules/@umijs/deps/compiled/webpack/5/bundle5.js:91410:46
    at /data/jenkins/workspace/。。。/node_modules/@umijs/deps/compiled/copy-webpack-plugin/cjs.js:1:279358
build failed
Error: build failed
    at /data/jenkins/workspace/。。。/node_modules/@umijs/bundler-webpack/lib/index.js:172:29
    at /data/jenkins/workspace/。。。/node_modules/@umijs/deps/compiled/webpack/5/bundle5.js:114591:14
    at /data/jenkins/workspace/。。。/node_modules/@umijs/deps/compiled/webpack/5/bundle5.js:114422:12
    at /data/jenkins/workspace/。。。/node_modules/@umijs/deps/compiled/webpack/5/bundle5.js:38249:7
    at done (/data/jenkins/workspace/。。。/node_modules/@umijs/deps/compiled/webpack/5/bundle5.js:38284:11)
    at /data/jenkins/workspace/。。。/node_modules/@umijs/deps/compiled/webpack/5/bundle5.js:38237:7
    at /data/jenkins/workspace/。。。/node_modules/@umijs/deps/compiled/webpack/5/bundle5.js:114419:8
    at arrayEach (/data/jenkins/workspace/。。。/node_modules/@umijs/deps/compiled/webpack/5/bundle5.js:37824:9)
    at Object.each (/data/jenkins/workspace/。。。/node_modules/@umijs/deps/compiled/webpack/5/bundle5.js:38265:9)
    at nodeDone (/data/jenkins/workspace/。。。/node_modules/@umijs/deps/compiled/webpack/5/bundle5.js:114413:21)
    at finalCallback (/data/jenkins/workspace/。。。/node_modules/@umijs/deps/compiled/webpack/5/bundle5.js:95870:32)
    at onCompiled (/data/jenkins/workspace/。。。/node_modules/@umijs/deps/compiled/webpack/5/bundle5.js:95879:20)
    at /data/jenkins/workspace/。。。/node_modules/@umijs/deps/compiled/webpack/5/bundle5.js:96554:25
    at finalCallback (/data/jenkins/workspace/。。。/node_modules/@umijs/deps/compiled/webpack/5/bundle5.js:93172:11)
    at /data/jenkins/workspace/。。。/node_modules/@umijs/deps/compiled/webpack/5/bundle5.js:93432:18
    at eval (eval at create (/data/jenkins/workspace/。。。/node_modules/@umijs/deps/compiled/webpack/5/bundle5.js:50186:10), <anonymous>:99:1)

5、尝试了很多方式,都没找到出现问题的原因,最后找到了解决的方式,将copy-webpack-plugin从版本12多降到9.1.0解决问题。

 

标签:node,plugin,modules,js,webpack,libpag,workspace,jenkins
From: https://www.cnblogs.com/atao24/p/18325387

相关文章

  • Nuxt3的plugins使用有哪些?
    Nuxt3是一个服务端渲染(ssr)框架在项目中,(1)有一些全局使用方法,不想每次使用都要单独导入,而不想像平时的框架项目,总是要export,然后频繁的import,现在nuxt3可以用plugins的provide注入全局方法,但是其实不同于Vue的provide  Nuxt的provide:可注入全局方法,解决全局方法多处导......
  • 无法解析插件 org.apache.maven.plugins:maven-war-plugin:3.2.3(已解决)
    文章目录1、问题出现的背景2、解决方法1、问题出现的背景最开始我想把springboot项目转为javaweb项目,然后我点击下面这个插件就转为javaweb项目了,但是我后悔了,想要还原成springboot项目,点开项目结构关于web的都移除了,还是不行,控制台报下面的错误无法解析插件org.......
  • webpack入门最简单的demo
    1、在空文件夹下npminit-y2、npminstall--save-devwebpack3、新建src文件夹,在src里新建index.html,写入:<!DOCTYPEhtml><htmllang="en"><head><metacharset="utf-8"><title>WebpackDemo</title></hea......
  • 自动导入unplugin-auto-import+unplugin-vue-components
    文章介绍接下来将会以Vite+Vue3+TS的项目来举例实现在我们进行项目开发时,无论是声明响应式数据使用的ref、reactive,或是各种生命周期,又或是computed、watch、watchEffect、provide-inject。这些都需要前置引入才能使用:import{ref,reactive,onMounted,watch,provid......
  • JS之webpack
    目录一、认识webpack1.1webpack数组形式1.2webpackde对象形式一、认识webpackWebpack是一个现代的静态模块打包工具,它主要用于前端开发中的模块化打包和构建。通过Webpack,开发者可以将多个模块(包括JavaScript、CSS、图片等)进行打包,生成优化后的静态资源文件,以供在浏览器中加......
  • 创建SpringBoot项目时出现Cannot resolve plugin org.springframework的解决方法 原
    创建SpringBoot项目时出现Cannotresolvepluginorg.springframework的解决方法原因是添加依赖时未添加版本号原因是添加依赖时未添加版本号解决方法:在pom.xml文件中的依赖添加版本号原来:<plugin><groupId>org.springframework.boot</groupId><a......
  • 类明显存在却报 package not found, Java程序中专门被其他工程所依赖的common jar用sp
    先上官方链接:https://docs.spring.io/spring-boot/docs/2.1.0.RELEASE/maven-plugin/examples/repackage-classifier.html在使用SpringBoot构建通用JAR库时,尤其是当通springboot默认的过spring-boot-maven-plugin插件打包时。如果遇到了类存在但报“packagenotfound......
  • 关于Webpack的原理
    目录具体原理多环境打包的具体问题相应注解具体原理一句话解释就是:解析配置、构建依赖图、解析模块并自动化代码分割,生成文件、输出到指定目录中以下是具体说明:1.解析配置:Webpack根据配置确定入口文件、输出路径、加载器和插件等。2.构建依赖图:从配置的入口文......
  • webpack 打包后复制文件
    写在前面项目中使用一些特定依赖的时候,会定义全局暴露的变量,不希望webpack将其压缩混淆,期望在打包后的成果物中保留原样。copy-webpack-plugin首先想到使用webpack插件copy-webpack-plugin,可以直接复制原始资源到输出目录中(非最优解!)安装依赖npminstallcopy-webpack-pl......
  • 2024-07-18 浅尝rollup-plugin-visualizer——文件打包分析体积大小
    前言:vite+vue项目rollup-plugin-visualizer:一个用于Rollup构建系统的插件,它能够生成可视化的报告,展示你的项目构建后的模块依赖关系和文件大小。仓库:https://github.com/btd/rollup-plugin-visualizer安装:yarnaddrollup-plugin-visualizer配置(vite.config.ts):import{......