Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: princed/postcss-modules-values-replace
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: faee159cfd8a911ba3a80efa6268cab75b31c2c3
Choose a base ref
...
head repository: princed/postcss-modules-values-replace
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: d88587a0e82a23e353ed5e927dd451d46766f1d0
Choose a head ref

Commits on Nov 18, 2016

  1. 🗑️

    princed committed Nov 18, 2016
    Copy the full SHA
    4192ca5 View commit details
  2. 📝

    princed committed Nov 18, 2016
    Copy the full SHA
    0367d49 View commit details
  3. 📝

    princed committed Nov 18, 2016
    Copy the full SHA
    eae7c3c View commit details

Commits on Nov 25, 2016

  1. fix(package): add a pre-publish compile step (#3)

    * fix(package): add a pre-publish compile step
    
    * add linting before publish, revert removal of 'files'
    Kumar Harsh authored and princed committed Nov 25, 2016
    Copy the full SHA
    b091b86 View commit details
  2. 📝

    princed committed Nov 25, 2016
    Copy the full SHA
    cdf75e2 View commit details
  3. 1.1.0

    princed committed Nov 25, 2016
    Copy the full SHA
    0b751fe View commit details

Commits on Dec 7, 2016

  1. ➖ (closes #4)

    princed committed Dec 7, 2016
    Copy the full SHA
    92f3373 View commit details
  2. 1.1.1

    princed committed Dec 7, 2016
    Copy the full SHA
    6697b3f View commit details

Commits on Feb 9, 2017

  1. Return the found variables in messages (#5)

    * Return the found variables in messages
    
    * Added test for 'variables are also present in messages'
    
    * Add documentation.
    Changed the message object format to conform to postcss expectations.
    breaking change: value property renamed to value.
    alexhisen authored and princed committed Feb 9, 2017
    Copy the full SHA
    cbb4451 View commit details
  2. * Support for modules

    * Refactor and add moar ESnext
    
    Closes #1
    princed committed Feb 9, 2017
    Copy the full SHA
    07eb5ef View commit details
  3. 💄

    princed committed Feb 9, 2017
    Copy the full SHA
    27fa7d6 View commit details
  4. 📝

    princed committed Feb 9, 2017
    Copy the full SHA
    a6b826a View commit details
  5. 🔩

    princed committed Feb 9, 2017
    Copy the full SHA
    2d8ec3f View commit details
  6. princed committed Feb 9, 2017
    Copy the full SHA
    cb77c35 View commit details
  7. 🔨

    princed committed Feb 9, 2017
    Copy the full SHA
    8183376 View commit details
  8. 🙈

    princed committed Feb 9, 2017
    Copy the full SHA
    ac6b998 View commit details
  9. 1.2.0

    princed committed Feb 9, 2017
    Copy the full SHA
    4608cb8 View commit details

Commits on Feb 10, 2017

  1. 🙈🙈🙈

    princed committed Feb 10, 2017
    Copy the full SHA
    a7cba64 View commit details
  2. 1.2.1

    princed committed Feb 10, 2017
    Copy the full SHA
    ba17353 View commit details

Commits on May 15, 2017

  1. Copy the full SHA
    925c2e0 View commit details
  2. Copy the full SHA
    9cea29e View commit details
  3. 🔩

    princed committed May 15, 2017
    Copy the full SHA
    cb0d76f View commit details

Commits on Jun 22, 2017

  1. Copy the full SHA
    99c1979 View commit details

Commits on Jun 28, 2017

  1. Copy the full SHA
    fa9307d View commit details

Commits on Jul 13, 2017

  1. Copy the full SHA
    b13996e View commit details

Commits on Jan 8, 2018

  1. Make it lint again

    princed committed Jan 8, 2018
    Copy the full SHA
    7e721d8 View commit details
  2. Remove GK

    princed committed Jan 8, 2018
    Copy the full SHA
    60e5d0c View commit details
  3. ⬆️

    princed committed Jan 8, 2018
    Copy the full SHA
    51cb1fc View commit details
  4. Copy the full SHA
    8085be3 View commit details
  5. Copy the full SHA
    0e553ea View commit details
  6. Do not replace selectors

    princed committed Jan 8, 2018
    Copy the full SHA
    4f5ec11 View commit details
  7. 📝

    princed committed Jan 8, 2018
    Copy the full SHA
    8194b1d View commit details
  8. .gitignore *.iml

    princed committed Jan 8, 2018
    Copy the full SHA
    8bda6bf View commit details
  9. 2.0.0

    princed committed Jan 8, 2018
    Copy the full SHA
    0e2dd54 View commit details
  10. Drop old Nodes

    princed committed Jan 8, 2018
    Copy the full SHA
    015f7ca View commit details

Commits on Jan 17, 2018

  1. Copy the full SHA
    97e44b7 View commit details
  2. 2.0.1

    princed committed Jan 17, 2018
    Copy the full SHA
    d5b21d7 View commit details
  3. 2.0.2

    princed committed Jan 17, 2018
    Copy the full SHA
    e094c2c View commit details

Commits on Jan 18, 2018

  1. Copy the full SHA
    d974ef6 View commit details
  2. 3.0.0

    princed committed Jan 18, 2018
    Copy the full SHA
    ff5132d View commit details

Commits on Jan 30, 2018

  1. Wallaby config clean up

    princed committed Jan 30, 2018
    Copy the full SHA
    c762569 View commit details
  2. .gitignore clean up

    princed committed Jan 30, 2018
    Copy the full SHA
    70a58ad View commit details
  3. Copy the full SHA
    4da3fe9 View commit details
  4. Copy the full SHA
    5c78b4f View commit details
  5. 3.0.1

    princed committed Jan 30, 2018
    Copy the full SHA
    f5df7b0 View commit details

Commits on Jan 19, 2020

  1. Support removal of @value exports, fixes #27 (#28)

    nickw444 authored and princed committed Jan 19, 2020
    Copy the full SHA
    4e07cb5 View commit details

Commits on Jan 30, 2020

  1. 3.1.0

    princed committed Jan 30, 2020
    Copy the full SHA
    198b0d4 View commit details

Commits on Mar 2, 2021

  1. Allow preprocessing of value declarations (#30)

    * Added support for css-loader ~ syntax of module imports
    
    * Add config, remove plugins after current.
    
    * Update readme
    
    * Revert breaking url resolution change
    
    * Add importsAsModuleRequests option
    
    Co-authored-by: Shipov Mikhail <mshipov@yandex.ru>
    ackwell and SkReD authored Mar 2, 2021
    Copy the full SHA
    abb832c View commit details
  2. 3.2.0

    princed committed Mar 2, 2021
    Copy the full SHA
    d88587a View commit details
Showing with 574 additions and 218 deletions.
  1. +2 −0 .gitignore
  2. +1 −0 .npmrc
  3. +1 −2 .travis.yml
  4. +0 −20 LICENSE
  5. +171 −12 README.md
  6. +1 −0 fixtures/node_modules/@scope/module/module.css
  7. +1 −0 fixtures/node_modules/module/module.css
  8. +3 −0 fixtures/node_modules/module/package.json
  9. +159 −104 index.js
  10. +13 −21 package.json
  11. +220 −47 test.js
  12. +2 −12 wallaby.js
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
.idea/
*.iml
node_modules/
!fixtures/node_modules
npm-debug.log
yarn.lock
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
language: node_js
node_js:
- stable
- "6"
- node
20 changes: 0 additions & 20 deletions LICENSE

This file was deleted.

183 changes: 171 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -5,12 +5,60 @@
[ci]: https://travis-ci.org/princed/postcss-modules-values-replace
[ci-img]: https://travis-ci.org/princed/postcss-modules-values-replace.svg
[PostCSS]: https://github.com/postcss/postcss
[css-loader]: https://github.com/webpack/css-loader
[postcss-calc]: https://github.com/postcss/postcss-calc
[postcss-modules-values]: https://github.com/css-modules/postcss-modules-values

[css-loader]: https://github.com/webpack/css-loader
[postcss-calc]: https://github.com/postcss/postcss-calc
[postcss-cssnext]: https://github.com/MoOx/postcss-cssnext
[postcss-color-function]: https://github.com/postcss/postcss-color-function
[postcss-modules-tilda]: https://github.com/princed/postcss-modules-tilda
[postcss-modules-values]: https://github.com/css-modules/postcss-modules-values
[modules-values-extract]: https://github.com/alexhisen/modules-values-extract
[enhanced-resolve]: https://github.com/webpack/enhanced-resolve/#contributing
Replaces CSS Modules @values just as [postcss-modules-values] does, but without help of [css-loader],
so it could be used before other [PostCSS] plugins like [postcss-calc].
so it could be used before other [PostCSS] plugins like [postcss-calc].

Example:

```css
/* constants.css */
@value unit: 8px;
@value footer-height: calc(unit * 5);

/* my-components.css */
@value unit, footer-height from "./constants.css";
@value component-height: calc(unit * 10);

.my-component {
padding: unit;
margin-top: footer-height;
height: component-height;
}
```

yields `my-components.css`:

```css
@value unit, footer-height from "./constants.css";
@value component-height: calc(8px * 10);

.my-component {
padding: 8px;
margin-top: calc(8px * 5);
height: calc(8px * 10);
}
```

and leads to export of following values to JS:

```js
{
"unit": "8px",
"footer-height": "calc(8px * 5)",
"component-height": "calc(8px * 10)",
...
}
```

See how to export computed values in usage with `calc` example [below](#calc-and-value).

## Usage

@@ -19,19 +67,130 @@ Place it before other plugins:
postcss([ require('postcss-modules-values-replace'), require('postcss-calc') ]);
```

To make it faster in webpack pass its file system to plugin:
When using from webpack, pass its file system in `postcss.config.js` form:

```js
{
postcss: webpack => [
require('postcss-modules-values-replace')({fs: webpack._compiler.inputFileSystem}),
require('postcss-calc')
module.exports = (ctx) => ({
plugins: [
require('postcss-modules-values-replace')({fs: ctx.webpack._compiler.inputFileSystem}),
require('postcss-calc'),
]
});
```
See [PostCSS] docs for other examples for your environment.

### Configuration params

#### fs `Object`

File system to use. To make it faster in webpack pass its file system to plugin.
Cached Node's file system is used by default.

#### resolve `Object`

[enhanced-resolve]'s configuration object, see there for possible options and defaults.


#### noEmitExports `boolean`

When enabled @value rules/declarations will be removed from the emitted output

**Input:**
```css
@value myBrandColor blue;
@font-face {}

body { background: myBrandColor }
```

**Output:**
```css
@font-face {}

body { background: blue }
```

#### preprocessValues `boolean`

When enabled, permit plugins defined earlier in the PostCSS pipeline to modify `@value` declarations before they are recorded by this plugin.

#### importsAsModuleRequests `boolean`

When enabled, value imports will be resolved as module requests, in line with `css-loader`'s resolution logic [as of 2.0.0](https://github.com/webpack-contrib/css-loader/blob/master/CHANGELOG.md#200-2018-12-07).
If your code is written with pre-2.0 import syntax, and utilises [postcss-modules-tilda] for compatibility, this option is not required.

### calc() and @value

To enable calculations *inside* **@value**, enable media queries support in [postcss-calc]:

```js
postcss([
require('postcss-modules-values-replace'),
require('postcss-calc')({mediaQueries: true})
])
```

or via [postcss-cssnext]:

```js
postcss([
require('postcss-modules-values-replace'),
require('postcss-cssnext')({features: {calc: {mediaQueries: true}}})
])
```

Example with `calc` enabled:

```css
/* constants.css */
@value unit: 8px;
@value footer-height: calc(unit * 5);

/* my-components.css */
@value unit, footer-height from "./constants.css";
@value component-height: calc(unit * 10);

.my-component {
padding: unit;
margin-top: footer-height;
height: component-height;
}
```

###
yields `my-components.css`:

```css
@value unit, footer-height from "./constants.css";
@value component-height: 80px;

.my-component {
padding: 8px;
margin-top: 40px;
height: 80px;
}
```

and leads to export of following values to JS:

```js
{
"unit": "8px",
"footer-height": "40px",
"component-height": "80px",
...
}
```

### Other computations and @value

[postcss-calc] and [postcss-color-function] are known to work *inside* **@value** as they traverse media queries.
Experience with other plugins may differ if they ignore media queries.

### Extracting values for programmatic use
This plugin provides to postcss a custom [messages](http://api.postcss.org/Result.html#messages) object with `type: 'values'`.
The `values` property of that object will contain all the extracted values with all substitution performed (i.e. for values that reference other values).

See [PostCSS] docs for examples for your environment.
See [modules-values-extract] for an example of how this can be used.

## Environment

1 change: 1 addition & 0 deletions fixtures/node_modules/@scope/module/module.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions fixtures/node_modules/module/module.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions fixtures/node_modules/module/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading