css-modules-require-hook
Advanced tools
Comparing version 1.0.5 to 1.0.6
/** | ||
* @param {function} compile | ||
* @param {string} extension | ||
*/ | ||
@@ -11,4 +12,4 @@ 'use strict'; | ||
function attachHook(compile) { | ||
require.extensions['.css'] = function hook(m, filename) { | ||
function attachHook(compile, extension) { | ||
require.extensions[extension] = function hook(m, filename) { | ||
var tokens = compile(filename); | ||
@@ -15,0 +16,0 @@ return m._compile('module.exports = ' + JSON.stringify(tokens), filename); |
@@ -67,2 +67,3 @@ 'use strict'; | ||
* @param {function} opts.generateScopedName | ||
* @param {function} opts.preprocessCss | ||
* @param {function} opts.processCss | ||
@@ -72,2 +73,3 @@ * @param {string} opts.rootDir | ||
* @param {array} opts.use | ||
* @param {array} opts.extensions | ||
*/ | ||
@@ -82,2 +84,3 @@ | ||
preProcess = (0, _utility.get)('preprocessCss', null, 'function', opts) || _lodashIdentity2['default']; | ||
postProcess = (0, _utility.get)('processCss', null, 'function', opts) || null; | ||
@@ -103,2 +106,11 @@ rootDir = (0, _utility.get)('rootDir', ['root', 'd'], 'string', opts) || process.cwd(); | ||
plugins.push(generateScopedName ? new _postcssModulesScope2['default']({ generateScopedName: opts.generateScopedName }) : _postcssModulesScope2['default']); | ||
var extraExtensions = (0, _utility.get)('extensions', null, 'array', opts); | ||
if (extraExtensions) { | ||
extraExtensions.forEach(function (extension) { | ||
(0, _hook2['default'])(function (filename) { | ||
return fetch(filename, filename); | ||
}, extension); | ||
}); | ||
} | ||
} | ||
@@ -146,3 +158,3 @@ | ||
return fetch(filename, filename); | ||
}); | ||
}, '.css'); | ||
module.exports = exports['default']; |
{ | ||
"name": "css-modules-require-hook", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "A require hook to compile CSS Modules on the fly", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -35,2 +35,3 @@ css-modules-require-hook | ||
* `function` **generateScopedName** — short alias for the [postcss-modules-scope](https://github.com/css-modules/postcss-modules-scope) plugin's option. Helps you to specify the custom way to build generic names for the class selectors. | ||
* `function` **preprocessCss** — in rare cases you may want to precompile styles, before they will be passed to the postcss pipeline. You should use **synchronous** transformations, since `require` function is synchronous. | ||
* `function` **processCss** — in rare cases you may want to get compiled styles in runtime, so providing this option helps. | ||
@@ -40,2 +41,3 @@ * `string` **rootDir** — absolute path to the project directory. Providing this will result in better generated class names. It can be obligatory, if you run require hook and build tools (like [css-modulesify](https://github.com/css-modules/css-modulesify)) from different working directories. | ||
* `array` **use** — custom subset of postcss plugins. | ||
* `array` **extensions** — attach the hook to additional file extensions (for example `['.scss']`). | ||
@@ -42,0 +44,0 @@ ### Examples |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
101925
637
98