Package Exports
- @neutrinojs/style-loader
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@neutrinojs/style-loader) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Neutrino Style Loader Middleware
@neutrinojs/style-loader is Neutrino middleware for loading and importing stylesheets from modules.
Features
- Zero upfront configuration necessary to import stylesheets into modules
- Automatic stylesheet extraction; importing stylesheets into modules creates bundled external stylesheets
- Pre-configured to support CSS Modules via
*.module.cssfile extensions - CSS Hot Module Replacement support
- Very extensible to customize as needed
Requirements
- Node.js v6.10+
- Yarn or npm client
- Neutrino v7
Installation
@neutrinojs/style-loader can be installed via the Yarn or npm clients.
Yarn
❯ yarn add @neutrinojs/style-loadernpm
❯ npm install --save @neutrinojs/style-loaderUsage
@neutrinojs/style-loader can be consumed from the Neutrino API, middleware, or presets. Require this package
and plug it into Neutrino:
// Using function middleware format
const styles = require('@neutrinojs/style-loader');
// Use with default options
neutrino.use(styles);
// Usage showing default options
neutrino.use(styles, {
style: {},
css: {},
test: /\.css$/,
ruleId: 'style',
styleUseId: 'style',
cssUseId: 'css',
hotUseId: 'hot',
hot: true,
modules: true,
modulesSuffix: '-modules',
modulesTest: /\.module.css$/,
extractId: 'extract',
extract: {
plugin: {},
loader: {}
}
});// Using object or array middleware format
// Use with default options
module.exports = {
use: ['@neutrinojs/style-loader']
};
// Usage showing default options
module.exports = {
use: [
['@neutrinojs/style-loader', {
style: {},
css: {},
test: /\.css$/,
ruleId: 'style',
styleUseId: 'style',
cssUseId: 'css',
hotUseId: 'hot',
hot: true,
modules: true,
modulesSuffix: '-modules',
modulesTest: /\.module.css$/,
extractId: 'extract',
extract: {
plugin: {},
loader: {}
}
}]
]
};style: Set options for the style-loader used when loading CSS files.css: Set options for the css-loader used when loading CSS files.test: File extensions which support stylesheetsruleId: The ID of the webpack-chain rule used to identify the stylesheet loadersstyleUseId: The ID of the webpack-chainuseused to identify the style-loadercssUseId: The ID of the webpack-chainuseused to identify the css-loaderhotUseId: The ID of the webpack-chainuseused to identify the css-hot-loaderhot: Enable usage of CSS Hot Module Replacement. Set tofalseto disable.modules: Enable usage of CSS modules via*.module.cssfiles. Set tofalseto disable and skip defining these rules.modulesSuffix: A suffix added toruleId,styleUseId,cssUseId,hotUseId, andextractIdto derive names for modules-related rules. For example, the default-modulessuffix will generate a rule ID for the CSS modules rules ofstyle-modules, while the normal rule remains asstyle.modulesTest: File extensions which support CSS Modules stylesheetsextractId: The ID of the webpack-chain plugin used to identify theExtractTextPluginextract: Options relating to theExtractTextPlugininstance. Overrideextract.pluginto override plugin options. Overrideextract.loaderto override the loader options. Set tofalseto disable stylesheet extraction.
Customization
@neutrinojs/style-loader creates some conventions to make overriding the configuration easier once you are
ready to make changes.
Rules
The following is a list of default rules and their identifiers which can be overridden:
| Name | Description | Environments and Commands |
|---|---|---|
style |
Allows importing CSS stylesheets from modules. Contains two loaders named style and css which use style-loader and css-loader, respectively. |
all |
style-modules |
Allows importing CSS Modules styles from modules. Contains two loaders named style-modules and css-modules which use style-loader and css-loader, respectively. |
all |
Plugins
The following is a default list of plugins and their identifiers which can be overridden:
Note: Some plugins may be only available in certain environments. To override them, they should be modified conditionally.
| Name | Description | Environments and Commands |
|---|---|---|
extract |
Extracts CSS from JS bundle into a separate stylesheet file. | all |
extract-modules |
Extracts CSS from JS bundle into a separate stylesheet file. | all |
Contributing
This middleware is part of the neutrino-dev repository, a monorepo containing all resources for developing Neutrino and its core presets and middleware. Follow the contributing guide for details.