Permalink
Browse files

init

  • Loading branch information...
egoist
egoist committed Dec 7, 2015
0 parents commit ed445b067e0772aa39403db23bfb2bc4b6129aef
Showing with 225 additions and 0 deletions.
  1. +29 −0 .gitignore
  2. +1 −0 .npmignore
  3. +21 −0 LICENSE
  4. +40 −0 README.md
  5. +40 −0 package.json
  6. +14 −0 rollup.config.js
  7. +21 −0 src/index.js
  8. +25 −0 tests/build.js
  9. +3 −0 tests/fixture.css
  10. +5 −0 tests/fixture.js
  11. +3 −0 tests/fixture_clone.css
  12. +4 −0 tests/output.json
  13. +19 −0 tests/test.js
@@ -0,0 +1,29 @@
/index.js
# Logs
logs
*.log
# Runtime data
pids
*.pid
*.seed
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# node-waf configuration
.lock-wscript
# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release
# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git-
node_modules
@@ -0,0 +1 @@
/tests
21 LICENSE
@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2015 egoist aprilorange.net@icloud.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
@@ -0,0 +1,40 @@
## rollup-plugin-postcss
Seamless integration between Rollup and PostCSS.
## Installation
```bash
npm install rollup-plugin-postcss
```
## Example
**rollup.config.js**
```javascript
import { rollup } from 'rollup';
import postcss from 'rollup-plugin-postcss';
rollup({
entry: 'main.js',
plugins: [
postcss({
plugins: [
// cssnext(),
// yourPostcssPlugin()
]
})
]
}).then(...)
```
**entry**
```javascript
import '/path/to/some_random_file.css'
```
## License
MIT © [EGOIST](https://github.com/egoist)
@@ -0,0 +1,40 @@
{
"name": "rollup-plugin-postcss",
"version": "0.0.1",
"description": "Seamless integration between Rollup and PostCSS",
"main": "index.js",
"jsnext:main": "./src/index.js",
"scripts": {
"test": "npm run build && mocha --compilers js:babel-core/register tests/test.js --recursive",
"build": "rollup -c -o index.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/egoist/rollup-plugin-postcss.git"
},
"keywords": [
"postcss",
"rollup"
],
"author": "EGOIST <0x142857@gmail.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/egoist/rollup-plugin-postcss/issues"
},
"homepage": "https://github.com/egoist/rollup-plugin-postcss#readme",
"devDependencies": {
"ava": "^0.7.0",
"babel-core": "^5.8.32",
"chai": "^3.4.1",
"jsdom": "^7.2.0",
"mocha": "^2.3.4",
"mocha-jsdom": "^1.0.0",
"require-from-string": "^1.1.0",
"rollup": "^0.21.2",
"rollup-plugin-babel": "^1.0.0"
},
"dependencies": {
"postcss": "^5.0.12",
"style-inject": "0.0.11"
}
}
@@ -0,0 +1,14 @@
import babel from 'rollup-plugin-babel';
const external = Object.keys( require( './package.json' ).dependencies ) ;
export default {
entry: 'src/index.js',
plugins: [
babel({
exclude: 'node_modules/**'
})
],
external,
format: 'cjs'
};
@@ -0,0 +1,21 @@
import postcss from 'postcss';
import styleInject from 'style-inject';
export default function (options = {}) {
return {
intro () {
return styleInject.toString();
},
transform (code, id) {
if (id.slice( -4 ) !== '.css') {
return null;
}
code = postcss(options.plugins || []).process(code).css;
code = `export default styleInject(${JSON.stringify(code)});`
return {
code,
map: { mappings: '' }
};
}
};
};
@@ -0,0 +1,25 @@
import { rollup } from 'rollup';
import babel from 'rollup-plugin-babel';
import postcss from '../src/index';
import fs from 'fs';
export default function () {
return new Promise(async (resolve, reject) => {
await rollup({
plugins: [
postcss({
include: '**/*.css'
}),
babel({
exclude: '**/*.css'
}),
],
entry: __dirname +'/fixture.js'
}).then(bundle => {
const result = bundle.generate({
format: 'umd'
});
resolve(result.code);
}).catch(err => reject(err));
});
};
@@ -0,0 +1,3 @@
body {
margin: 0;
}
@@ -0,0 +1,5 @@
import './fixture.css';
import './fixture_clone.css';
const a = function () {
};
@@ -0,0 +1,3 @@
h1 {
margin: 0;
}
@@ -0,0 +1,4 @@
{
"code": "(function (global, factory) {\n typeof exports === 'object' && typeof module !== 'undefined' ? factory() :\n typeof define === 'function' && define.amd ? define(factory) :\n factory();\n}(this, function () { 'use strict';\n\n function styleInject(css) {\r\n css = css || '';\r\n var head = document.head || document.getElementsByTagName('head')[0];\r\n var style = document.createElement('style');\r\n style.type = 'text/css';\r\n if (style.styleSheet){\r\n style.styleSheet.cssText = css;\r\n } else {\r\n style.appendChild(document.createTextNode(css));\r\n }\r\n head.appendChild(style);\r\n }\n styleInject(\"body {\\r\\n margin: 0;\\r\\n}\\r\\n\");\n\n styleInject(\"h1 {\\r\\n margin: 0;\\r\\n}\\r\\n\");\n\n}));",
"map": null
}
@@ -0,0 +1,19 @@
import { expect } from 'chai';
import build from './build';
import jsdom from 'mocha-jsdom'
import requireFromString from 'require-from-string';
describe('main', () => {
jsdom();
it('test postcss', async done => {
const data = await build().catch(err => console.log(err));
requireFromString(data);
try {
const styles = window.getComputedStyle(document.body);
expect(styles.margin).to.equal('0');
done();
}catch(err) {
console.log(err);
}
});
});

0 comments on commit ed445b0

Please sign in to comment.