-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 85bb765
Showing
6 changed files
with
285 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
|
||
# Dependency directory | ||
node_modules | ||
|
||
# Unwanted | ||
.idea | ||
.DS_Store | ||
|
||
# Build files | ||
index.cjs.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2016 Thomas Ghysels | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
# Rollup multiple .scss, .sass and .css imports | ||
|
||
### Integrates nicely with rollup-plugin-vue2 | ||
|
||
<a href="LICENSE"> | ||
<img src="https://img.shields.io/badge/license-MIT-brightgreen.svg" alt="Software License" /> | ||
</a> | ||
<a href="https://github.com/thgh/rollup-plugin-scss/issues"> | ||
<img src="https://img.shields.io/github/issues/thgh/rollup-plugin-scss.svg" alt="Issues" /> | ||
</a> | ||
<a href="http://standardjs.com/"> | ||
<img src="https://img.shields.io/badge/code%20style-standard-brightgreen.svg" alt="JavaScript Style Guide" /> | ||
</a> | ||
<a href="https://npmjs.org/package/rollup-plugin-scss"> | ||
<img src="https://img.shields.io/npm/v/rollup-plugin-scss.svg?style=flat-squar" alt="NPM" /> | ||
</a> | ||
<a href="https://github.com/thgh/rollup-plugin-scss/releases"> | ||
<img src="https://img.shields.io/github/release/thgh/rollup-plugin-scss.svg" alt="Latest Version" /> | ||
</a> | ||
|
||
## Installation | ||
``` | ||
npm install --save-dev rollup-plugin-scss | ||
``` | ||
|
||
## Usage | ||
```js | ||
// rollup.config.js | ||
import scss from 'rollup-plugin-scss' | ||
|
||
export default { | ||
entry: 'entry.js', | ||
dest: 'bundle.js', | ||
plugins: [ | ||
scss() // will output compiled styles to bundle.css | ||
] | ||
} | ||
``` | ||
|
||
```js | ||
// entry.js | ||
import './reset.css' | ||
``` | ||
|
||
### Options | ||
|
||
Options are passed to [node-sass]. | ||
By default the plugin will base the filename for the css on the bundle destination. | ||
|
||
```js | ||
vue({ | ||
// Default behaviour is to write all styles to the bundle destination where .js is replaced by .css | ||
output: true, | ||
|
||
// Filename to write all styles to | ||
output: 'bundle.css', | ||
|
||
// Callback that will be called ongenerate with two arguments: | ||
// - styles: the contents of all style tags combined: 'body { color: green }' | ||
// - styleNodes: an array of style objects: { filename: 'body { ... }' } | ||
output: function (styles, styleNodes) { | ||
writeFileSync('bundle.css', styles) | ||
}, | ||
|
||
// Disable any style output or callbacks, import as string | ||
output: false | ||
}) | ||
``` | ||
|
||
## Changelog | ||
|
||
Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently. | ||
|
||
## Contributing | ||
|
||
Contributions and feedback are very welcome. | ||
|
||
To get it running: | ||
1. Clone the project. | ||
2. `npm install` | ||
|
||
## Credits | ||
|
||
- [Thomas Ghysels](https://github.com/thgh) | ||
- [All Contributors][link-contributors] | ||
|
||
## License | ||
|
||
The MIT License (MIT). Please see [License File](LICENSE) for more information. | ||
|
||
[link-author]: https://github.com/thgh | ||
[link-contributors]: ../../contributors | ||
[rollup-plugin-vue]: https://www.npmjs.com/package/rollup-plugin-vue | ||
[rollup-plugin-buble]: https://www.npmjs.com/package/rollup-plugin-buble | ||
[rollup-plugin-babel]: https://www.npmjs.com/package/rollup-plugin-babel | ||
[node-sass]: https://www.npmjs.com/package/node-sass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { writeFile } from 'fs' | ||
import { dirname } from 'path' | ||
import { createFilter } from 'rollup-pluginutils' | ||
import { renderSync } from 'node-sass' | ||
|
||
export default function css(options = {}) { | ||
const filter = createFilter(options.include || ['**/*.css', '**/*.scss', '**/*.sass'], options.exclude); | ||
let dest = options.output | ||
|
||
const styles = {} | ||
let includePaths = options.includePaths || [] | ||
includePaths.push(process.cwd()) | ||
|
||
return { | ||
name: 'css', | ||
transform(code, id) { | ||
if (!filter(id)) { | ||
return | ||
} | ||
|
||
// When output is disabled, the stylesheet is exported as a string | ||
if (options.output === false) { | ||
return { | ||
code: 'export default ' + JSON.stringify(code), | ||
map: { mappings: '' } | ||
} | ||
} | ||
|
||
// Map of every stylesheet | ||
styles[id] = code | ||
includePaths.push(dirname(id)) | ||
|
||
return '' | ||
}, | ||
ongenerate (opts, rendered) { | ||
// No stylesheet needed | ||
if (options.output === false) { | ||
return | ||
} | ||
|
||
// Combine all stylesheets | ||
let css = '' | ||
for (const id in styles) { | ||
css += styles[id] || '' | ||
} | ||
|
||
// Compile SASS to CSS | ||
includePaths = includePaths.filter((v, i, a) => a.indexOf(v) === i) | ||
css = renderSync(Object.assign({ | ||
data: css, | ||
includePaths | ||
}, options)).css.toString(); | ||
|
||
// Emit styles through callback | ||
if (typeof options.output === 'function') { | ||
options.output(css, styles) | ||
return | ||
} | ||
|
||
if (typeof dest !== 'string') { | ||
// Don't create unwanted empty stylesheets | ||
if (!css.length) { | ||
return | ||
} | ||
|
||
// Guess destination filename | ||
dest = opts.dest || 'bundle.js' | ||
if (dest.endsWith('.js')) { | ||
dest = dest.slice(0, -3) | ||
} | ||
dest = dest + '.css' | ||
} | ||
|
||
// Emit styles to file | ||
writeFile(dest, css, (err) => { | ||
if (err) { | ||
throw err | ||
} | ||
console.log(green(dest), getSize(css.length)) | ||
}) | ||
} | ||
} | ||
} | ||
|
||
function green (text) { | ||
return '\u001b[1m\u001b[32m' + text + '\u001b[39m\u001b[22m' | ||
} | ||
|
||
function getSize (bytes) { | ||
return bytes < 10000 | ||
? bytes.toFixed(0) + ' B' | ||
: bytes < 1024000 | ||
? (bytes / 1024).toPrecision(3) + ' kB' | ||
: (bytes / 1024 / 1024).toPrecision(4) + ' MB' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
{ | ||
"name": "rollup-plugin-scss", | ||
"version": "0.1.0", | ||
"description": "Rollup multiple .scss, .sass and .css imports", | ||
"main": "index.cjs.js", | ||
"module": "index.es.js", | ||
"jsnext:main": "index.es.js", | ||
"scripts": { | ||
"build": "rollup -c -f cjs -o index.cjs.js", | ||
"dev": "rollup -cw -f cjs -o index.cjs.js", | ||
"lint": "standard rollup.config.js index.es.js", | ||
"prepublish": "npm run build" | ||
}, | ||
"keywords": [ | ||
"rollup-plugin", | ||
"vue2", | ||
"css", | ||
"sass", | ||
"scss" | ||
], | ||
"license": "MIT", | ||
"author": "Thomas Ghysels <info@thomasg.be>", | ||
"homepage": "https://github.com/thgh/rollup-plugin-scss", | ||
"bugs": { | ||
"url": "https://github.com/thgh/rollup-plugin-scss/issues" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/thgh/rollup-plugin-scss" | ||
}, | ||
"files": [ | ||
"index.cjs.js", | ||
"index.es.js" | ||
], | ||
"dependencies": { | ||
"node-sass": "^3.10.1", | ||
"rollup-pluginutils": "^1.5.2" | ||
}, | ||
"devDependencies": { | ||
"rollup": "^0.36.0", | ||
"rollup-plugin-buble": "^0.14.0", | ||
"rollup-watch": "^2.5.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import buble from 'rollup-plugin-buble' | ||
|
||
export default { | ||
entry: 'index.es.js', | ||
dest: 'index.common.js', | ||
plugins: [ | ||
buble() | ||
], | ||
// Cleaner console | ||
onwarn (msg) { | ||
if (msg && msg.startsWith('Treating')) { | ||
return | ||
} | ||
} | ||
} |