Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

revert to 7.1.3 #237

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
node_modules
test/fixtures/*.actual.css
jspm_packages
84 changes: 0 additions & 84 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,87 +1,3 @@
# 8.1.2 - 2016-05-07

- Fixed: prevent JSPM to throw unrecoverable error
([#205](https://github.com/postcss/postcss-import/pull/205))

# 8.1.1 - 2016-05-04

- Fixed: JSPM support
([#194](https://github.com/postcss/postcss-import/pull/194))

# 8.1.0 - 2016-04-04

- Added: JSPM browser field
([#186](https://github.com/postcss/postcss-import/pull/186))

# 8.0.2 - 2015-01-27

- Fixed: Comments between imports statements are ignored
([#164](https://github.com/postcss/postcss-import/pull/164))

# 8.0.1 - 2015-01-27

- Fixed: missing "lib" folder
([#161](https://github.com/postcss/postcss-import/issues/161))

# 8.0.0 - 2015-01-27

**All imports statements must be at the top of your file now, per CSS specification.**
You should use [postcss-reporter](https://github.com/postcss/postcss-reporter) to see the warnings raised.

- Removed: async mode/option (now async by default)
([#107](https://github.com/postcss/postcss-import/pull/107))
- Removed: "bower_components" not supported by default anymore,
use "path" option to add it back
- Removed: `encoding` option. Encoding can be specified in custom `load` option

```js
postcssImport({
load: function(filename) {
return fs.readFileSync(filename, "utf-8")
}
})
```
([#144](https://github.com/postcss/postcss-import/pull/144))

- Removed: glob support
([#146](https://github.com/postcss/postcss-import/pull/146))

Globs can be implemented with custom `resolve` option

```js
postcssImport({
resolve: function(id, base) {
return glob.sync(path.join(base, id))
}
})
```

([#116](https://github.com/postcss/postcss-import/pull/116))
- Changed: custom resolve has more responsibility for paths resolving.
See [resolve option](https://github.com/postcss/postcss-import#resolve)
for more information about this change
([#116](https://github.com/postcss/postcss-import/pull/116))
- Changed: support promise in `transform` option and `undefined` result will be
skipped
([#147](https://github.com/postcss/postcss-import/pull/147))
- Changed: `options.plugins` are applied to unprocessed ast before imports
detecting
([157](https://github.com/postcss/postcss-import/pull/157))
- Added: custom resolve function can return array of paths
([#120](https://github.com/postcss/postcss-import/pull/120))
- Added: custom syntax in imported files support
([#130](https://github.com/postcss/postcss-import/pull/130))
- Added: support custom `load` option
([#144](https://github.com/postcss/postcss-import/pull/144))
- Added: detect css extension in package.json `main` field
([153](https://github.com/postcss/postcss-import/pull/153))

**Note:**
_If you miss options/default behavior (glob etc), a new plugin will handle all
those things.
Please follow issue [#145](https://github.com/postcss/postcss-import/issues/145)
_

# 7.1.3 - 2015-11-05

- Fixed: ensure node 0.12 compatibility, round 2
Expand Down
156 changes: 64 additions & 92 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,23 @@
# postcss-import
# postcss-import [![Travis Build Status](https://travis-ci.org/postcss/postcss-import.svg)](https://travis-ci.org/postcss/postcss-import) [![AppVeyor Build status](https://ci.appveyor.com/api/projects/status/u8l6u3lr6s5u5tpi?svg=true)](https://ci.appveyor.com/project/MoOx/postcss-import)

[![Unix Build status](https://img.shields.io/travis/postcss/postcss-import/master.svg?branch=master&label=unix%20build)](https://travis-ci.org/postcss/postcss-import)
[![Windows Build status](https://img.shields.io/appveyor/ci/MoOx/postcss-import/master.svg?label=window%20build)](https://ci.appveyor.com/project/MoOx/postcss-import/branch/master)
[![Version](https://img.shields.io/npm/v/postcss-import.svg)](https://github.com/postcss/postcss-import/blob/master/CHANGELOG.md)
> [PostCSS](https://github.com/postcss/postcss) plugin to transform `@import` rules by inlining content.

> [PostCSS](https://github.com/postcss/postcss) plugin to transform `@import`
rules by inlining content.

This plugin can consume local files, node modules or web_modules.
This plugin can consume local files, node modules or bower packages.
To resolve path of an `@import` rule, it can look into root directory
(by default `process.cwd()`), `web_modules`, `node_modules`
(by default `process.cwd()`), `node_modules`, `web_modules`, `bower_components`
or local modules.
_When importing a module, it will look for `index.css` or file referenced in
`package.json` in the `style` or `main` fields._
_When importing a module, it will looks for `index.css` or file referenced in
`package.json` in the `style` field._
You can also provide manually multiples paths where to look at.

**Notes:**

- **This plugin should probably be used as the first plugin of your list.
This way, other plugins will work on the AST as if there were only a single file
to process, and will probably work as you can expect**.
- This plugin works great with
[postcss-url](https://github.com/postcss/postcss-url) plugin,
which will allow you to adjust assets `url()` (or even inline them) after
inlining imported files.
- In order to optimize output, **this plugin will only import a file once** on
a given scope (root, media query...).
Tests are made from the path & the content of imported files (using a hash
table).
- **This plugin should probably be used as the first plugin of your list. This way, other plugins will work on the AST as if there were only a single file to process, and will probably work as you can expect**.
- This plugin works great with [postcss-url](https://github.com/postcss/postcss-url) plugin,
which will allow you to adjust assets `url()` (or even inline them) after inlining imported files.
- In order to optimize output, **this plugin will only import a file once** on a given scope (root, media query...).
Tests are made from the path & the content of imported files (using a hash table).
If this behavior is not what you want, look at `skipDuplicates` option
- **If you are looking for glob, or sass like imports (prefixed partials)**,
please look at
[postcss-easy-import](https://github.com/trysound/postcss-easy-import)
(which use this plugin under the hood).

## Installation

Expand All @@ -42,9 +27,7 @@ $ npm install postcss-import

## Usage

If your stylesheets are not in the same place where you run postcss
(`process.cwd()`), you will need to use `from` option to make relative imports
work from input dirname.
If your stylesheets are not in the same place where you run postcss (`process.cwd()`), you will need to use `from` option to make relative imports work from input dirname.

```js
// dependencies
Expand All @@ -56,25 +39,24 @@ var atImport = require("postcss-import")
var css = fs.readFileSync("css/input.css", "utf8")

// process css
postcss()
var output = postcss()
.use(atImport())
.process(css, {
// `from` option is required so relative import can work from input dirname
from: "css/input.css"
})
.then(function (result) {
var output = result.css
.css

console.log(output)
})
console.log(output)
```

Using this `input.css`:

```css
/* can consume `node_modules`, `web_modules` or local modules */
/* can consume `node_modules`, `web_modules`, `bower_components` or local modules */
@import "cssrecipes-defaults"; /* == @import "./node_modules/cssrecipes-defaults/index.css"; */
@import "normalize.css"; /* == @import "./node_modules/normalize.css/normalize.css"; */

