question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

resolve path relative to public folder

See original GitHub issue

I have mix copied semantic-sass assets from node_modules to public folder :

// /webpack.mix.js
mix.copy('node_modules/semantic-ui-sass/app/assets/images/', 'public/images/', false)
  .copy('node_modules/semantic-ui-sass/app/assets/fonts/', 'public/fonts/', false)
  .js('resources/assets/js/app.js', 'public/js')
   .sass('resources/assets/sass/app.scss', 'public/css')

This is how it looks like after copying: source :

/node_modules
 |+semantic-ui-sass
     |+app
        |+assets
            |+fonts
               |+semantic-ui
                  |-icons.eof
                  |-icons.otf
                     ......
           |+stylesheets
               |+semantic-ui
                  |+elements
                      |_icon.scss 
                 .......

dest:

/public
 |+css
     |-app.css
 |+fonts
     |-semantic-ui
     |-icons.eot
     |-icons.otf
     |-icons.svg
     |-icons.ttf
     |-icons.woff
     |-icons.woff2

Then imported icons inside /resource/assets/sass/app.scss

// resources/assets/sass/app.scss
@import 'node_modules/semantic-ui-sass/app/assets/stylesheets/semantic-ui/elements/icon';

After running npm run dev, this is the result produced : source:

  src: font-url("semantic-ui/icons.eot");
  src: font-url("semantic-ui/icons.eot?#iefix") format('embedded-opentype')
    ...

dest:

/* public/css/app.css */
@font-face {
  src: font-url("./../../../node_modules/semantic-ui-sass/app/assets/fonts/semantic-ui/icons.eot");
  font-url("./../../../node_modules/semantic-ui-sass/app/assets/fonts/semantic-ui/icons.eot") format("embedded-opentype");
  .....
}

But this is want i want :

/* public/css/app.css */
@font-face {
  src: font-url("fonts/semantic-ui/icons.eot");
  src: font-url("fonts/semantic-ui/icons.eot");
  .....
}

I was wondering is there some way to configure mix to resolve urls inside scss relative to production public folder instead of dependencies source folder without changing the source?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:8

github_iconTop GitHub Comments

47reactions
swt83commented, Feb 28, 2017

Aha!

Add this to your webpack.mix.js file:

.options({ processCssUrls: false })

As referenced here.

10reactions
M-Hoogiecommented, Sep 26, 2017

Here’s what I did for relative asset paths:

webpack.mix.js

mix.webpackConfig({
    resolve: {
        alias: {
            '@': path.resolve('src')
        }
    }
}).options({
    extractVueStyles: true
}).js('src/main.js', 'dist/').sass('src/assets/scss/app.scss', 'dist');

fonts.scss

@font-face {
  font-family: 'font';
  src: url('~@/assets/fonts/font-webfont.woff2') format('woff2'),
  url('~@/assets/fonts/font-webfont.woff') format('woff');
  font-weight: bold;
  font-style: normal;
}

App.vue

  ....
<style lang="scss">

    @import 'assets/scss/module/fonts';
....

Offcourse these aren’t node-modules but they are a use case that can be applied to this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

resolve path relative to public folder · Issue #364 · laravel-mix ...
I was wondering is there some way to configure mix to resolve urls inside scss relative to production public folder instead of dependencies ......
Read more >
Resolve-Path (Microsoft.PowerShell.Management)
The Resolve-Path cmdlet displays the items and containers that match the wildcard pattern at the location specified. The match can include files, folders, ......
Read more >
python - How to resolve a relative path, relative to any directory
I'm aware of how to resolve a relative path like '..\input\file\hello.txt' to an absolute path, relative to the current working directory:
Read more >
Relative fs.readFileSync paths with Node.js - Ultimate Courses
Relative paths will be resolved relative to the current working directory as determined by calling process.cwd() .
Read more >
Relative and absolute paths, in the file system and on the web ...
realpath() command will convert a relative path to an absolute one. getcwd() will give you the current directory.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found