Code Monkey home page Code Monkey logo

Comments (10)

taniarascia avatar taniarascia commented on May 10, 2024

I can take a look.

from webpack-boilerplate.

taniarascia avatar taniarascia commented on May 10, 2024

@nelsonvassalo Can you please explain what you're trying to do? I just tested background-image URLs in scss files in folders, and it worked just fine on dev and build.

Generally, with SCSS you'll have index.scss that imports everything else.

// index.scss
@import 'config/variables';
@import 'components/example';

Then from the folder, you'll refer to the URL based on the index directory.

// components/_example.scss
.card {
  background: url('../images/favicon.png');
}

You can test this right now and build or start and it'll work just fine. Please let me know or I'm closing this issue.

from webpack-boilerplate.

nelsonvassalo avatar nelsonvassalo commented on May 10, 2024

Hi,

It works fine yes, but the output urls are not relative to css file but to the root (starting with '/'), which means if I host the sites elsewhere but the root they start failing. Was that clear?

from webpack-boilerplate.

taniarascia avatar taniarascia commented on May 10, 2024

@nelsonvassalo You mean if you host your website on https://www.example.com/subdirectory vs https://www.example.com/?

from webpack-boilerplate.

nelsonvassalo avatar nelsonvassalo commented on May 10, 2024

from webpack-boilerplate.

taniarascia avatar taniarascia commented on May 10, 2024

@nelsonvassalo Where are you putting your Webpack config relative to the directory? You should be able to put publicPath:

  output: {
    path: paths.build,
    publicPath: './subdirectory/'
    filename: '[name].[contenthash].bundle.js',
  },

from webpack-boilerplate.

taniarascia avatar taniarascia commented on May 10, 2024

I made an update, let me know if it fixes your issue. (You'll just need to update publicPath from / to /yourdirectory.

from webpack-boilerplate.

nelsonvassalo avatar nelsonvassalo commented on May 10, 2024

Thanks!

It would still make them relative to root I think. To manage it's dependency free from root I've noticed you can pass a new publicPath option to MiniCSSExtract.loader. Right now you0ve hardcoded ../../. It seems this can be made actually relative by passing in the following function as value:

options: {
  publicPath: (resourcePath, context) => {
      // publicPath is the relative path of the resource to the context
      // e.g. for ./css/admin/main.css the publicPath will be ../../
      // while for ./css/main.css the publicPath will be ../
        return path.relative(path.dirname(resourcePath), context) + '/';
      }
  }
…
}

from webpack-boilerplate.

taniarascia avatar taniarascia commented on May 10, 2024

Did you try it with the latest update? publicPath was removed from MiniCSSExtract.loader and moved to output in webpack.prod.js. You should be able to put /yourdirectory in publicPath of ouput. I don't 100% understand your setup and where you have your files located so I can't test it myself.

from webpack-boilerplate.

taniarascia avatar taniarascia commented on May 10, 2024

I'm going to close this issue, feel free to re-open if the issue persists.

from webpack-boilerplate.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.