diff options
author | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2021-12-02 02:08:08 +0300 |
---|---|---|
committer | John Molakvoæ <skjnldsv@protonmail.com> | 2022-01-08 12:11:58 +0300 |
commit | b664aad7abdca5327684b1218ac78fa172f8acb3 (patch) | |
tree | 0c1b04c2f8d3cf9b68d82e430f4754ff523a5f71 /webpack.common.js | |
parent | 8ee7c20e4d634f85a9b481b4a829cc65e277bc69 (diff) |
Move bundles to /dist
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Diffstat (limited to 'webpack.common.js')
-rw-r--r-- | webpack.common.js | 45 |
1 files changed, 25 insertions, 20 deletions
diff --git a/webpack.common.js b/webpack.common.js index cb9b0d0a806..0656b389b31 100644 --- a/webpack.common.js +++ b/webpack.common.js @@ -7,40 +7,45 @@ const ESLintPlugin = require('eslint-webpack-plugin') const modules = require('./webpack.modules.js') +const formatOutputFromModules = (modules) => { + // merge all configs into one object, and use AppID to generate the fileNames + // with the following format: + // AppId-fileName: path/to/js-file.js + const moduleEntries = Object.keys(modules).map(moduleKey => { + const module = modules[moduleKey] + + const entries = Object.keys(module).map(entryKey => { + const entry = module[entryKey] + return { [`${moduleKey}-${entryKey}`]: entry } + }) + + return Object.assign({}, ...Object.values(entries)) + }) + return Object.assign({}, ...Object.values(moduleEntries)) +} + const modulesToBuild = () => { const MODULE = process.env.MODULE if (MODULE) { if (!modules[MODULE]) { throw new Error(`No module "${MODULE}" found`) } - return modules[MODULE] + return formatOutputFromModules({ + [MODULE]: modules[MODULE] + }) } - // merge all configs into one object - return Object.assign({}, ...Object.values(modules)) + + return formatOutputFromModules(modules) } module.exports = { entry: modulesToBuild(), output: { // Step away from the src folder and extract to the js folder - path: path.join(__dirname), + path: path.join(__dirname, 'dist'), publicPath: '/dist/', - filename: (chunkData) => { - // Get relative path of the src folder - let srcPath = chunkData.chunk.entryModule.context - if (srcPath === null) { - srcPath = chunkData.chunk.entryModule.rootModule.context - } - const relativePath = path.relative(__dirname, srcPath) - - // If this is a core source, output in core dist folder - if (relativePath.indexOf('core/src') > -1) { - return path.join('core/js/dist/', '[name].js?v=[contenthash]') - } - // Get out of the shared dist folder and output inside apps js folder - return path.join(relativePath, '..', 'js') + '/[name].js?v=[contenthash]' - }, - chunkFilename: 'dist/[name]-[id].js?v=[contenthash]', + filename: '[name].js?v=[contenthash]', + chunkFilename: '[name]-[id].js?v=[contenthash]', }, module: { |