Answer the question
In order to leave comments, you need to log in
How to merge configs that have Promise with webpack-merge?
Hello!
There are two webpack configs: dev and prod. They are merged with common config using webpack-merge
Webpack 2
Abbreviated:
webpack.dev.js
const webpackMerge = require('webpack-merge');
const commonConfig = require('./webpack.common.js');
const config = {
...
};
module.exports = function (options) {
return webpackMerge(commonConfig({env: ENV}), config);
}
const config = {
...
};
let pages = new Array();
let promise = new Promise((resolve, reject) => {
fs.readdir('./src/templates', function (err, files) {
files
.filter(function(file) { return file.substr(-4) === '.ejs'; })
.forEach(function (file) {
pages.push({
name: file.replace('.ejs', '.html'),
template: './src/templates/' + file
});
});
resolve(pages);
});
});
promise.then(result => {
result.forEach(function (page) {
config.plugins.push(
new HtmlWebpackPlugin({
template: page.template,
filename: page.name,
inject: 'body',
chunksSortMode: 'dependency',
minify: false
})
);
});
module.exports = function (options) {
return config;
};
});
Answer the question
In order to leave comments, you need to log in
Only if you write a nodejs script that launches the webpack compiler when the promise resolves. But the easiest way is to scan the directory synchronously, for example via glob.sync . I did this on more than one project and there are no problems.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question