Skip to content

feat(appconfig): Add base path so module preloading works #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 12, 2023

Conversation

susnux
Copy link
Contributor

@susnux susnux commented Oct 12, 2023

For apps the config will generate a vite app config, so vite will try to preload all modules imported directly by the entry point.
To do so we have to configure the base path where to import the modules from (this is different from normal import, as module preloading works by adding the modules with their source URL to the document, meaning for normal imports the base url is not required (browsers support the relative imports), but for module preloading it is).

We can not set one base url, as we do not know it (we do not know the webroot of an app on build time).
So we need to use the runtime feature (currently hidden behind a the experimental flag).

@susnux susnux added type: enhancement 🚀 New feature or request 3. to review 3️⃣ Waiting for reviews labels Oct 12, 2023
@susnux susnux requested a review from ShGKme October 12, 2023 00:09
@codecov
Copy link

codecov bot commented Oct 12, 2023

Codecov Report

Merging #43 (3057128) into main (7af5c2a) will decrease coverage by 0.56%.
The diff coverage is 54.54%.

@@            Coverage Diff             @@
##             main      #43      +/-   ##
==========================================
- Coverage   80.26%   79.70%   -0.56%     
==========================================
  Files           8        8              
  Lines         537      547      +10     
  Branches       32       32              
==========================================
+ Hits          431      436       +5     
- Misses         74       79       +5     
  Partials       32       32              
Files Coverage Δ
lib/appConfig.ts 78.94% <54.54%> (-2.04%) ⬇️

Copy link
Contributor

@ShGKme ShGKme left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, replacement for __webpack_public_path__.

So we need to use the runtime feature (currently hidden behind a the experimental flag).

I guess it is safe as this experimental feature is already in use by many things, including Nuxt.

@susnux susnux merged commit 9db641a into main Oct 12, 2023
@susnux susnux deleted the feat/add-base-url-for-module-preloading branch October 12, 2023 15:44
@susnux susnux mentioned this pull request Oct 20, 2023
@raimund-schluessler
Copy link
Contributor

I get this error now with the migration to vite in nextcloud/tasks#2321

rendering chunks (5)...[vite:css-post] { runtime: "OC.filePath('tasks', '', 'img/tasks-dark.svg')" } is not supported for assets in css files: img/tasks-dark.svg
✓ built in 18.82s
error during build:
Error: { runtime: "OC.filePath('tasks', '', 'img/tasks-dark.svg')" } is not supported for assets in css files: img/tasks-dark.svg
    at toOutputFilePathWithoutRuntime (file:///home/raimund/nextcloud/apps2/tasks/node_modules/vite/dist/node/chunks/dep-68d1a114.js:48446:23)
    at file:///home/raimund/nextcloud/apps2/tasks/node_modules/vite/dist/node/chunks/dep-68d1a114.js:38522:28
    at String.replace (<anonymous>)
    at resolveAssetUrlsInCss (file:///home/raimund/nextcloud/apps2/tasks/node_modules/vite/dist/node/chunks/dep-68d1a114.js:38519:37)
    at Object.renderChunk (file:///home/raimund/nextcloud/apps2/tasks/node_modules/vite/dist/node/chunks/dep-68d1a114.js:38548:32)
    at file:///home/raimund/nextcloud/apps2/tasks/node_modules/rollup/dist/es/shared/node-entry.js:25544:40
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

@raimund-schluessler
Copy link
Contributor

I get this error now with the migration to vite in nextcloud/tasks#2321

rendering chunks (5)...[vite:css-post] { runtime: "OC.filePath('tasks', '', 'img/tasks-dark.svg')" } is not supported for assets in css files: img/tasks-dark.svg
✓ built in 18.82s
error during build:
Error: { runtime: "OC.filePath('tasks', '', 'img/tasks-dark.svg')" } is not supported for assets in css files: img/tasks-dark.svg
    at toOutputFilePathWithoutRuntime (file:///home/raimund/nextcloud/apps2/tasks/node_modules/vite/dist/node/chunks/dep-68d1a114.js:48446:23)
    at file:///home/raimund/nextcloud/apps2/tasks/node_modules/vite/dist/node/chunks/dep-68d1a114.js:38522:28
    at String.replace (<anonymous>)
    at resolveAssetUrlsInCss (file:///home/raimund/nextcloud/apps2/tasks/node_modules/vite/dist/node/chunks/dep-68d1a114.js:38519:37)
    at Object.renderChunk (file:///home/raimund/nextcloud/apps2/tasks/node_modules/vite/dist/node/chunks/dep-68d1a114.js:38548:32)
    at file:///home/raimund/nextcloud/apps2/tasks/node_modules/rollup/dist/es/shared/node-entry.js:25544:40
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

The reason was a a file in the style section of a vue file like so background-image: url('../../../img/color_picker.svg');. I worked around it by using a vue component as the background image. It's not the solution for the underlying problem, but it works for me. See https://github.com/nextcloud/tasks/pull/2321/files#diff-df9e78dfbc2f67a9738794e3f781ed6a3bf7097a307ebbf24cb4a67c308db48fL197

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3. to review 3️⃣ Waiting for reviews type: enhancement 🚀 New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants