Skip to content

Commit

Permalink
chore(packager): replace VUE_SFC_STYLE_PLACEHOLDER with cssContents f…
Browse files Browse the repository at this point in the history
…rom bundle
  • Loading branch information
gogoend committed Oct 16, 2023
1 parent 892d6b0 commit 821a207
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions core/parcel-packager-vue-content-script-style-injector/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,27 +102,27 @@ var _default = new (_plugin().Packager)({
if (
/VUE_SFC_STYLE_PLACEHOLDER/.test(contents)
) {
let promises = [];
bundle.traverseAssets(asset => {
if (asset.filePath.endsWith('.vue')) {
console.log(asset.filePath, asset.pipeline, asset.type)
promises.push(Promise.all([
asset.getCode(),
asset.getMap()
]));
// get css asset from bundleGraph
const cssBundle = new Set()
bundleGraph.traverseBundles((bundle) => {
if (bundle.type === 'css') {
cssBundle.add(bundle)
}
});
})

let cssAssets = new Set()
;[...cssBundle].forEach(bundle => {
bundle.traverseAssets(asset => {
console.log(asset.filePath, asset.pipeline, asset.type)
cssAssets.add(asset)
});
})
const cssContents = await Promise.all([...cssAssets].map(asset => asset.getCode()))

let styleAssets = await Promise.all(promises)
console.log(styleAssets)
// TODO: Here we should replace the placeholder with the css assets content. But there is no css asset?
// console.log(styleAssets)
contents = contents.replace(
/VUE_SFC_STYLE_PLACEHOLDER/,
`
* {
background-color: red;
}
` // sample css content
`${cssContents.join('\n')}`
)
}
//#endregion
Expand Down

0 comments on commit 821a207

Please sign in to comment.