[英]How do I import Vue Material (Webpack UMD) using ESM?
I have a pug file with the following... 我有以下的哈巴狗档案...
#footer
script(type="module")
| import Vue from '/vue/vue.esm.browser.js'
| import { JRGVue } from '/ui/index.js'
| import VueMaterial from '/material/vue-material.js'
| (()=>{
| const vue = new JRGVue(Vue);
| vue.app.use(VueMaterial);
| vue.app.$mount('#jg-app');
| })();
I get 我懂了
Uncaught SyntaxError: The requested module '/material/vue-material.js' does not provide an export named 'default'
未捕获到的SyntaxError:请求的模块'/material/vue-material.js'不提供名为'default'的导出
When I change it to 当我将其更改为
import * as VueMaterial from '/material/vue-material.js'
I get 我懂了
Uncaught TypeError: _vue2.default is not a constructor
What is the proper way to import the Vue Material library using ESM? 使用ESM导入Vue材质库的正确方法是什么?
It does seem to work with Vuetify 它似乎与Vuetify一起使用
#footer
script(type="module")
| import Vue from '/vue/vue.esm.browser.js'
| window.Vue = Vue;
script(type="module")
| import * as Vuetify from '/vuetify/vuetify.js';
| import { JRGVue } from '/ui/index.js';
| Vue.use(Vuetify);
| const vue = new JRGVue(Vue);
| vue.app.$mount('#jg-app');
No longer seems to be working with the newest version. 似乎不再使用最新版本。 It would be really nice to find a UI with native ESM support
找到具有本机ESM支持的UI真是太好了
In case the import refers to vue-material
library, a correct way to import it is: 如果导入引用
vue-material
库,则正确的导入方法是:
import VueMaterial from 'vue-material';
And bundle the application with it. 并将应用程序与其捆绑在一起。
It's impossible to import it with native ES modules ( <script type="module">
). 使用本机ES模块(
<script type="module">
)导入它是不可能的。
It's possible to import packages that were built as ES modules (eg vue.esm.browser.js
for vue
) but vue-material
doesn't have ES6 entry point. 可以导入构建为ES模块的软件包(例如
vue
vue.esm.browser.js
),但是vue-material
没有ES6入口点。
In case /material/vue-material.js
refers to vue-material/dist/vue-material.js
, it is UMD module which cannot be imported by ES module without module interop. 如果
/material/vue-material.js
引用vue-material/dist/vue-material.js
,则它是UMD模块,如果没有模块互操作,则ES模块无法导入该模块。
ES module that could be imported is vue-material/src/index.js
but it cannot be imported directly because the package uses source files that aren't compliant with specs (.vue, .scss) and need to be built. 可以导入的ES模块是
vue-material/src/index.js
但不能直接导入,因为该软件包使用的文件不符合规范(.vue,.scss),需要构建。
A way to import vue-material
UMD module at runtime is to use SystemJS for module interop. 在运行时导入Vue
vue-material
UMD模块的一种方法是使用SystemJS进行模块互操作。
Also, IIFE is an antipattern in module scope. 同样,IIFE在模块范围内也是一种反模式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.