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

Lightweight CSS extraction plugin

License

NotificationsYou must be signed in to change notification settings

DevSide/mini-css-extract-plugin

 
 

Repository files navigation

npmdepstestcoveragechat

mini-css-extract-plugin

desc

This plugin extract CSS into separate files. It creates a CSS file per JS file which contains CSS. It supports On-Demand-Loading of CSS and SourceMaps.

It builds on top of a new webpack v4 feature (module types) and requires webpack 4 to work.

Compared to the extract-text-webpack-plugin:

  • Async loading
  • No duplicate compilation (performance)
  • Easier to use
  • Specific to CSS

TODO:

  • HMR support

Install

npm install --save-dev mini-css-extract-plugin

Usage

Configuration

webpack.config.js

constMiniCssExtractPlugin=require("mini-css-extract-plugin");module.exports={plugins:[newMiniCssExtractPlugin({// Options similar to the same options in webpackOptions.output// both options are optionalfilename:"[name].css",chunkFilename:"[id].css"})],module:{rules:[{test:/\.css$/,use:[MiniCssExtractPlugin.loader,"css-loader"]}]}}

Features

Using preloaded or inlined CSS

The runtime code detects already added CSS via<link> or<style> tag.This can be useful when injecting CSS on server-side for Server-Side-Rendering.Thehref of the<link> tag has to match the URL that will be used for loading the CSS chunk.Thedata-href attribute can be used for<link> and<style> too.When inlining CSSdata-href must be used.

Extracting all CSS in a single file

Similar to whatextract-text-webpack-plugin does, the CSScan be extracted in one CSS file usingoptimization.splitChunks.cacheGroups.

webpack.config.js

constMiniCssExtractPlugin=require("mini-css-extract-plugin");module.exports={optimization:{splitChunks:{cacheGroups:{styles:{name:'styles',test:/\.css$/,chunks:'all',enforce:true}}}},plugins:[newMiniCssExtractPlugin({filename:"[name].css",})],module:{rules:[{test:/\.css$/,use:[MiniCssExtractPlugin.loader,"css-loader"]}]}}

Maintainers


Tobias Koppers

Long Term Caching

For long term caching usefilename: "[contenthash].css". Optionally add[name].

About

Lightweight CSS extraction plugin

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript86.6%
  • CSS8.0%
  • HTML5.4%

[8]ページ先頭

©2009-2025 Movatter.jp