Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Rollup plugin that transforms inline styling with PostCSS

NotificationsYou must be signed in to change notification settings

steveblue/rollup-plugin-inline-postcss

Repository files navigation

Rollup plugin that transforms inline styling with PostCSS

Install

npm i rollup-plugin-inline-postcss --save-devyarn add rollup-plugin-inline-postcss --dev

Usage

importresolvefrom'rollup-plugin-node-resolve';importinlinePostCSSfrom'rollup-plugin-inline-postcss';exportdefault{input:'src/main.js',plugins:[resolve(),inlinePostCSS()],};

Options

PropertyDescription
configPathPath to directory that contains postcss.config.js
envEnvironment variable, defaults toprocess.env.NODE_ENV where available
excludeFiles to exclude
failOnErrorAllows errors to propagate whentrue, otherwise warnings are thrown
fromInput file name (usually set by rollup)
includeFiles to include
pluginsArray of PostCSS plugins, defaults topostcss.config.js
styleDelimiterCustom delimiter for parsing styles in a file, default is /`/
styleRegexCustom regex for selecting CSS in file
toOutput file name (usually set by rollup)

Template Literals in JavaScript

This plugin by default looks for a template literal in JavaScript (or TypeScript) and will process CSS found inside of the string. This is particularly useful for Web Components or other CSS in JavaScript situations. The default pattern is below. The regex can be configured by passing the styleRegex property in the plugin options.

css`:host {display: block;background:rgba(24,24,24,1);width:200px;height:200px;color: white;padding:1em;border-radius:8px;  }`

The default regex for selecting template literals in a file is:

/(?:css`)((.|\n)+?)(?=(`(\n|;|,)))/gi;

The lookahead in the above RegExp statement allows for multiple matches of styles in the same file.

Customize the regex that is used to parse inline CSS with thestyleRegex andstyleDelimiter options.

For example, to parse inline<style> tags:

inlinePostCSS({styleRegex:/(?:<style>)((.|\n)+?)(?=(<\/style>))/gi,styleDelimiter:/<\/?style>/g,});

postcss.config.js

This plugin honorspostcss.config.js in the root directory and will look for environment variables based on the currentNODE_ENV. The example postcss.config.js below demonstrates minifying CSS with thepostcss-csso plugin only when the NODE_ENV is set toprod.

module.exports=(ctx)=>({plugins:{'postcss-csso':ctx.env==='prod' ?{} :false,},});

Development

npm run build compiles the plugin.

npm run test runs the tests.

npm run version versions the package, run withSEMVER environment variable et to eitherpatch,minor, ormajor.

About

Rollup plugin that transforms inline styling with PostCSS

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors2

  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp