2018-02-22 14:39:58 +01:00
|
|
|
/*
|
|
|
|
* Common Environment
|
|
|
|
*/
|
|
|
|
|
2021-08-09 20:05:28 +02:00
|
|
|
const INDEX_NAME = 'app';
|
2021-05-03 19:11:13 +02:00
|
|
|
const YML_PATH = '/app/_config/webpack.yml';
|
2021-06-19 22:22:44 +02:00
|
|
|
const CONF_VAR = 'A2nt\\CMSNiceties\\Templates\\WebpackTemplateProvider';
|
2018-02-22 14:39:58 +01:00
|
|
|
|
2018-04-21 05:36:06 +02:00
|
|
|
const path = require('path');
|
2021-05-03 19:11:13 +02:00
|
|
|
const fs = require('fs');
|
|
|
|
const yaml = require('js-yaml');
|
|
|
|
const webpack = require('webpack');
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Load webpack configuration from webpack.yml
|
|
|
|
*/
|
|
|
|
|
2021-08-03 03:22:09 +02:00
|
|
|
const yml = yaml.load(
|
2021-05-03 19:11:13 +02:00
|
|
|
fs.readFileSync(path.join(__dirname, YML_PATH), 'utf8'),
|
|
|
|
);
|
2021-09-13 00:24:40 +02:00
|
|
|
const conf = yml[CONF_VAR];
|
2021-05-03 19:11:13 +02:00
|
|
|
|
|
|
|
let themes = [];
|
|
|
|
// add themes
|
|
|
|
if (conf.THEMESDIR) {
|
2021-09-13 00:24:40 +02:00
|
|
|
const themeDir = conf.THEMESDIR;
|
|
|
|
const dir = path.resolve(__dirname, themeDir);
|
|
|
|
|
|
|
|
if (fs.existsSync(dir)) {
|
|
|
|
fs.readdirSync(dir).forEach((file) => {
|
|
|
|
filePath = path.join(themeDir, file);
|
|
|
|
const stat = fs.statSync(filePath);
|
|
|
|
|
|
|
|
if (stat && stat.isDirectory()) {
|
|
|
|
themes.push(filePath);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2021-05-03 19:11:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Setup Entries */
|
2019-04-11 00:15:29 +02:00
|
|
|
const includes = {};
|
2019-05-23 13:02:32 +02:00
|
|
|
const modules = [
|
2021-02-26 05:28:19 +01:00
|
|
|
path.resolve(__dirname, conf.APPDIR, conf.SRC),
|
|
|
|
path.resolve(__dirname, conf.APPDIR, conf.SRC, 'js'),
|
|
|
|
path.resolve(__dirname, conf.APPDIR, conf.SRC, 'scss'),
|
|
|
|
path.resolve(__dirname, conf.APPDIR, conf.SRC, 'img'),
|
|
|
|
path.resolve(__dirname, conf.APPDIR, conf.SRC, 'thirdparty'),
|
|
|
|
path.resolve(__dirname, 'node_modules'),
|
|
|
|
path.resolve(__dirname),
|
|
|
|
path.resolve(__dirname, 'public'),
|
2019-05-23 13:02:32 +02:00
|
|
|
];
|
2019-04-11 00:15:29 +02:00
|
|
|
|
2020-07-20 12:25:57 +02:00
|
|
|
const _addAppFiles = (theme) => {
|
2021-02-26 05:28:19 +01:00
|
|
|
const dirPath = './' + theme;
|
|
|
|
let themeName = path.basename(theme);
|
|
|
|
if (themeName == '.') {
|
2021-09-13 00:24:40 +02:00
|
|
|
themeName = 'app';
|
2021-02-26 05:28:19 +01:00
|
|
|
}
|
|
|
|
|
2021-08-09 20:05:28 +02:00
|
|
|
if (fs.existsSync(path.join(dirPath, conf.SRC, 'js', INDEX_NAME + '.js'))) {
|
2021-09-13 00:24:40 +02:00
|
|
|
includes[`${themeName}`] = path.join(dirPath, conf.SRC, 'js', INDEX_NAME + '.js');
|
2021-02-26 05:28:19 +01:00
|
|
|
} else if (
|
2021-08-09 20:05:28 +02:00
|
|
|
fs.existsSync(path.join(dirPath, conf.SRC, 'scss', INDEX_NAME + '.scss'))
|
2021-02-26 05:28:19 +01:00
|
|
|
) {
|
2021-09-13 00:24:40 +02:00
|
|
|
includes[`${themeName}`] = path.join(
|
|
|
|
dirPath,
|
|
|
|
conf.SRC,
|
|
|
|
'scss',
|
|
|
|
INDEX_NAME + '.scss',
|
|
|
|
);
|
2021-02-26 05:28:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
modules.push(path.join(dirPath, conf.SRC, 'js'));
|
|
|
|
modules.push(path.join(dirPath, conf.SRC, 'scss'));
|
|
|
|
modules.push(path.join(dirPath, conf.SRC, 'img'));
|
|
|
|
modules.push(path.join(dirPath, conf.SRC, 'thirdparty'));
|
|
|
|
|
2021-09-13 00:24:40 +02:00
|
|
|
const _getAllFilesFromFolder = function (dir, includeSubFolders = true) {
|
2021-02-26 05:28:19 +01:00
|
|
|
const dirPath = path.resolve(__dirname, dir);
|
|
|
|
let results = [];
|
|
|
|
|
2021-05-03 19:11:13 +02:00
|
|
|
fs.readdirSync(dirPath).forEach((file) => {
|
2021-02-26 05:28:19 +01:00
|
|
|
if (file.charAt(0) === '_') {
|
2021-09-13 00:24:40 +02:00
|
|
|
return;
|
2021-02-26 05:28:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const filePath = path.join(dirPath, file);
|
2021-05-03 19:11:13 +02:00
|
|
|
const stat = fs.statSync(filePath);
|
2021-02-26 05:28:19 +01:00
|
|
|
|
|
|
|
if (stat && stat.isDirectory() && includeSubFolders) {
|
2021-09-13 00:24:40 +02:00
|
|
|
results = results.concat(
|
|
|
|
_getAllFilesFromFolder(filePath, includeSubFolders),
|
|
|
|
);
|
2021-02-26 05:28:19 +01:00
|
|
|
} else {
|
2021-09-13 00:24:40 +02:00
|
|
|
results.push(filePath);
|
2021-02-26 05:28:19 +01:00
|
|
|
}
|
2021-09-13 00:24:40 +02:00
|
|
|
});
|
2021-02-26 05:28:19 +01:00
|
|
|
|
|
|
|
return results;
|
2021-09-13 00:24:40 +02:00
|
|
|
};
|
2021-02-26 05:28:19 +01:00
|
|
|
|
|
|
|
// add page specific scripts
|
|
|
|
const typesJSPath = path.join(theme, conf.TYPESJS);
|
2021-05-03 19:11:13 +02:00
|
|
|
if (fs.existsSync(typesJSPath)) {
|
2021-09-13 00:24:40 +02:00
|
|
|
const pageScripts = _getAllFilesFromFolder(typesJSPath, true);
|
|
|
|
pageScripts.forEach((file) => {
|
|
|
|
includes[`${themeName}_${path.basename(file, '.js')}`] = file;
|
2021-02-26 05:28:19 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// add page specific scss
|
|
|
|
const typesSCSSPath = path.join(theme, conf.TYPESSCSS);
|
2021-05-03 19:11:13 +02:00
|
|
|
if (fs.existsSync(typesSCSSPath)) {
|
2021-09-13 00:24:40 +02:00
|
|
|
const scssIncludes = _getAllFilesFromFolder(typesSCSSPath, true);
|
|
|
|
scssIncludes.forEach((file) => {
|
|
|
|
includes[`${themeName}_${path.basename(file, '.scss')}`] = file;
|
2021-02-26 05:28:19 +01:00
|
|
|
});
|
|
|
|
}
|
2021-09-13 00:24:40 +02:00
|
|
|
};
|
2018-02-05 12:11:01 +01:00
|
|
|
|
2019-04-11 00:15:29 +02:00
|
|
|
_addAppFiles(conf.APPDIR);
|
2018-02-21 11:19:51 +01:00
|
|
|
|
2019-04-11 00:15:29 +02:00
|
|
|
// add themes
|
2021-05-03 19:11:13 +02:00
|
|
|
themes.forEach((theme) => {
|
2021-02-26 05:28:19 +01:00
|
|
|
_addAppFiles(theme);
|
2021-09-13 00:24:40 +02:00
|
|
|
});
|
2018-02-05 12:11:01 +01:00
|
|
|
|
2022-01-09 23:59:45 +01:00
|
|
|
const UIInfo = require('./node_modules/@a2nt/ss-bootstrap-ui-webpack-boilerplate-react/package.json');
|
2022-05-27 18:08:09 +02:00
|
|
|
const UINAME = JSON.stringify(UIInfo.name);
|
2022-01-09 23:59:45 +01:00
|
|
|
const UIVERSION = JSON.stringify(UIInfo.version);
|
|
|
|
const UIMetaInfo = require('./node_modules/@a2nt/meta-lightbox-js/package.json');
|
|
|
|
|
|
|
|
const NODE_ENV = conf.NODE_ENV || process.env.NODE_ENV;
|
|
|
|
const COMPRESS = NODE_ENV === 'production' ? true : false;
|
|
|
|
|
|
|
|
const IP = process.env.IP || conf.HOSTNAME;
|
|
|
|
const PORT = process.env.PORT || conf.PORT;
|
|
|
|
|
|
|
|
console.log('NODE_ENV: ' + NODE_ENV);
|
|
|
|
console.log('COMPRESS: ' + COMPRESS);
|
|
|
|
console.log('WebP images: ' + conf['webp']);
|
|
|
|
console.log('GRAPHQL_API_KEY: ' + conf['GRAPHQL_API_KEY']);
|
|
|
|
|
|
|
|
const JSVARS = {
|
|
|
|
NODE_ENV: JSON.stringify(NODE_ENV),
|
2022-05-27 18:08:09 +02:00
|
|
|
UINAME: UINAME,
|
2022-01-15 14:12:12 +01:00
|
|
|
UIVERSION: UIVERSION,
|
|
|
|
UIAUTHOR: JSON.stringify(UIInfo.author),
|
|
|
|
UIMetaNAME: JSON.stringify(UIMetaInfo.name),
|
|
|
|
UIMetaVersion: JSON.stringify(UIMetaInfo.version),
|
|
|
|
GRAPHQL_API_KEY: JSON.stringify(conf['GRAPHQL_API_KEY']),
|
|
|
|
SWVERSION: JSON.stringify(`sw-${new Date().getTime()}`),
|
|
|
|
BASE_HREF: JSON.stringify(''),
|
|
|
|
};
|
2022-01-09 23:59:45 +01:00
|
|
|
|
2022-01-31 13:01:42 +01:00
|
|
|
const provides = {};
|
|
|
|
const externals = {};
|
|
|
|
const aliases = {};
|
|
|
|
|
|
|
|
if (!conf['JQUERY']) {
|
2023-10-23 18:57:41 +02:00
|
|
|
/*provides['react'] = 'React';
|
2022-01-31 13:01:42 +01:00
|
|
|
provides['react-dom'] = 'ReactDOM';
|
|
|
|
externals['react'] = 'React';
|
2023-10-23 18:57:41 +02:00
|
|
|
externals['react-dom'] = 'ReactDOM';*/
|
2022-01-31 13:01:42 +01:00
|
|
|
} else {
|
|
|
|
provides['$'] = 'jquery';
|
|
|
|
provides['jQuery'] = 'jquery';
|
|
|
|
externals['jquery'] = 'jQuery';
|
|
|
|
|
|
|
|
aliases['window.jQuery'] = require.resolve('jquery');
|
|
|
|
aliases['$'] = require.resolve('jquery');
|
|
|
|
aliases['jquery'] = require.resolve('jquery');
|
|
|
|
aliases['jQuery'] = require.resolve('jquery');
|
|
|
|
}
|
|
|
|
|
2018-02-05 12:11:01 +01:00
|
|
|
module.exports = {
|
2022-01-31 13:01:42 +01:00
|
|
|
PROVIDES: provides,
|
2022-01-09 23:59:45 +01:00
|
|
|
JSVARS: JSVARS,
|
2021-05-03 19:11:13 +02:00
|
|
|
configuration: conf,
|
|
|
|
themes: themes,
|
|
|
|
webpack: {
|
|
|
|
entry: includes,
|
2022-01-31 13:01:42 +01:00
|
|
|
externals: externals,
|
2021-05-03 19:11:13 +02:00
|
|
|
resolve: {
|
|
|
|
modules: modules,
|
2021-09-13 00:24:40 +02:00
|
|
|
extensions: ['.tsx', '.ts', '.js'],
|
2022-01-31 13:01:42 +01:00
|
|
|
alias: aliases,
|
2021-06-19 22:22:44 +02:00
|
|
|
fallback: {
|
2021-09-13 00:24:40 +02:00
|
|
|
path: false,
|
|
|
|
},
|
|
|
|
},
|
2021-05-03 19:11:13 +02:00
|
|
|
experiments: {
|
|
|
|
topLevelAwait: true,
|
2021-09-13 00:24:40 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|