From f8c3dfe782373a4d57c1f7f75a60e1ee644a24d6 Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Tue, 17 Nov 2020 17:05:19 +0100 Subject: [PATCH] Allow configuring autoExportImports --- README.md | 2 +- notes.md | 3 +++ src/postcss/postprocess.js | 1 + src/transform.js | 2 +- 4 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 notes.md diff --git a/README.md b/README.md index f5cd566..3bead42 100644 --- a/README.md +++ b/README.md @@ -71,12 +71,12 @@ Plugin options (all optional): * __extensions:__ An array of extensions (without the leading dot!) that should be considered "CSS files"; this is useful when you eg. name your files `.postcss` to indicate that you are using non-standard syntax. This list of extensions will *replace* the default list of extensions, so you will need to explicitly specify `"css"` in the list, if you want to keep parsing `.css` files. Defaults to `[ "css" ]`. * __mode:__ Whether to assume that untagged class names in your CSS (ie. those without a `:local` or `:global` tag) are local or global. Defaults to `"local"`, but you can set this to `"global"` if you want to make the class name mangling *opt-in*. You'll generally want to leave this at the default setting. +* __autoExportImports:__ Whether to automatically re-export all imports in a CSS file. When disabled, only *explicitly-defined* class names are exported from a CSS file. Defaults to `true`, ie. all imports are automatically re-exported under their local name. * __before:__ PostCSS transforms to run *before* the ICSS transforms, ie. before imports/exports are analyzed. This is usually where you want custom PostCSS plugins to go. * __after:__ PostCSS transforms to run *after* the ICSS transforms, ie. after mangling the class names, but before bundling it all together into a single file. You'll rarely need to use this. * __ignoreCycles:__ When enabling this, `icssify` will handle cyclical dependencies by randomly (but deterministically) ignoring a dependency relation during sorting. This *should* be safe to do for JS files, but there's no guarantee - and if things break in strange ways when you enable this, that is probably why. __Cyclical dependencies in CSS files are *still* not allowed__, even when enabling this setting! It's just intended to deal with cyclical JS dependencies during sorting, which are a bad practice but technically valid to have. It's opt-in to ensure that you understand the risks of enabling it. - ## Changelog ### v2.0.0 (August 23, 2020) diff --git a/notes.md b/notes.md new file mode 100644 index 0000000..8bc7bc4 --- /dev/null +++ b/notes.md @@ -0,0 +1,3 @@ +# FIXME + +- Check that `autoExportImports` works together correctly with `mode` diff --git a/src/postcss/postprocess.js b/src/postcss/postprocess.js index 9aea3aa..f623357 100644 --- a/src/postcss/postprocess.js +++ b/src/postcss/postprocess.js @@ -15,6 +15,7 @@ module.exports = function createFilePostprocessor(options) { // TODO: Reuse instance, figure out how to pass the file metadata to the callback for an individual `process` call let postcssInstance = postcss([ icssParser({ + autoExportImports: options.autoExportImports, keyReplacer: ({ url, remoteKey }) => { let resolvedSourcePath = item.deps[url]; diff --git a/src/transform.js b/src/transform.js index 90f440b..06d5c92 100644 --- a/src/transform.js +++ b/src/transform.js @@ -14,7 +14,7 @@ module.exports = function (state) { return function createTransform(file, options) { // TODO: Reuse instance? let preprocessFile = createFilePreprocessor(options); - + if (isCss({ file: file })) { let buffer = new bl.BufferList();