@import "normalize.css/normalize"; /* == @import "./bower_components/normalize.css/normalize.css"; */

@import "css/foo.css"; /* relative to stylesheets/ according to `from` option above */

Expand All @@ -88,8 +70,9 @@ body {
will give you:

```css
/* ... content of ./node_modules/cssrecipes-defaults/index.css */
/* ... content of ./node_modules/normalize.css/normalize.css */
/* ... content of ./node_modules/my-css-on-npm/index.css */

/* ... content of ./bower_components/my-css-on-bower/index.css */

/* ... content of foo.css */

Expand All @@ -109,71 +92,68 @@ Checkout [tests](test) for more examples.
#### `root`

Type: `String`
Default: `process.cwd()` or _dirname of
[the postcss `from`](https://github.com/postcss/postcss#node-source)_
Default: `process.cwd()`

Define the root where to resolve path (eg: place where `node_modules` are).
Should not be used that much.
_Note: nested `@import` will additionally benefit of the relative dirname of
imported files._
Define the root where to resolve path (eg: place where `node_modules` and `bower_components` are). Should not be used that much.

#### `path`

Type: `String|Array`
Default: `[]`
Default: `process.cwd()` or _dirname of [the postcss `from`](https://github.com/postcss/postcss#node-source)_

A string or an array of paths in where to look for files.
_Note: nested `@import` will additionally benefit of the relative dirname of imported files._

#### `async`

A string or an array of paths in where to look for files.
Type: `Boolean`
Default: `false`

Allow to enable PostCSS async API usage. Before enabling this, check that your
runner allow async usage.
_Note: this is not enabling async fs read yet._

#### `transform`

Type: `Function`
Default: `null`

A function to transform the content of imported files. Take one argument (file
content) and should return the modified content or a resolved promise with it.
`undefined` result will be skipped.

```js
transform: function(css) {
return postcss([somePlugin]).process(css).then(function(result) {
return result.css;
});
}
```
A function to transform the content of imported files. Take one argument (file content) & should return the modified content.

#### `plugins`

Type: `Array`
Default: `undefined`

An array of plugins to be applied on each imported files.
An array of plugins to be applied on each imported file.

#### `encoding`

Type: `String`
Default: `utf8`

Use if your CSS is encoded in anything other than UTF-8.

#### `onImport`

Type: `Function`
Default: `null`

Function called after the import process. Take one argument (array of imported
files).
Function called after the import process. Take one argument (array of imported files).

#### `resolve`
#### `glob`

Type: `Function`
Default: `null`
Type: `Boolean`
Default: `false`

You can overwrite the default path resolving way by setting this option.
This function gets `(id, basedir, importOptions)` arguments and returns full
path, array of paths or promise resolving paths.
You can use [resolve](https://github.com/substack/node-resolve) for that.
Set to `true` if you want @import rules to parse glob patterns.

#### `load`
#### `resolve`

Type: `Function`
Default: null
Default: `null`

You can overwrite the default loading way by setting this option.
This function gets `(filename, importOptions)` arguments and returns content or
promised content.
You can overwrite the default path resolving way by setting this option, using the `resolve.sync(id, opts)` signature that [resolve.sync](https://github.com/substack/node-resolve#resolvesyncid-opts) has.

#### `skipDuplicates`

Expand All @@ -187,25 +167,19 @@ disable it.

#### `addDependencyTo`

Type: `Object`
Type: `Function`
Default: null

An object with `addDependency()` method, taking file path as an argument.
Called whenever a file is imported.
You can use it for hot-reloading in webpack `postcss-loader` like this:
Allow to generate and call a callback that take one argument, the object from
which you need to call `addDependency` from.
Called whenever a file is imported, handy in a webpack workflow.
It's equivalent to `onImport` with the following code:

```js
postcss: function(webpack) {
return [
require('postcss-import')({
addDependencyTo: webpack
/* Is equivalent to
onImport: function (files) {
files.forEach(this.addDependency)
}.bind(webpack)
*/
})
]
{
onImport: function (files) {
files.forEach(this.addDependency)
}.bind(obj) // obj = the argument you should pass to `addDependencyTo()`
}
```

Expand All @@ -215,15 +189,13 @@ postcss: function(webpack) {
var postcss = require("postcss")
var atImport = require("postcss-import")

postcss()
var css = postcss()
.use(atImport({
path: ["src/css"],
path: ["src/css"]
transform: require("css-whitespace")
}))
.process(cssString)
.then(function (result) {
var css = result.css
})
.css
```

---
Expand Down
1 change: 1 addition & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ install:
test_script:
- node --version
- npm --version
- ps: "npm test # PowerShell"
- cmd: "npm test"
Loading