Git Product home page Git Product logo

prepend-style-loader's Introduction

prepend-style-loader

Build Status

Style import prepender for webpack, prepends defined style files on build(scss, stylus, css).

This will prepend the defined files to every file that is matched by the loader. Perfect to remove tedious variables and mixins imports while using design patters like css-modules or other techniques that isolates style scopes.

The example below will import variable.styl and mixnin.styl and prepend import statements for each file. This allows .styl files to use "global" variables and mixins, which are not defined within the same file.

Install

npm install prepend-style-loader

Usage

Example config

here

Config

Multiple files:

{
  loader: 'prepend-style-loader',
  options: {
    prepend: [
      path.resolve('src/resources/global/variables'),
      path.resolve('src/resources/global/mixins')
    ]
  }
}

Single file:

{
  loader: 'prepend-style-loader',
  options: {
    prepend: path.resolve('src/resources/global/mixins')
  }
}

Styl example

{
  rules: {
    loaders: [
      {
        test: /\.styl$/,
        use: [
          {
            loader: 'style-loader'
          },
          {
            loader: 'css-loader',
            options: {
              modules: true,
              camelCase: true,
              localIdentName: '[name]__[local]___[hash:base64:5]'
            }
          },
          {
            loader: 'stylus-loader'
          },
          {
            loader: 'prepend-style-loader',
            options: {
              prepend: [
                path.resolve('src/resources/global/variables'),
                path.resolve('src/resources/global/mixins')
              ]
            }
          }
        ]
      }
    ]
  }
}

Demo

Run demo

git clone [email protected]:JoelRoxell/prepend-style-loader.git

npm link prepend-style-loader

yarn demo

open demo/build/index.html

prepend-style-loader's People

Contributors

narthur157 avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

prepend-style-loader's Issues

Prepend should accept non array prepend

Prepend fails somewhat mysteriously if prepend is supplied with a single value instead of an array. Supporting this or giving a useful error message would be nice

Provide a more efficient way of specifying files via query.

When I specify which files which should be included, I want to specify them via the query property as a Array of strings, so I can get a more manageable loader configuration.

query: {
  prepend: [
    './src/styles/global/variables',
    './src/styles/global/mixins',
    ...
  ]
}

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.