Skip to content

Commit

Permalink
v2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jleeson committed Feb 12, 2021
1 parent 004d341 commit b2c8470
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ A single file, or array of files to exclude when minifying.
Type: `string`
Default: `null`

An output file for the css bundle.
An output file name for the css bundle.

### transform

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rollup-plugin-import-css",
"version": "1.1.7",
"version": "2.0.0",
"description": "A Rollup plugin to import CSS into JavaScript",
"main": "dist/plugin.cjs.js",
"module": "dist/plugin.esm.js",
Expand Down
13 changes: 3 additions & 10 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default (options = {}) => {
},

/* output a css file with all css that was imported without being assigned a variable */
generateBundle(options, bundle) {
generateBundle(opts, bundle) {
for (let file in bundle) {

let modules = Array.isArray(bundle[file].modules) ? bundle[file].modules : Object.getOwnPropertyNames(bundle[file].modules);
Expand All @@ -52,17 +52,10 @@ export default (options = {}) => {
if(css.trim().length <= 0 && !alwaysOutput) return;

/* create the directories in the output option if they do not already exist */
const output = options.output || path.join(path.dirname(options.file), path.basename(file, path.extname(options.file)) + ".css");
const outputParts = output.split("/");
const outputFile = outputParts.pop();
const outputPath = path.join(process.cwd(), outputParts.join("/"));

if(outputParts.length > 0 && !(fs.existsSync(outputPath))) {
fs.mkdirSync(outputPath, { recursive: true });
}
const output = options.output || path.join(path.dirname(opts.file), path.basename(file, path.extname(opts.file)) + ".css");

/* write the css content to a file */
fs.writeFileSync(path.join(outputPath, outputFile) || path.join(path.dirname(options.file), path.basename(file, path.extname(options.file)) + ".css"), css);
this.emitFile({ type: "asset", fileName: output, source: css });
}
}
};
Expand Down

0 comments on commit b2c8470

Please sign in to comment.