diff --git a/apps/files/lib/Controller/ViewController.php b/apps/files/lib/Controller/ViewController.php index 06a6253adef..bba8660399c 100644 --- a/apps/files/lib/Controller/ViewController.php +++ b/apps/files/lib/Controller/ViewController.php @@ -197,7 +197,9 @@ class ViewController extends Controller { // Load the files we need \OCP\Util::addStyle('files', 'merged'); \OCP\Util::addScript('files', 'merged-index'); - \OCP\Util::addScript('files', 'dist/main'); + \OCP\Util::addScript('files', 'templates'); + \OCP\Util::addScript('files', 'files-app-settings'); + \OCP\Util::addScript('files', 'legacy-filelist-search'); // mostly for the home storage's free space // FIXME: Make non static diff --git a/apps/files/lib/Listener/LoadSidebarListener.php b/apps/files/lib/Listener/LoadSidebarListener.php index aa24538c2ee..15f24279e0a 100644 --- a/apps/files/lib/Listener/LoadSidebarListener.php +++ b/apps/files/lib/Listener/LoadSidebarListener.php @@ -37,7 +37,7 @@ class LoadSidebarListener implements IEventListener { return; } - Util::addScript(Application::APP_ID, 'dist/sidebar'); + Util::addScript(Application::APP_ID, 'sidebar'); // needed by the Sidebar legacy tabs // TODO: remove when all tabs migrated to the new api Util::addScript('files', 'fileinfomodel'); diff --git a/apps/files/src/main.js b/apps/files/src/main.js deleted file mode 100644 index a979822bdc4..00000000000 --- a/apps/files/src/main.js +++ /dev/null @@ -1,3 +0,0 @@ -import './files-app-settings' -import './templates' -import './legacy/filelistSearch' diff --git a/apps/files/templates/settings-personal.php b/apps/files/templates/settings-personal.php index 1cddae3d33d..7aefb470cd6 100644 --- a/apps/files/templates/settings-personal.php +++ b/apps/files/templates/settings-personal.php @@ -22,7 +22,7 @@ */ -script(\OCA\Files\AppInfo\Application::APP_ID, 'dist/personal-settings'); +script(\OCA\Files\AppInfo\Application::APP_ID, 'personal-settings'); ?>
diff --git a/apps/files_sharing/lib/AppInfo/Application.php b/apps/files_sharing/lib/AppInfo/Application.php index 056d246296f..befd1532d02 100644 --- a/apps/files_sharing/lib/AppInfo/Application.php +++ b/apps/files_sharing/lib/AppInfo/Application.php @@ -113,7 +113,7 @@ class Application extends App implements IBootstrap { /** * Always add main sharing script */ - Util::addScript(self::APP_ID, 'dist/main'); + Util::addScript(self::APP_ID, 'main'); } @@ -129,7 +129,7 @@ class Application extends App implements IBootstrap { $dispatcher->addServiceListener(LoadSidebar::class, LoadSidebarListener::class); $dispatcher->addServiceListener(ShareCreatedEvent::class, ShareInteractionListener::class); $dispatcher->addListener('\OCP\Collaboration\Resources::loadAdditionalScripts', function () { - \OCP\Util::addScript('files_sharing', 'dist/collaboration'); + \OCP\Util::addScript('files_sharing', 'collaboration'); }); $dispatcher->addServiceListener(ShareCreatedEvent::class, UserShareAcceptanceListener::class); $dispatcher->addServiceListener(UserAddedEvent::class, UserAddedToGroupListener::class); diff --git a/apps/files_sharing/lib/Listener/LoadAdditionalListener.php b/apps/files_sharing/lib/Listener/LoadAdditionalListener.php index f24dca62a00..8c11fec3999 100644 --- a/apps/files_sharing/lib/Listener/LoadAdditionalListener.php +++ b/apps/files_sharing/lib/Listener/LoadAdditionalListener.php @@ -38,9 +38,9 @@ class LoadAdditionalListener implements IEventListener { } // After files for the files list shared content - Util::addScript(Application::APP_ID, 'dist/files_sharing', 'files'); + Util::addScript(Application::APP_ID, 'files_sharing', 'files'); // After files for the breadcrumb share indicator - Util::addScript(Application::APP_ID, 'dist/additionalScripts', 'files'); + Util::addScript(Application::APP_ID, 'additionalScripts', 'files'); Util::addStyle(Application::APP_ID, 'icons'); } } diff --git a/apps/files_sharing/lib/Listener/LoadSidebarListener.php b/apps/files_sharing/lib/Listener/LoadSidebarListener.php index 9eac82e6024..cb5ebf8a792 100644 --- a/apps/files_sharing/lib/Listener/LoadSidebarListener.php +++ b/apps/files_sharing/lib/Listener/LoadSidebarListener.php @@ -37,6 +37,6 @@ class LoadSidebarListener implements IEventListener { return; } - Util::addScript(Application::APP_ID, 'dist/files_sharing_tab', 'files'); + Util::addScript(Application::APP_ID, 'files_sharing_tab', 'files'); } } diff --git a/apps/files_sharing/templates/Settings/personal.php b/apps/files_sharing/templates/Settings/personal.php index 0fe0e2f5445..30caeb16206 100644 --- a/apps/files_sharing/templates/Settings/personal.php +++ b/apps/files_sharing/templates/Settings/personal.php @@ -22,7 +22,7 @@ declare(strict_types=1); * */ -script(\OCA\Files_Sharing\AppInfo\Application::APP_ID, 'dist/personal-settings'); +script(\OCA\Files_Sharing\AppInfo\Application::APP_ID, 'personal-settings'); ?>
diff --git a/apps/systemtags/lib/AppInfo/Application.php b/apps/systemtags/lib/AppInfo/Application.php index 5fdd98f3526..cdc059d4a42 100644 --- a/apps/systemtags/lib/AppInfo/Application.php +++ b/apps/systemtags/lib/AppInfo/Application.php @@ -52,7 +52,7 @@ class Application extends App implements IBootstrap { $dispatcher->addListener( 'OCA\Files::loadAdditionalScripts', function () { - \OCP\Util::addScript('core', 'dist/systemtags'); + \OCP\Util::addScript('core', 'systemtags'); \OCP\Util::addScript(self::APP_ID, 'systemtags'); } ); diff --git a/apps/systemtags/templates/admin.php b/apps/systemtags/templates/admin.php index 33e5f2b061d..998e8628c3d 100644 --- a/apps/systemtags/templates/admin.php +++ b/apps/systemtags/templates/admin.php @@ -19,7 +19,7 @@ * */ -script('core', 'dist/systemtags'); +script('core', 'systemtags'); script('systemtags', 'admin'); style('systemtags', 'settings'); diff --git a/apps/user_status/lib/Listener/BeforeTemplateRenderedListener.php b/apps/user_status/lib/Listener/BeforeTemplateRenderedListener.php index 24090188170..c98e988a37c 100644 --- a/apps/user_status/lib/Listener/BeforeTemplateRenderedListener.php +++ b/apps/user_status/lib/Listener/BeforeTemplateRenderedListener.php @@ -99,7 +99,7 @@ class BeforeTemplateRenderedListener implements IEventListener { return ['profileEnabled' => $this->isProfileEnabled($account)]; }); - \OCP\Util::addScript('user_status', 'user-status-menu'); + \OCP\Util::addScript('user_status', 'user_status-menu'); \OCP\Util::addStyle('user_status', 'user-status-menu'); } } diff --git a/apps/workflowengine/lib/Listener/LoadAdditionalSettingsScriptsListener.php b/apps/workflowengine/lib/Listener/LoadAdditionalSettingsScriptsListener.php index dd1b345a69b..6c38051d41a 100644 --- a/apps/workflowengine/lib/Listener/LoadAdditionalSettingsScriptsListener.php +++ b/apps/workflowengine/lib/Listener/LoadAdditionalSettingsScriptsListener.php @@ -41,7 +41,7 @@ class LoadAdditionalSettingsScriptsListener implements IEventListener { class_exists(Template::class, true); } - script('core', 'dist/systemtags'); + script('core', 'systemtags'); script(Application::APP_ID, [ 'workflowengine', diff --git a/core/Controller/ProfilePageController.php b/core/Controller/ProfilePageController.php index 505dfa4e249..8b1ecb6c98e 100644 --- a/core/Controller/ProfilePageController.php +++ b/core/Controller/ProfilePageController.php @@ -143,7 +143,7 @@ class ProfilePageController extends Controller { $this->profileManager->getProfileParams($targetUser, $visitingUser), ); - \OCP\Util::addScript('core', 'dist/profile'); + \OCP\Util::addScript('core', 'profile'); return new TemplateResponse( 'core', diff --git a/core/templates/installation.php b/core/templates/installation.php index 5bdf8b0cc96..78d6e6e97a2 100644 --- a/core/templates/installation.php +++ b/core/templates/installation.php @@ -1,5 +1,5 @@ '> '> diff --git a/core/templates/login.php b/core/templates/login.php index eab2ee4c604..6b4b9285240 100644 --- a/core/templates/login.php +++ b/core/templates/login.php @@ -1,6 +1,6 @@
diff --git a/core/templates/recommendedapps.php b/core/templates/recommendedapps.php index 2fe13355278..e51189ec137 100644 --- a/core/templates/recommendedapps.php +++ b/core/templates/recommendedapps.php @@ -21,7 +21,7 @@ * along with this program. If not, see . */ -script('core', 'dist/recommendedapps'); +script('core', 'recommendedapps'); ?> diff --git a/lib/base.php b/lib/base.php index 75459fc6b42..91544c949c2 100644 --- a/lib/base.php +++ b/lib/base.php @@ -292,7 +292,7 @@ class OC { // render error page $template = new OC_Template('', 'update.user', 'guest'); - OC_Util::addScript('dist/maintenance'); + OC_Util::addScript('maintenance'); OC_Util::addStyle('core', 'guest'); $template->printPage(); die(); diff --git a/lib/private/Template/JSResourceLocator.php b/lib/private/Template/JSResourceLocator.php index 3f6b2b49e10..1017b8c3a06 100644 --- a/lib/private/Template/JSResourceLocator.php +++ b/lib/private/Template/JSResourceLocator.php @@ -48,11 +48,14 @@ class JSResourceLocator extends ResourceLocator { return; } + // Extracting the appId and the script file name + $app = substr($script, 0, strpos($script, '/')); + $scriptName = basename($script); + if (strpos($script, '/l10n/') !== false) { // For language files we try to load them all, so themes can overwrite // single l10n strings without having to translate all of them. $found = 0; - $found += $this->appendIfExist($this->serverroot, 'core/'.$script.'.js'); $found += $this->appendIfExist($this->serverroot, $theme_dir.'core/'.$script.'.js'); $found += $this->appendIfExist($this->serverroot, $script.'.js'); $found += $this->appendIfExist($this->serverroot, $theme_dir.$script.'.js'); @@ -65,16 +68,16 @@ class JSResourceLocator extends ResourceLocator { } elseif ($this->appendIfExist($this->serverroot, $theme_dir.'apps/'.$script.'.js') || $this->appendIfExist($this->serverroot, $theme_dir.$script.'.js') || $this->appendIfExist($this->serverroot, $script.'.js') + || $this->appendIfExist($this->serverroot, "dist/$app-$scriptName.js") || $this->cacheAndAppendCombineJsonIfExist($this->serverroot, $script.'.json') || $this->appendIfExist($this->serverroot, $theme_dir.'core/'.$script.'.js') || $this->appendIfExist($this->serverroot, 'core/'.$script.'.js') + || $this->appendIfExist($this->serverroot, "dist/core-$scriptName.js") || $this->cacheAndAppendCombineJsonIfExist($this->serverroot, 'core/'.$script.'.json') ) { return; } - $app = substr($script, 0, strpos($script, '/')); - $script = substr($script, strpos($script, '/') + 1); $app_path = \OC_App::getAppPath($app); $app_url = \OC_App::getAppWebPath($app); @@ -86,21 +89,21 @@ class JSResourceLocator extends ResourceLocator { } // missing translations files fill be ignored - if (strpos($script, 'l10n/') === 0) { - $this->appendIfExist($app_path, $script . '.js', $app_url); + if (strpos($scriptName, 'l10n/') === 0) { + $this->appendIfExist($app_path, $scriptName . '.js', $app_url); return; } if ($app_path === false && $app_url === false) { $this->logger->error('Could not find resource {resource} to load', [ - 'resource' => $app . '/' . $script . '.js', + 'resource' => $app . '/' . $scriptName . '.js', 'app' => 'jsresourceloader', ]); return; } - if (!$this->cacheAndAppendCombineJsonIfExist($app_path, $script.'.json', $app)) { - $this->append($app_path, $script . '.js', $app_url); + if (!$this->cacheAndAppendCombineJsonIfExist($app_path, $scriptName.'.json', $app)) { + $this->append($app_path, $scriptName . '.js', $app_url); } } diff --git a/lib/private/TemplateLayout.php b/lib/private/TemplateLayout.php index 317862ff386..f5109c678fd 100644 --- a/lib/private/TemplateLayout.php +++ b/lib/private/TemplateLayout.php @@ -96,7 +96,7 @@ class TemplateLayout extends \OC_Template { $this->initialState->provideInitialState('core', 'active-app', $this->navigationManager->getActiveEntry()); $this->initialState->provideInitialState('unified-search', 'limit-default', SearchQuery::LIMIT_DEFAULT); - Util::addScript('core', 'dist/unified-search', 'core'); + Util::addScript('core', 'unified-search', 'core'); // Add navigation entry $this->assign('application', ''); @@ -209,7 +209,7 @@ class TemplateLayout extends \OC_Template { } // Add the js files - $jsFiles = self::findJavascriptFiles(array_merge(\OC_Util::$scripts, Util::getScripts())); + $jsFiles = self::findJavascriptFiles(\OC_Util::$scripts); $this->assign('jsfiles', []); if ($this->config->getSystemValue('installed', false) && $renderAs != TemplateResponse::RENDER_AS_ERROR) { // this is on purpose outside of the if statement below so that the initial state is prefilled (done in the getConfig() call) diff --git a/lib/private/legacy/OC_Template.php b/lib/private/legacy/OC_Template.php index 9dfdb87e5ee..61fc82dacbb 100644 --- a/lib/private/legacy/OC_Template.php +++ b/lib/private/legacy/OC_Template.php @@ -106,7 +106,7 @@ class OC_Template extends \OC\Template\Base { //meaning the last script/style in this list will be loaded first if (\OC::$server->getSystemConfig()->getValue('installed', false) && $renderAs !== TemplateResponse::RENDER_AS_ERROR && !\OCP\Util::needUpgrade()) { if (\OC::$server->getConfig()->getAppValue('core', 'backgroundjobs_mode', 'ajax') == 'ajax') { - OC_Util::addScript('backgroundjobs', null, true); + OC_Util::addScript('core', 'backgroundjobs', true); } } OC_Util::addStyle('css-variables', null, true); @@ -114,11 +114,11 @@ class OC_Template extends \OC\Template\Base { OC_Util::addTranslations('core', null, true); if (\OC::$server->getSystemConfig()->getValue('installed', false) && !\OCP\Util::needUpgrade()) { - OC_Util::addScript('merged-template-prepend', null, true); - OC_Util::addScript('dist/files_client', null, true); - OC_Util::addScript('dist/files_fileinfo', null, true); + OC_Util::addScript('core', 'merged-template-prepend', true); + OC_Util::addScript('core', 'files_client', true); + OC_Util::addScript('core', 'files_fileinfo', true); } - OC_Util::addScript('core', 'dist/main', true); + OC_Util::addScript('core', 'main', true); self::$initTemplateEngineFirstRun = false; } 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: { diff --git a/webpack.modules.js b/webpack.modules.js index b8573fbf281..2d91b47df1e 100644 --- a/webpack.modules.js +++ b/webpack.modules.js @@ -52,6 +52,7 @@ module.exports = { sidebar: path.join(__dirname, 'apps/files/src', 'sidebar.js'), templates: path.join(__dirname, 'apps/files/src', 'templates.js'), 'files-app-settings': path.join(__dirname, 'apps/files/src', 'files-app-settings.js'), + 'legacy-filelist-search': path.join(__dirname, 'apps/files/src', 'legacy/filelistSearch.js'), 'personal-settings': path.join(__dirname, 'apps/files/src', 'main-personal-settings.js'), }, files_sharing: {