Giter VIP home page Giter VIP logo

styled-jsx-url-loader's Introduction

styled-jsx-url-loader

Build Status npm version

Webpack loader to transform url() to es6 imports inside the css or sass when using separate files to create styled-jsx styles.
This loader needs to be used together with styled-jsx/webpack loader.
It's similar to what css-loader does, but css-loader is incompatible with styled-jsx/webpack loader.

Installation

Using yarn:

yarn add styled-jsx-url-loader --dev

Or using npm:

npm install styled-jsx-url-loader --dev

Configuration

This loader should be executed right after styled-jsx/webpack and before babel loader.
Since loaders are executed from last to first, usage can be like this (with next.js):

config.module.rules.push({
  test: /\.s?css$/,
  use: [
    options.defaultLoaders.babel,
    {
      loader: require.resolve('styled-jsx-url-loader'),
      options: {},
    },
    {
      loader: require('styled-jsx/webpack').loader,
      options: {
        type: 'scoped',
      },
    },
  ],
})

Options

scss

Type: Boolean
Default: false

Allow parsing scss code.
(It will not transform scss to css, only allow parser to parse it)

exclude

Type: String|RegExp
Default: null

Exclude urls from transformations.

debug

Type: Boolean
Default: false

Print debug messages.

Caveats

Sass variables inside the urls are not supported. For example: background: url($heroImage).
If you need to transform urls with variables, transform your sass code first to plain css.

There is no source maps support. (PR welcome)

License

MIT © Daniel Husar

styled-jsx-url-loader's People

Contributors

danielhusar avatar

Stargazers

Roman avatar Steven Petryk avatar

Watchers

James Cloos avatar  avatar

styled-jsx-url-loader's Issues

Failed to load image on resolve type

Hi, I'm meeting an issue. When setting type as resolve from external stylesheet file, the image will not solved and leave it as is in style config.
Demo code as below:
test.scss

/* @styled-jsx=resolve */
div {
  background: url(./someimage.png);
}

test.jsx

import style from './test.scss';
export default function Comp() {
  return (
    <>
      {style.styles}
      <div className={style.className} />
    </>
  );
}

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.