Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

link-media-ext-html-webpack-plugin

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

link-media-ext-html-webpack-plugin

Adds standard or custom media attributes to link tags processed by html-webpack-plugin

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
11
increased by450%
Maintainers
1
Weekly downloads
 
Created
Source

Build Status Coverage Status

This is an extension plugin for html-webpack-plugin. It sets standard and custom media attributes for link tags like link-media-html-webpack-plugin but uses configuration object similar to script-ext-html-webpack-plugin.

Installation

You must be running webpack (4.x) on node 6+.

Install plugin with npm:

$ npm install link-media-ext-html-webpack-plugin -D

Or yarn:

$ yarn add link-media-ext-html-webpack-plugin -D

Please note that you will need html-webpack-plugin v3.0.6+ and CSS extraction plugin e.g. mini-css-extract-plugin.

Basic usage:

Load the plugin:

const LinkMediaExtHtmlWebpackPlugin = require('link-media-ext-html-webpack-plugin');

Add the plugin to your webpack config as follows:

plugins: [
  new HtmlWebpackPlugin(),
  new MiniCssExtractPlugin({
    filename: '[name].css',
  }),
  new LinkMediaExtHtmlWebpackPlugin()
]

The order is important — the plugin must come after HtmlWebpackPlugin. The above configuration will actually do nothing.

Configuration

You must pass a configuration object to the plugin. You can define only those properties that you need.

new LinkMediaExtHtmlWebpackPlugin({
    defaultAttribute: 'screen',
    all: [],
    print: [],
    screen: [],
    speech: [],
    custom: [{
        test: '',
        value: ''
    }]
})

Options

  1. all / screen / speech / print — stylesheet matching pattern defining link tags that should have media attributes all / screen / speech / print appropriately.
  2. custom — array of objects with following structure:
  • test: stylesheet matching pattern defining link tags that should have media attribute with custom value added.
  • value:  a String value for the attribute; if not set the attribute has no value set (equivalent of true)

A stylesheet matching pattern matches against a stylesheets’s name. It can be one of:

  • String matches if it is a substring of the script name;
  • RegExp;
  • an array of String's and/or RegExp's — matches if any one element matches.

Examples:

Set all link tags media attributes to screen:

new LinkMediaExtHtmlWebpackPlugin({
  defaultAttribute: 'screen'
}) 

Set media attribute for main.css to screen and for print1.css, print2.css to print:

new LinkMediaExtHtmlWebpackPlugin({
  screen: 'main.css',
  print: [/print1.css/, 'print2.css']
})  

Set link tags media attributes screen except main.css which is all:

new LinkMediaExtHtmlWebpackPlugin({
  defaultAttribute: 'screen',
  all: [/main.css/],
})  

Change history:

v.1.0.x Initial release

FAQs

Package last updated on 18 Oct 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc