UNPKG

@bbc/spartacus

Version:
93 lines (86 loc) 2.76 kB
/* eslint-disable import/no-dynamic-require, global-require */ const path = require('path'); // `shell` parameter populated via CLI, e.g. --env.platform=web module.exports = (CONFIG_FILE, appDirectory) => { const resolvePath = relativePath => path.resolve(appDirectory, relativePath); const merge = require(`${appDirectory}/node_modules/webpack-merge`); const IS_PROD = process.env.NODE_ENV === 'production'; const IS_CI = process.env.CI; const START_DEV_SERVER = !IS_PROD; const stats = IS_PROD ? {} : { // reduce verbosity of console output assets: false, children: false, chunks: false, hash: false, modules: false, publicPath: false, timings: false, version: false, warnings: true, colors: true, // color the console output in terminal entrypoints: false, }; const baseConfig = { mode: IS_PROD ? 'production' : 'development', devtool: IS_PROD ? 'source-map' : 'cheap-eval-source-map', resolve: { symlinks: false, // allow linking of spartacus locally. Source: https://webpack.js.org/configuration/resolve/#resolvesymlinks extensions: ['.js', '.jsx'], // resolves `import '../Foo'` to `../Foo/index.jsx` }, devServer: { stats, }, stats, node: { // tell Webpack to provide a polyfill for this functionality. __filename: true, __dirname: true, }, context: appDirectory, // set the context for webpack as the parent application module: { rules: [ // tell Webpack to use the .babelrc to know how to transform JS/JSX to ES2015 JS { test: /\.(js|jsx|mjs)$/, include: /src/, use: [ { loader: 'babel-loader', options: { babelrc: true, cacheDirectory: true, presets: [], }, }, ], }, ], }, // This is to override bundle performance test. @TODO explain better performance: IS_CI ? { maxAssetSize: 245760, // 240kb - individual bundles maxEntrypointSize: 491520, // 480kb - total bundles } : undefined, }; const mergeIntoBaseConfig = app => { const specialisedConfig = require(`./webpack.config.${app}.js`)({ resolvePath, IS_PROD, IS_CI, START_DEV_SERVER, appDirectory, }); return merge(baseConfig, specialisedConfig); }; // if we've passed env.config, just compile that one file if (CONFIG_FILE) { return mergeIntoBaseConfig(CONFIG_FILE); } // else compile both (we've run `webpack` on its own) return ['client', 'server'].map(mergeIntoBaseConfig); };