npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

newer-universal-style-loader

v0.16.2

Published

style loader for webpack with SSR support

Downloads

6

Readme

npm node

Adds CSS to the DOM by injecting a <style> tag

Install

npm install newer-universal-style-loader --save-dev

Usage

Documentation: Using loaders

Webpack Configuration

newer-universal-style-loader is a drop-in replacement for the usual style-loader.

It's recommended to combine it with the css-loader.

Example for Webpack 5 with CSS module support:

  module: {
    rules: [ {
      test: /\.css$/,
      use: [ {
        loader: "newer-universal-style-loader",
        options: { singleton: true }
      }, {
        loader: "css-loader",
        options: {
          modules: { localIdentName: "[name]--[local]--[hash:base64:8]" },
          sourceMap: true,
          importLoaders: 1
        }
      } ]
    } ]
  },

Then, in your JS code:

import css from './file.css';

This will add rules in file.css to the document.

Server environment

On server side we can't load styles into the DOM but to collect them and use when assembling the layout.

Use getStyles() to get captured styles in the form of a <style> element ready to be added into <head>.

Use this piece of code somewhere in your server-side bundle:

import universal from 'newer-universal-style-loader/universal';

const html = universal.getStyles();

Options

insertAt

By default, the loader appends <style> elements to the end of the style target, which is the <head> tag of the page unless specified by insertInto. This will cause CSS created by the loader to take priority over CSS already present in the target. To insert style elements at the beginning of the target, set this query parameter to top.

insertInto

By default, the loader inserts the <style> elements into the <head> tag of the page. If you want the tags to be inserted somewhere else, e.g. into a ShadowRoot, you can specify a CSS selector for that element here, e.g. options: { insertInto: "#host::shadow>#root" }.

singleton

If defined, the loader will re-use a single <style> element, instead of adding/removing individual elements for each required module. This option is ON by default. To disable it, set options: { singleton: false }.

convertToAbsoluteUrls

If convertToAbsoluteUrls and sourceMaps are both enabled, relative urls will be converted to absolute urls right before the css is injected into the page. This resolves an issue where relative resources fail to load when source maps are enabled.

attrs

If defined, style-loader will attach given attributes with their values on each <style> / <link> element.

Note about source maps support and assets referenced with url: when style loader is used with ?sourceMap option, the CSS modules will be generated as Blobs, so relative paths don't work (they would be relative to chrome:blob or chrome:devtools). In order for assets to maintain correct paths setting output.publicPath property of webpack configuration must be set, so that absolute paths are generated. Alternatively you can enable the convertToAbsoluteUrls option mentioned above.

Contributing

Don't hesitate to create a pull request. Every contribution is appreciated. In development you can start the tests by calling npm test.

Maintainer

Vitaliy Filippov https://github.com/vitalif

Also contains code authored by:

  • Terence Chow https://github.com/terencechow
  • Istvan Jano https://github.com/janoist1
  • Tobias Koppers https://github.com/sokra
  • Kees Kluskens https://github.com/SpaceK33z

LICENSE

MIT