mirror of
https://github.com/embarklabs/embark.git
synced 2025-01-12 23:05:07 +00:00
91e5e9c990
For file changes that do not require a webpack run, ie HTML, the assets will still be copied to the output directory, but webpack will not run (as it’s too slow).
57 lines
1.9 KiB
JavaScript
57 lines
1.9 KiB
JavaScript
|
|
const {errorMessage} = require('../../utils/utils');
|
|
const fs = require('../../core/fs');
|
|
|
|
class WebpackConfigReader {
|
|
constructor(options) {
|
|
this.webpackConfigName = options.webpackConfigName;
|
|
}
|
|
|
|
async readConfig(callback){
|
|
const dappConfigPath = fs.dappPath('webpack.config.js');
|
|
const defaultConfigPath = fs.embarkPath('lib/modules/pipeline', 'webpack.config.js');
|
|
|
|
let config, configPath;
|
|
try {
|
|
if (fs.existsSync(dappConfigPath)) {
|
|
configPath = dappConfigPath;
|
|
delete require.cache[configPath];
|
|
} else {
|
|
configPath = defaultConfigPath;
|
|
}
|
|
config = require(configPath);
|
|
// valid config types: https://webpack.js.org/configuration/configuration-types/
|
|
// + function that returns a config object
|
|
// + function that returns a promise for a config object
|
|
// + array of named config objects
|
|
// + config object
|
|
if (typeof config === 'function') {
|
|
// if(Promise.resolve(config)){
|
|
// return config(this.webpackConfigName).then(config => {
|
|
// callback(null, config);
|
|
// });
|
|
// }
|
|
|
|
config = await config(this.webpackConfigName);
|
|
//return callback(null, config);
|
|
} else if (Array.isArray(config)) {
|
|
config = config.filter(cfg => cfg.name === this.webpackConfigName);
|
|
if (!config.length) {
|
|
return callback(`no webpack config has the name '${this.webpackConfigName}'`);
|
|
}
|
|
if (config.length > 1) {
|
|
console.warn(`detected ${config.length} webpack configs having the name '${this.webpackConfigName}', using the first one`);
|
|
}
|
|
config = config[0];
|
|
//return callback(null, config);
|
|
}
|
|
callback(null, config);
|
|
} catch (e) {
|
|
console.error(`error while loading webpack config ${configPath}`);
|
|
callback(errorMessage(e));
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = WebpackConfigReader;
|