forked from frappe/frappe
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build(deps): Bump from vue 2 to vue 3
- Loading branch information
1 parent
abeed35
commit 44e9f6b
Showing
3 changed files
with
74 additions
and
11 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
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,48 @@ | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
const { sites_path } = require("./utils"); | ||
|
||
module.exports = { | ||
name: "frappe-vue-style", | ||
setup(build) { | ||
build.initialOptions.write = false; | ||
build.onEnd((result) => { | ||
let files = get_files(result.metafile.outputs); | ||
let keys = Object.keys(files); | ||
for (let out of result.outputFiles) { | ||
let asset_path = "/" + path.relative(sites_path, out.path); | ||
let dir = path.dirname(out.path); | ||
if (out.path.endsWith(".js") && keys.includes(asset_path)) { | ||
let bundle_css = files[asset_path]; | ||
let include_css = '\nfrappe.require("' + bundle_css + '");\n'; | ||
let modified = include_css + out.text; | ||
out.contents = Buffer.from(modified); | ||
} | ||
if (!fs.existsSync(dir)){ | ||
fs.mkdirSync(dir); | ||
} | ||
fs.writeFile(out.path, out.contents, (err) => { | ||
err && console.error(err); | ||
}); | ||
} | ||
}); | ||
}, | ||
}; | ||
|
||
function get_files(files) { | ||
let result = {}; | ||
for (let file in files) { | ||
let info = files[file]; | ||
let asset_path = "/" + path.relative(sites_path, file); | ||
if (info && info.entryPoint && Object.keys(info.inputs).length !== 0) { | ||
for (let input in info.inputs) { | ||
if (input.includes(".vue?type=style")) { | ||
let bundle_css = path.basename(info.entryPoint).replace(".js", ".css"); | ||
result[asset_path] = bundle_css; | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
return result; | ||
} |
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