From 0b94c08a987f4eea97d0f125f587a5239d240bb4 Mon Sep 17 00:00:00 2001 From: Ro Savage Date: Tue, 4 Oct 2016 20:33:15 +1300 Subject: [PATCH 1/3] Updated readme for babel-node and ES6 import --- README.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/README.md b/README.md index 892814a..154923a 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,29 @@ require('css-modules-require-hook/preset'); // const styles = require('./icon.css'); ``` + +### Using with babel-node / ES6 Imports +You will need to create a `cmrh.conf.js` file within the directory as you are importing `css-modules-require-hook`. + + +```javascript +// server.js +import csshook from 'css-modules-require-hook/preset' // import hook before routes +import routes from '/shared/views/routes' + +// create server, etc +``` + +```javascript +// cmrh.conf.js +module.exports = { + // Same scope name as in webpack build + generateScopedName: '[name]__[local]___[hash:base64:5]', +} +``` + + + ### Development mode Usually, Node.js caches all the `require` calls by default. In order to invalidate cache for the purpose of development you should set the environment variable `NODE_ENV` to `development`. For example: From dfe72a2726d6cd9c42a3530db40a33d67ad7aa85 Mon Sep 17 00:00:00 2001 From: Alexey Litvinov Date: Sun, 5 Mar 2017 21:10:05 +0300 Subject: [PATCH 2/3] parser -> resolve-imports plugin --- .gitignore | 1 + lib/index.js | 9 +++++---- package.json | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 905f8e6..861a265 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,4 @@ node_modules/* # added automatically by precommit-hook as defaults .jshint* +yarn.lock diff --git a/lib/index.js b/lib/index.js index 42b0526..743eee6 100644 --- a/lib/index.js +++ b/lib/index.js @@ -17,7 +17,7 @@ const Values = require('postcss-modules-values'); const LocalByDefault = require('postcss-modules-local-by-default'); const ExtractImports = require('postcss-modules-extract-imports'); const Scope = require('postcss-modules-scope'); -const Parser = require('postcss-modules-parser'); +const ResolveImports = require('postcss-modules-resolve-imports'); const debugFetch = require('debug')('css-modules:fetch'); const debugSetup = require('debug')('css-modules:setup'); @@ -42,6 +42,7 @@ module.exports = function setupHook({ debugSetup(arguments[0]); validate(arguments[0]); + const exts = toArray(extensions); const tokensByFile = {}; // debug option is preferred NODE_ENV === 'development' @@ -71,8 +72,9 @@ module.exports = function setupHook({ ? new ExtractImports({createImportedName}) : ExtractImports, new Scope({generateScopedName: scopedName}), + new ResolveImports({resolve: {extensions: exts}}), ...append, - ]).concat(new Parser({fetch})); // no pushing in order to avoid the possible mutations; + ]); // https://github.com/postcss/postcss#options const runner = postcss(plugins); @@ -105,7 +107,7 @@ module.exports = function setupHook({ // https://github.com/postcss/postcss/blob/master/docs/api.md#lazywarnings lazyResult.warnings().forEach(message => console.warn(message.text)); - tokens = lazyResult.root.tokens; + tokens = lazyResult.root.exports || {}; if (camelCase) { tokens = assign(mapKeys(tokens, (value, key) => camelCaseFunc(key)), tokens); @@ -129,7 +131,6 @@ module.exports = function setupHook({ return tokens; }; - const exts = toArray(extensions); const isException = buildExceptionChecker(ignore); // @todo add possibility to specify particular config for each extension diff --git a/package.json b/package.json index f939277..6403729 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "css-modules-require-hook", - "version": "4.0.5", + "version": "4.1.0-beta", "description": "A require hook to compile CSS Modules on the fly", "main": "lib/index.js", "engines": { @@ -47,7 +47,7 @@ "postcss": "^5.0.19", "postcss-modules-extract-imports": "^1.0.0", "postcss-modules-local-by-default": "^1.0.1", - "postcss-modules-parser": "^1.1.0", + "postcss-modules-resolve-imports": "^1.0.0", "postcss-modules-scope": "^1.0.0", "postcss-modules-values": "^1.1.1", "seekout": "^1.0.1" From 6af6128679d7240387452611175ac1b70197e85b Mon Sep 17 00:00:00 2001 From: Alexey Litvinov Date: Sun, 5 Mar 2017 21:21:15 +0300 Subject: [PATCH 3/3] travis env update --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index ca8e5dd..90d7b0d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,5 @@ language: node_js node_js: - - "4.3" + - "4" + - "6" + - "7"