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

double /nuxtfiles/ in replace-relative-paths #3

Open
maxBenelli opened this issue Jul 12, 2021 · 4 comments
Open

double /nuxtfiles/ in replace-relative-paths #3

maxBenelli opened this issue Jul 12, 2021 · 4 comments

Comments

@maxBenelli
Copy link

maxBenelli commented Jul 12, 2021

when I using in scss ->

nuxt.config.js

css : [
    '~/assets/scss/style.scss'
],
styleResources : {
    scss : [
        '~/assets/scss/fonts.scss'
    ]
},
....

style.scss

.block {
    background-image : url('~assets/img/test.jpeg');
}

or fonts.scss

@font-face {
  font-family  : 'Gilroy';
  src          : url('~assets/fonts/Gilroy-Medium.eot');
  ...
  font-style   : normal;
  font-display : swap;
}

it transforms into ->

http://localhost:8000/nuxtfiles/nuxtfiles/img/a80ec01.jpeg

http://localhost:8000/nuxtfiles/nuxtfiles/fonts/7d5dc17.woff
http://localhost:8000/nuxtfiles/nuxtfiles/img/e0dd053.svg#Gilroy-Medium

/nuxtfiles/nuxtfiles/ - double replace

How I can fix it ?

@maxBenelli maxBenelli changed the title replace-relative-paths error double /nuxtfiles/ in replace-relative-paths Jul 12, 2021
@maxBenelli
Copy link
Author

maxBenelli commented Jul 13, 2021

Found the solution!

If you are using this dependencies for working with the scss

package.json

{
    "node-sass": "^4.14.1",
    "sass-loader": "10.1.1",
}

nuxt.config.js

/*
 ** Nuxt.js modules
 */
modules: [
    '@nuxtjs/style-resources',
    ...
],

and you are using structure like this

assets
  - scss
  - img
  - fonts
  ...
  etc.

you need to add the new replace after replace '/assets/' 'nuxtfiles/' dist --recursive into "replace-relative-paths" script inside package.json

replace 'nuxtfiles/(img|fonts)' '../nuxtfiles/$1'

finished script will like this

"replace-relative-paths": "replace '/nuxtfiles/' 'nuxtfiles/' dist --recursive && replace '/assets/' 'nuxtfiles/' dist --recursive && replace 'nuxtfiles/(img|fonts)' '../nuxtfiles/$1' && replace '(href|src|\"href\"|\"src\")=\"/' '$1=\"../' dist --recursive && replace '(href|src|\"href\"|\"src\"):\"/' '$1:\"../' dist --recursive",

@maxBenelli
Copy link
Author

Please, add me to contributors, I will add some fixes as soon as possible. Thanks

@simllll
Copy link
Contributor

simllll commented Jul 13, 2021

Please, add me to contributors, I will add some fixes as soon as possible. Thanks

Please create PRs :) thanks for your contribution

@maxBenelli
Copy link
Author

Please, add me to contributors, I will add some fixes as soon as possible. Thanks

Please create PRs :) thanks for your contribution

Done! Hopefully, it will helps to someone

#4

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

2 participants