Skip to content
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

fix(plugin-vue): user defined transformAssetUrls ignored in production build #7171

Merged
merged 1 commit into from
May 11, 2022

Conversation

Wiejeben
Copy link
Contributor

@Wiejeben Wiejeben commented Mar 4, 2022

Description

Whenever options.devServer is false it overrides assetUrlOptions, this makes it impossible to fully disable transformAssetUrls.

Additional context

In my setup I have been trying to make rollup not import any <img src="">, this I fixed by overwriting the supported tags
https://vue-loader.vuejs.org/options.html#transformasseturls

plugins: [
    vue({
        template: {
            transformAssetUrls: {
                // Do not transform any asset urls
                tags: {},
            },
        }
    }),
}

However this doesn't disable automatic srcset importing, for that I have to be able to fully set transformAssetUrls to false but I'm unable to because of the override on vite build. (see: https://github.com/vuejs/core/blob/main/packages/compiler-sfc/src/templateTransformSrcset.ts)

See https://github.com/vuejs/core/blob/main/packages/compiler-sfc/src/compileTemplate.ts#L67, it should be able to support booleans:

/**
 * Configure what tags/attributes to transform into asset url imports,
 * or disable the transform altogether with `false`.
 */
transformAssetUrls?: AssetURLOptions | AssetURLTagConfig | boolean

What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the Commit Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

Whenever `options.devServer` is `false` it overrides `assetUrlOptions`, this causes user defined `transformAssetUrls` to be ignored.
@Wiejeben Wiejeben changed the title fix(plugin-vue): transformAssetUrls ignored fix(plugin-vue): user defined transformAssetUrls ignored in production build Mar 4, 2022
@@ -123,7 +123,7 @@ export function resolveTemplateCompilerOptions(
slash(path.relative(options.root, path.dirname(filename)))
}
}
} else {
} else if (transformAssetUrls !== false) {
Copy link
Member

Choose a reason for hiding this comment

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

If transformAssetUrls is false, should we disabled it if options.devServer is true too? I think we can skip most of the code around here for that case.

Copy link
Member

Choose a reason for hiding this comment

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

Let's check this in another PR, the current branch refers to an optimization that may still be good to have for dev. I think we can merge this PR for the moment.

@patak-dev patak-dev merged commit bfab569 into vitejs:main May 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants