Answer the question
In order to leave comments, you need to log in
How to check files synchronously in Node?
Can't read file names synchronously (problem via callback). How to do such operations correctly?
const fs = require('fs');
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
function findFiles(dir, regExp) {
return fs.readdir(dir, (err, files) => {
if (err) throw err;
return files.filter(file => regExp.test(file));
});
}
module.exports = dirname => {
let HTMLFiles = findFiles(path.resolve(dirname, 'examples'), /\.m?js$/);
return {
plugins: HTMLFiles.map(file => new HtmlWebpackPlugin({
inject: false,
template: path.resolve(dirname, `examples/${file}`)
}))
};
};
Answer the question
In order to leave comments, you need to log in
function findFiles(dir, regExp) {
const files = fs.readdirSync(dir);
return files.filter(file => regExp.test(file));
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question