Git Product home page Git Product logo

css-visor's Introduction

css-visor

The ultimate style-loader replacement you knew you needed

css-visor is like a supervisor that finds, injects and updates your imported stylesheets - with sourcemaps and no Flash of Unstyled Content

Background

css-visor was created out of long living pain as seen in:

Usage

Install it

npm install --save-dev css-visor

Light it up

// webpack.config.js

const CSSVisor = require('css-visor')
const HtmlWebpackPlugin = require('html-webpack-plugin')

module.exports = {
    // existing config
    module: {
        rules: [{
            test: /\.css$/,
            use: [
                {
                    loader: 'css-visor/loader',
                    // Optional
                    options: {
                        /**
                         * Path prefix you'd like to be prefixed in <link> tag
                         * 
                         * Default: ''
                         *  => <link href="styles/button.da3n1b.css">
                         * 
                         * Custom: 'static/base'
                         *  => <link href="static/base/styles/button.da3n1b.css">
                         */
                        pathPrefix: 'static/styles' // default: ''
                    }
                },
                {
                    loader: 'css-loader',
                    options: {
                        sourceMap: true,
                    }
                },
                // more loaders (sass, postcss)
            ]
        }]
    },
    plugins: [
        new CSSVisor(),
        new HtmlWebpackPlugin({
            inject: true
        })
    ]
}

It should now be working out of the box.

Not working? Make sure to have css-visor/loader right before css-loader and instance of CSSVisor in plugins list of your webpack config.

Still not working? Please file an issue to have it known

This release is only compatible with webpack 4 and up. To use with an older version of webpack use npm i [email protected], although 1.0 is no longer maintained

Reliability

css-visor is literally built from source of extract-loader. So far, it has shown no problems, even with imported stylsheets, images/svg's (processed through url-loader/file-loader).

The only things you can import in a CSS file anyway.

External Licenses

Much of the code taken from extract-loader which is Unlicensed, see extract-loader/LICENSEfor more information.

css-visor's People

Contributors

zikaari avatar

Stargazers

Damian Adams avatar Andrejs Agejevs avatar Ade Viankakrisna Fadlil avatar John Rodler avatar James Treworgy avatar  avatar Lucas Aragno avatar Ceane avatar

Watchers

Alyx avatar  avatar

Forkers

jamietre

css-visor's Issues

Link emitted without hash substitution

I'm just trying this for the first time and our build is pretty complicated so I might be doing something wrong. But only one out of >100 link tags injected by the plugin is wrong:

  <link href="/app/common/ui/Flex/Column.scs.[hash:6].css" rel="stylesheet">

Everything else has a hash.

Webpack 4 support

Using the plugin with the latest Webpack results in the following error:

node_modules/css-visor/plugin.js:40
                    if (chunk.isInitial()) {
                              ^
TypeError: chunk.isInitial is not a function
    at compilation.chunks.forEach.chunk

Can it be used with scss files?

I am using scss files in my project as this is hoe my webpack.config.js looks like this:

{
	test: /\.scss$/,
		resolve: {
			extensions: ['.css', '.scss']
		},
		use: [
			IS_DEV
            	? {
				loader: 'css-visor/loader',
				}
           		 : MiniCssExtractPlugin.loader,
				{
					loader: 'css-loader',
					options: {
						sourceMap: IS_DEV
					}
				},
				{
					loader: 'postcss-loader',
					options: {
						sourceMap: IS_DEV
					}
				},
                {
                	loader: 'sass-loader',
                    options: {
                    data: '@import \'styles/abstracts/index\';',
                    sourceMap: IS_DEV
                }
		}
	]
}

This is a block added in module.
Let me know if there is anything to add in this.
I am getting this error right now

ERROR in ./app/automate/Details/styles/ProjectTag.scss
Module build failed (from ./node_modules/css-visor/loader.js):
NonErrorEmittedError: (Emitted value instead of an instance of Error) TypeError: require(...) is not a function
    at runLoaders (/Users/sunil/bsstag/railsApp/react_new/node_modules/webpack/lib/NormalModule.js:283:13)
    at /Users/sunil/bsstag/railsApp/react_new/node_modules/loader-runner/lib/LoaderRunner.js:364:11
    at /Users/sunil/bsstag/railsApp/react_new/node_modules/loader-runner/lib/LoaderRunner.js:230:18
    at runSyncOrAsync (/Users/sunil/bsstag/railsApp/react_new/node_modules/loader-runner/lib/LoaderRunner.js:143:3)
    at iterateNormalLoaders (/Users/sunil/bsstag/railsApp/react_new/node_modules/loader-runner/lib/LoaderRunner.js:229:2)
    at iterateNormalLoaders (/Users/sunil/bsstag/railsApp/react_new/node_modules/loader-runner/lib/LoaderRunner.js:218:10)
    at /Users/sunil/bsstag/railsApp/react_new/node_modules/loader-runner/lib/LoaderRunner.js:233:3
    at context.callback (/Users/sunil/bsstag/railsApp/react_new/node_modules/loader-runner/lib/LoaderRunner.js:111:13)
    at process.then.result (/Users/sunil/bsstag/railsApp/react_new/node_modules/css-loader/dist/index.js:261:12)

For all scss files

IE11 support

Thanks for the nice fix!

It fails in IE11 due to the use of template literals inside the HTML inline script.

Not work with webpack 3?

During build, following error appeared "Cannot read property 'thisCompilation' of undefined".
It seems no "compiler.hooks" for webpack 3.

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.