Est-il possible de charger un fichier .json via html-webpack-plugin et de le passer à mes fichiers du guidon ?
ma configuration actuelle
const path = require('path');
const fs = require('fs');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const webpack = require('webpack');
const extractCss = new ExtractTextPlugin({
filename: './css/app.css'
});
const pages = fs
.readdirSync(path.resolve(__dirname, 'src/hbs/pages'))
.filter(fileName => fileName.endsWith('.hbs'));
module.exports = {
context: path.resolve(__dirname, "src"),
entry: './js/main.js',
output: {
path: path.resolve(__dirname, './build'),
filename: 'js/app.js',
},
...
...
plugins: [
new CleanWebpackPlugin(['build']),
extractCss,
...pages.map(page => new HtmlWebpackPlugin({
template: 'hbs/pages/'+page,
filename: page
}))
],
module: {
rules: [
//babel-loader
{
test: /\.js$/,
include: /src/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
options: {
presets: ['env']
}
}
},
...
...
//handlebars-loader
{
test: /\.(hbs)$/,
loader: "handlebars-loader",
query: {
helperDirs: [
__dirname + "/hbs/helpers"
]
}
}
]
}
};
Je veux avoir un dossier avec des fichiers comme list1.json, list2.json... qui sera très grand, afin de ne pas abîmer mon fichier .hbs.
quelque chose comme
...pages.map(page => new HtmlWebpackPlugin({
template: 'hbs/pages/'+page,
filename: page,
data: myData.json
}))
serait génial
applaudissements, Gregor ;)