originjs / vite-plugins

Other
173 stars 28 forks source link

开启了 `transformMixedEsModules: true`, vite preview 依然报错 - require 是动态引入 #43

Open haiting opened 1 year ago

haiting commented 1 year ago

开启了 transformMixedEsModules: true, require 动态引入文件, vite preview 依然报错

if (a) {
    require('a.js');
    require('b.scss');
}

if (b) {
    require(c.js');
}

或者:

function registeredLayoutStore() {
  return {
    state: require('./store/state').default,
    actions: require('./store/actions').default,
    getters: require('./store/getters').default,
    mutations: require('./store/mutations').default
  };
}

Originally posted by @u373693041 in https://github.com/originjs/vite-plugins/issues/9#issuecomment-1132634279

wmo123 commented 1 year ago

请问问题解决了吗?

haiting commented 1 year ago

registeredLayoutStore

没呢,改了代码引用方式

export function useLayoutStoreWithOut() {
  return {
    state: { ...state },
    actions: { ...actions },
    getters: { ...getters },
    mutations: { ...mutations }
  };
}
JasonBoy commented 1 year ago

动态改静态我也不行 🤦 ,第三方ui库,vue组件里混着写。。。,或者能让这插件支持build么?

CleanShot 2023-09-06 at 16 56 46@2x