[英]Importing a vuejs component without npm install or webpack
I am trying to include this component in my project: https://www.npmjs.com/package/vuejs-auto-complete我正在尝试将此组件包含在我的项目中: https://www.npmjs.com/package/vuejs-auto-complete
The problem is I am not allowed to use npm install.问题是我不允许使用 npm 安装。 We are not using npm or webpack on the project (something about a small footprint and minimizing dependencies) so all I have to work with is LibMan.
我们没有在项目中使用 npm 或 webpack(关于占用空间小和最小化依赖关系的东西)所以我只需要使用 LibMan。
I found the component on unpkg using LibMan and "installed" it.我使用 LibMan 在 unpkg 上找到了该组件并“安装”了它。 However this only gave me two files: dist/build.js and build.js.map (I assume this is some webpack thing).
然而,这只给了我两个文件:dist/build.js 和 build.js.map(我认为这是一些 webpack 的东西)。
Unlike other components I got from unpkg, (which give me something like component.esm.js to work with) I am unable to import the component from the file:与我从 unpkg 获得的其他组件不同,(它给了我类似 component.esm.js 的东西)我无法从文件中导入组件:
import { Autocomplete } from "../../lib/vuejs-auto-complete/dist/build.js";
gives me给我
SyntaxError: import not found: Autocomplete
语法错误:找不到导入:自动完成
I have tried the component in a side project, where I used npm install, and it worked fine.我在一个辅助项目中尝试了该组件,我使用了 npm 安装,它工作正常。
How do I make it work in my scenario?如何让它在我的场景中工作?
You have to import Autocomplete as a default import like so:您必须将自动完成导入为默认导入,如下所示:
import Autocomplete from '../path/to/dist/build.js';
or use node's require()
function:或使用节点的
require()
function:
const Autocomplete = require('../path/to/dist/build.js');
You have to import it like this:你必须像这样导入它:
import Autocomplete from "../../lib/vuejs-auto-complete/dist/build.js";
And then in components section:然后在组件部分:
components: {Autocomplete}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.