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

Add option to prepend ./ to rebased urls #107

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

derekstavis
Copy link

@derekstavis derekstavis commented Sep 3, 2017

This adds a relative option allowing to prepend ./ in front of the rebased URL.

This is needed to rebase paths after postcss-import and keep the imports relative to the root style.css.

This allows the following structure to work:

src/styles
├── index.css
└── webfonts
    ├── opensans
    │   ├── index.css
    │   └── open-sans-v14-latin-regular.woff2
    └── unineue
        ├── index.css
        └── UniNeueLight.woff2

src/styles/index.css

@import "./webfonts/opensans";
@import "./webfonts/unineue";

...

src/styles/webfonts/opensans/index.css

@font-face {
  font-family: "Open Sans";
  font-style: normal;
  font-weight: normal;
  src: url("./open-sans-v14-latin-regular.eot");

...

Using postcss with the following configuration:

webpack.config.js

...
      {
        test: /\.css$/,
        use: [
          require.resolve('style-loader'),
          {
            loader: require.resolve('css-loader'),
            options: {
              importLoaders: 1,
              modules: 1,
            },
          },
          {
            loader: require.resolve('postcss-loader'),
            options: {
              ident: 'postcss',
              plugins: () => [
                require('postcss-import'),
                require('postcss-url')({ relative: true }),
              ],
            },
          },
        ],
      },
...

@sergcen
Copy link
Collaborator

sergcen commented Nov 17, 2017

Hi @derekstavis
maybe you need to use custom function

require('postcss-url')([
  { url: 'rebase' }
  // postprocessing with 'custom' function
  { url: (asset) => `./${asset.url}`, multi: true }
])

I added flag multi especially for corner cases

Sorry, documentation is not clearly

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

2 participants