【发布时间】:2021-11-19 08:15:45
【问题描述】:
我的文件夹中有 1000 张图像,我必须将所有这些图像导入到项目中。我试过这个:
import images from './img/*.jpg
它在本地主机上工作得很好,但是当我尝试将它部署在远程服务器上时,它会抛出一个错误:
???? Build failed.
8:44:50 AM: @parcel/core: Failed to resolve './../img/*.jpg' from './src/js/model.js'
8:44:50 AM: /opt/build/repo/src/js/model.js:1:18
8:44:50 AM: > 1 | import imgs from './../img/*.jpg';
8:44:50 AM: > | ^^^^^^^^^^^^^^^^^^^^
8:44:50 AM: 2 | import { AMOUNT_OF_IMAGES } from './config.js';
8:44:50 AM: 3 |
8:44:50 AM: @parcel/resolver-default: Cannot load file '../img/*.jpg' in './src/js'.
8:44:50 AM: ???? Did you mean '../img/1.jpg'?
8:44:50 AM: ???? Did you mean '../img/2.jpg'?
我的 package.json:
{
"default": "index.html",
"scripts": {
"start": "parcel index.html",
"build": "parcel build index.html -d ./dist --no-minify"
},
"license": "ISC",
"devDependencies": {
"@parcel/transformer-image": "^2.0.0-rc.0",
"parcel": "^2.0.0-rc.0",
"parcel-bundler": "1.12.5"
},
"dependencies": {
"core-js": "^3.18.0",
"img": "^3.0.3",
"regenerator-runtime": "^0.13.9"
}
}
【问题讨论】:
-
“将图像导入项目”是什么意思?仅供参考,Javascript 关键字
import不接受文件名中的通配符。import关键字必须指向单个模块文件。 -
我觉得你得一一导入。
标签: javascript node.js import bundler parceljs