Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: build umd&iife bug #1641

Closed
wants to merge 1 commit into from
Closed

fix: build umd&iife bug #1641

wants to merge 1 commit into from

Conversation

demong89
Copy link

when i use vite to build umd&iife,
It has an error
image

Therefore, I checked the source code and found that the package can be completed by calling this function here

@netlify
Copy link

netlify bot commented Sep 26, 2022

Deploy Preview for unocss ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit fc742f7
🔍 Latest deploy log https://app.netlify.com/sites/unocss/deploys/633186649c1dd3000ac7e49b
😎 Deploy Preview https://deploy-preview-1641--unocss.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@antfu
Copy link
Member

antfu commented Sep 26, 2022

Can you explain a bit more about why this change would fix it? I remember it should be a bug of Vite 3.1

@Dunqing
Copy link
Member

Dunqing commented Sep 27, 2022

vite has fixed this issue, refer: vitejs/vite#10185

@demong89
Copy link
Author

demong89 commented Sep 27, 2022

Can you explain a bit more about why this change would fix it? I remember it should be a bug of Vite 3.1

This could be a boundary case.
image
In my code, String.prototype.replace.call does not execute.
I extracted code snippets to confirm this problem.
Therefore, method replacer is executed manually
`
function replacer(...arg) {
console.log(...arg);
}

const values = [];
console.log('执行了么1');

String.prototype.replace.call('!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vue")):"function"==typeof define&&define.amd?define(["exports","vue"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).vueUI={},e.Vue)}(this,(function(e,t){"use strict";const n={size:{type:String,default:"medium"},color:{type:String,default:"blue"},round:{type:Boolean,default:!1},plain:{type:Boolean,default:!1},icon:{type:String,default:""}},o=t.defineComponent({name:"SButton",props:n,setup(e,{slots:n}){const o={small:{x:"2",y:"1",text:"sm"},medium:{x:"3",y:"1.5",text:"base"},large:{x:"4",y:"2",text:"lg"}};return()=>t.createVNode("button",{class:\n py-${o[e.size].y}\n px-${o[e.size].x}\n ${e.round?"rounded-full":"rounded-lg"}\n bg-${e.color}-${e.plain?"100":"500"}\n hover:bg-${e.color}-400\n border-${e.color}-${e.plain,"500"}\n cursor-pointer\n border-solid\n text-${e.plain?e.color+"-500":"white"}\n text-${o[e.size].text}\n hover:text-white\n transition duration-300 ease-in-out transform hover:scale-105\n mx-1\n },[""!==e.icon?t.createVNode("i",{class:i-ic-baseline-${e.icon} p-3},null):"",n.default?n.default():""])}});const l=((e,t)=>{const n=e.__vccOpts||e;for(const[o,l]of t)n[o]=l;return n})({name:"SFCButton"},[["render",function(e,n,o,l,u,r){return t.openBlock(),t.createElementBlock("button",null,"SFC Button")}]]),u=t.defineComponent({name:"JSXButton",render:()=>t.createVNode("button",null,[t.createTextVNode("JSX Button")])}),r={install(e){console.log("install xxx",o),e.component(o.name,o),e.component(l.name,l),e.component(u.name,u)}};e.JSXButton=u,e.MyButton=o,e.SFCButton=l,e.default=r,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));',
/(\?")?#--unocss--\s*{\slayer\s:\s*(.+?);?\s*}/g,
(...args) => {
console.log('执行了么2');
values.push(replacer(...args));
return "";
});
console.log('执行了么3');
`

@demong89
Copy link
Author

Can you explain a bit more about why this change would fix it? I remember it should be a bug of Vite 3.1
The method replace :
When there is no match, the callback will not be executed.
image

@antfu
Copy link
Member

antfu commented Oct 6, 2022

Fixed with Vite 3.1.5

@antfu antfu closed this Oct 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants