Skip to content

url is resolved in a wrong way #3111

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

Closed
Huai-Kang opened this issue Sep 29, 2017 · 3 comments
Closed

url is resolved in a wrong way #3111

Huai-Kang opened this issue Sep 29, 2017 · 3 comments

Comments

@Huai-Kang
Copy link

Huai-Kang commented Sep 29, 2017

I was using vue-cli to build a project, and use less to write styles;
when I try to import a .less file into .vue to use a utils function, it was return a bad result;
below is my utils.less:

.background(@url) {
  background-image: url('@{url}@2x.png');
  @media (-webkit-min-device-pixel-ratio: 3), (min-device-pixel-ratio: 3) {
    background-image: url('@{url}@3x.png');
  }
}

and this is styles in my header.vue, it was import utils.less:

<style lang="less">
  @import '../../common/css/utils';
  .brand {
     width: 64px;
     height: 64px;
     margin-right: 16px;
     border-radius: 4px;
     vertical-align: bottom;
     .background('./brand');
   }
</style>

webpack:

[ 
  'vue-style-loader',
  {
    loader: 'css-loader',
    options: { minimize: false, sourceMap: false }
  },
  {
    loader: 'less-loader',
    options: { sourceMap: false }
  }
]

I think the url will be just simply merge, like './[email protected]' and './[email protected];
but in fact, I got '../../common/css/[email protected]' and '../../common/css/[email protected]';
it looks like merge the url of import file;
I don't know how to deal with the problem, can somebody help me?

below is the error message:

ERROR  Failed to compile with 2 errors                                                                                                          4:18:06 PM

These relative modules were not found:

* ../../common/css/brand@2x.png in ./~/css-loader?{"minimize":false,"sourceMap":false}!./~/vueloader/lib/style-compiler?{"vue":true,"id":"data-v-bc573e70","scoped":false,"hasInlineConfig":false}!./~/less-loader/dist/cjs.js?{"sourceMap":false}!./~/vue-loader/lib/selector.js?type=styles&index=0!./src/components/Header/Header.vue
* ../../common/css/brand@3x.png in ./~/css-loader?{"minimize":false,"sourceMap":false}!./~/vue-loader/lib/style-compiler?{"vue":true,"id":"data-v-bc573e70","scoped":false,"hasInlineConfig":false}!./~/less-loader/dist/cjs.js?{"sourceMap":false}!./~/vue-loader/lib/selector.js?type=styles&index=0!./src/components/Header/Header.vue
@rjgotten
Copy link
Contributor

rjgotten commented Oct 4, 2017

Path resolution occurs at the place where the url() function is used. If that is inside a mixin declared in another imported .less sheet, then the path will be made relative to that imported sheet and not relative to where said mixin is called.

This relates also to earlier discussion in #2629 as the data-uri() function has the same behavior.
No final solution to this problem was designed yet, though I did take a shot at it back then.

@Huai-Kang
Copy link
Author

@rjgotten I had resolved this problem with #2598

@matthew-dean
Copy link
Member

@Feel-Joy Is this closable then?

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

No branches or pull requests

3 participants