[英]Webpack: Get map with all names of files in a directory
I'm currently trying to get a map of all filenames in a folder within a Webpack project. 我目前正在尝试获取Webpack项目内文件夹中所有文件名的映射。 This is what I've tried: 这是我尝试过的:
import * as fs from 'fs';
const interfacesFolder = '../interfaces/';
fs.readdirSync(interfacesFolder).forEach(file => {
console.log(file)
})
But this don't works because it's no a backend script. 但这不起作用,因为它不是后端脚本。 So because is Webpack, I'm looking for a way to receive all filenames in my interfaces directory. 因此,因为是Webpack,我正在寻找一种在我的interfaces目录中接收所有文件名的方法。
Since you do not have access to your local filesystem in the frontend, you'll need to provide an API endpoint to gather the information you need from the backend. 由于您无权访问前端中的本地文件系统,因此您需要提供一个API终结点,以从后端收集所需的信息。
There are ways to read the contents of files in the local filesystem, (see How do I access and read a local file from html+javascript page running locally ) but this will not give you access to a directory listing. 有多种方法可以读取本地文件系统中的文件内容(请参阅如何从本地运行的html + javascript页面访问和读取本地文件 ),但这无法使您访问目录列表。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.