From d67d60c52b5b3b17e8d3ed8dd1abc7a95856649a Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Sun, 3 Jun 2018 14:18:41 +0930 Subject: [PATCH] Update for new JS directory structure + multiple entry points + sourcemaps --- js-packages/webpack-config/index.js | 46 ++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/js-packages/webpack-config/index.js b/js-packages/webpack-config/index.js index 612c1cce4..dbf9a3963 100644 --- a/js-packages/webpack-config/index.js +++ b/js-packages/webpack-config/index.js @@ -1,8 +1,24 @@ +const fs = require('fs'); const path = require('path'); const webpack = require('webpack'); module.exports = function(options = {}) { - const config = { + return { + // Set up entry points for each of the forum + admin apps, but only + // if they exist. + entry: function() { + const entries = {}; + + for (const app of ['forum', 'admin']) { + const file = path.resolve(process.cwd(), 'js/' + app + '/index.js'); + if (fs.existsSync(file)) { + entries[app] = file; + } + } + + return entries; + }(), + module: { rules: [ { @@ -23,21 +39,31 @@ module.exports = function(options = {}) { ] }, + output: { + path: path.resolve(process.cwd(), 'js') + }, + // For backwards compatibility, search for non-relative-path modules - // in the `src` and `lib` directories. Also make sure the root node_modules - // directory is searched, otherwise importing a module from a file - // inside `lib` won't work. + // in the source directories. Also make sure the root node_modules + // directory is searched. resolve: { modules: [ - path.resolve(process.cwd(), 'src'), - path.resolve(process.cwd(), '../lib'), + path.resolve(process.cwd(), 'js/forum'), + path.resolve(process.cwd(), 'js/admin'), + path.resolve(process.cwd(), 'js/common'), path.resolve(process.cwd(), 'node_modules'), 'node_modules' ] }, - // Support importing old-style core modules. externals: [ + { + '@flarum/core/forum': 'flarum', + '@flarum/core/admin': 'flarum', + 'jquery': 'jQuery' + }, + + // Support importing old-style core modules. function(context, request, callback) { let matches; if ((matches = /^flarum\/(.+)$/.exec(request))) { @@ -45,8 +71,8 @@ module.exports = function(options = {}) { } callback(); } - ] - }; + ], - return config; + devtool: 'source-map' + }; };