rollup-plugin-img
Advanced tools
Comparing version 1.0.4 to 1.0.5
@@ -16,3 +16,4 @@ 'use strict'; | ||
function img(opt) { | ||
!opt && (opt = {}); | ||
if ( opt === void 0 ) opt = {}; | ||
var extensions = opt.extensions || /\.(png|jpg|jpeg|gif|svg)$/; | ||
@@ -32,3 +33,3 @@ var filter = rollupPluginutils.createFilter(opt.include, opt.exclude); | ||
} else { //copy file to distPath | ||
var output = opt.output || ''; | ||
var output = path.relative('./', opt.output) || ''; | ||
if (!fs.existsSync(output)) { | ||
@@ -43,4 +44,6 @@ var dirs = output.split('/'); | ||
var outputFile = output + "/" + (path.basename(id)); | ||
var baseIndex = outputFile.indexOf('/'); | ||
baseIndex = baseIndex !== -1 ? baseIndex + 1 : 0; | ||
fs.createReadStream(id).pipe(fs.createWriteStream(outputFile)); | ||
return ("export default \"" + outputFile + "\""); | ||
return ("export default \"" + (outputFile.slice(baseIndex)) + "\""); | ||
} | ||
@@ -47,0 +50,0 @@ } |
import { createReadStream, createWriteStream, existsSync, mkdirSync, readFileSync, statSync } from 'fs'; | ||
import { basename, extname } from 'path'; | ||
import { basename, extname, relative } from 'path'; | ||
import { createFilter } from 'rollup-pluginutils'; | ||
@@ -14,3 +14,4 @@ | ||
function img(opt) { | ||
!opt && (opt = {}); | ||
if ( opt === void 0 ) opt = {}; | ||
var extensions = opt.extensions || /\.(png|jpg|jpeg|gif|svg)$/; | ||
@@ -30,3 +31,3 @@ var filter = createFilter(opt.include, opt.exclude); | ||
} else { //copy file to distPath | ||
var output = opt.output || ''; | ||
var output = relative('./', opt.output) || ''; | ||
if (!existsSync(output)) { | ||
@@ -41,4 +42,6 @@ var dirs = output.split('/'); | ||
var outputFile = output + "/" + (basename(id)); | ||
var baseIndex = outputFile.indexOf('/'); | ||
baseIndex = baseIndex !== -1 ? baseIndex + 1 : 0; | ||
createReadStream(id).pipe(createWriteStream(outputFile)); | ||
return ("export default \"" + outputFile + "\""); | ||
return ("export default \"" + (outputFile.slice(baseIndex)) + "\""); | ||
} | ||
@@ -45,0 +48,0 @@ } |
{ | ||
"name": "rollup-plugin-img", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "import image files with rollup", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.cjs.js", |
import { statSync, readFileSync, createReadStream, createWriteStream, existsSync, mkdirSync } from 'fs'; | ||
import { extname, basename } from 'path'; | ||
import { extname, basename, relative } from 'path'; | ||
import { createFilter } from 'rollup-pluginutils'; | ||
@@ -13,4 +13,3 @@ | ||
function img(opt) { | ||
!opt && (opt = {}); | ||
function img(opt = {}) { | ||
const extensions = opt.extensions || /\.(png|jpg|jpeg|gif|svg)$/; | ||
@@ -30,3 +29,3 @@ const filter = createFilter(opt.include, opt.exclude); | ||
} else { //copy file to distPath | ||
const output = opt.output || ''; | ||
const output = relative('./', opt.output) || ''; | ||
if (!existsSync(output)) { | ||
@@ -40,5 +39,7 @@ const dirs = output.split('/'); | ||
} | ||
var outputFile = `${output}/${basename(id)}`; | ||
const outputFile = `${output}/${basename(id)}`; | ||
let baseIndex = outputFile.indexOf('/'); | ||
baseIndex = baseIndex !== -1 ? baseIndex + 1 : 0; | ||
createReadStream(id).pipe(createWriteStream(outputFile)); | ||
return `export default "${outputFile}"`; | ||
return `export default "${outputFile.slice(baseIndex)}"`; | ||
} | ||
@@ -45,0 +46,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7921
126