简体   繁体   English

Webpack:使用目录中文件的所有名称获取地图

[英]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.

相关问题 使用 webpack 获取目录中的所有路径 - Using webpack to get all paths in directory 如何获取 Node.js 目录中存在的所有文件的名称列表? - How do you get a list of the names of all files present in a directory in Node.js? 获取目录json中的所有文件 - Get all files in directory json 将目录中的所有文件作为 webpack 入口点的最佳方法? - Best way to have all files in a directory be entry points in webpack? 如何在没有require语句的情况下使用webpack加载目录中的所有文件 - How to load all files in a directory using webpack without require statements Webpack output 将同一个目录下的所有文件放到不同的文件夹中 - Webpack output all the files within a directory with the same name into a different folder 使用 webpack 时,有没有办法将目录中的文件列表放入变量中? - Is there any way to get a list of files in a directory into a variable when using webpack? 获取 chrome 扩展目录中所有文件的文件名? - Get filenames for all files in a chrome extension directory? AngularJS:获取src / app / templates目录中的所有文件名 - AngularJS: Get all file names in the src/app/templates directory Javascript / Webpack:如何使用自定义循环将文件中的所有json文件连接起来 - Javascript / webpack : how to concatenate all json files in directory with a custom loop over files
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM