silverstripe-webpack/webpack.configuration.js

34 lines
904 B
JavaScript
Raw Normal View History

2018-02-22 20:39:58 +07:00
/*
2018-06-23 17:27:06 +07:00
* Load webpack configuration from app/_config/webpack.yml
2018-02-22 20:39:58 +07:00
*/
2018-04-21 11:29:32 +07:00
const path = require('path');
2019-05-23 18:02:32 +07:00
const filesystem = require('fs');
2018-04-21 11:29:32 +07:00
const fs = require('fs');
const yaml = require('js-yaml');
2019-05-23 18:02:32 +07:00
2018-06-23 17:27:06 +07:00
const conf = yaml.safeLoad(fs.readFileSync(path.join(__dirname, 'app/_config/webpack.yml'), 'utf8'));
2018-02-05 18:11:01 +07:00
2019-05-23 18:02:32 +07:00
let themes = [];
// add themes
if (conf['Site\\Templates\\WebpackTemplateProvider'].THEMESDIR) {
2019-06-08 22:54:43 +07:00
const themeDir = conf['Site\\Templates\\WebpackTemplateProvider'].THEMESDIR;
const dir = path.resolve(__dirname, themeDir);
2019-05-23 18:02:32 +07:00
2019-06-08 22:54:43 +07:00
if (filesystem.existsSync(dir)) {
filesystem.readdirSync(dir).forEach((file) => {
filePath = path.join(themeDir, file);
const stat = filesystem.statSync(filePath);
2019-05-23 18:02:32 +07:00
2019-06-08 22:54:43 +07:00
if (stat && stat.isDirectory()) {
themes.push(filePath);
}
});
}
2019-05-23 18:02:32 +07:00
}
module.exports = {
2019-06-08 22:54:43 +07:00
configuration: conf['Site\\Templates\\WebpackTemplateProvider'],
themes: themes,
2019-05-23 18:02:32 +07:00
};