UNPKG

kk-webpack-base--config

Version:

Webpack config for kk-webpack-base

87 lines (74 loc) 2.09 kB
const path = require('path'); const { config } = require('../webpack.project-config.js'); const fs = require('fs'); const { lorem, pageLink } = require('./common-functions'); const isProd = process.env.NODE_ENV === 'prod' || process.env.NODE_ENV === 'production'; const pimcoreConfig = require('./config-pimcore.js'); exports.data = (context) => { const defaultData = { editmode: false }; const files = ['twig-data.js']; let filesData = {}; files.forEach((fileName) => { const file = path.join(process.cwd(), `${config.sourcePath}${fileName}`); const ext = fileName.split('.').pop(); const fileData = (() => { if (fs.existsSync(file)) { context.addDependency(file); // Force webpack to watch file if (ext === 'json') { return context.fs.readJsonSync(file, { throws: false }) || {}; } if (ext === 'js') { const thisFile = require(file); return thisFile.data; } } })(); filesData = { ...filesData, ...fileData }; }); return { ...defaultData, ...filesData, isProd: isProd }; }; exports.functions = { ...pimcoreConfig.functions, icon( name = false, size = 24, rotation = false, viewBox = false, path = '/assets' ) { if (!name) { return ''; } let attrArr = []; if (rotation) { attrArr.push(`data-rotate="${rotation}"`); } if (viewBox) { attrArr.push(`viewBox="${viewBox}"`); } attrArr.push(`data-size="${size || 'auto'}"`); return ` <svg ${attrArr.join(' ')}> <use href="${path}/iconset.svg#${name}"></use> </svg> `; }, lorem: lorem, pageLink: pageLink, }; exports.namespaces = (() => { let namespaces = {}; if (config.twigNamespaces) { Object.keys(config.twigNamespaces).forEach((twigNamespaceKey) => { namespaces = { ...namespaces, [twigNamespaceKey]: path.join( process.cwd(), `${config.sourcePath}twig/${config.twigNamespaces[twigNamespaceKey]}` ), }; }); } return namespaces; })();