fix: file copy

This commit is contained in:
Hamid Pourrabi
2023-06-01 15:00:45 +02:00
parent 7e8484a9ba
commit 0072496834
2 changed files with 4 additions and 27 deletions

View File

@@ -13,24 +13,9 @@ const schema = {
baseDir: {
type: "string",
},
baseOutputDir: {
type: "string",
},
},
}
function mkDirP(dir) {
this.addDependency(dir)
const baseDir = "/"
dir.split(path.sep).reduce((parent, child) => {
const full = path.resolve(baseDir, parent, child)
if (!fs.existsSync(full)) {
fs.mkdirSync(full)
}
return full
})
}
module.exports = function chromeUrlLoader(contents) {
const options = this.getOptions() || {}
const callback = this.async()
@@ -41,8 +26,6 @@ module.exports = function chromeUrlLoader(contents) {
options.baseDir = options.baseDir || process.cwd()
options.baseDir = options.baseDir.endsWith("/") ? options.baseDir.slice(0, -1) : options.baseDir
options.baseOutputDir = options.baseOutputDir || process.cwd()
options.baseOutputDir = options.baseOutputDir.endsWith("/") ? options.baseOutputDir.slice(0, -1) : options.baseOutputDir
options.publicDir = options.publicDir || ""
options.publicDir = options.publicDir.endsWith("/")
? options.publicDir.slice(0, -1)
@@ -56,17 +39,11 @@ module.exports = function chromeUrlLoader(contents) {
const fileName = path.basename(relativeFilePath)
const relativeDir = options.publicDir.split(path.sep).slice(1).join(path.sep)
const outputPath = path.join(options.baseOutputDir, options.publicDir, fileName)
const outputPath = path.join(options.publicDir, fileName)
const outputDir = path.dirname(outputPath)
mkDirP.call(this, outputDir)
fs.writeFile(outputPath, contents, (err) => {
if (err) {
return callback(err)
}
callback(null, `module.exports = chrome.runtime.getURL('${relativeDir}/${fileName}')`)
})
this.emitFile(outputPath, contents, null)
callback(null, `module.exports = chrome.runtime.getURL('${relativeDir}/${fileName}')`)
}
module.exports.raw = true;

View File

@@ -1,6 +1,6 @@
{
"name": "chrome-url-loader",
"version": "1.3.1",
"version": "1.3.2",
"description": "chrome extension URL loader for webpack",
"main": "index.js",
"repository": "https://github.com/chenasraf/chrome-url-loader.git",