You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Parcel API Bundle.getEntryAssets() seems to ignore (or fail to create the appropriate properties) CSS files. This is present in the newer versions of the bundler.
import{Parcel}from'@parcel/core';importpathfrom'path';import{fileURLToPath}from'url';import{writeFile}from'fs/promises';importchalkfrom"chalk";// Required to convert the current module URL to a pathconst__filename=fileURLToPath(import.meta.url);const__dirname=path.dirname(__filename);asyncfunctionbuildAndRetrieveHashes(){// Define the entry file or directoryconstentryFile=path.join(__dirname,'src/index.html');constdistDir=path.join(__dirname,'build')// Initialize a new Parcel bundlerconstbundler=newParcel({entries: entryFile,defaultConfig: '@parcel/config-default',mode: 'production',// 'production' or 'development'targets: {default: {distDir: distDir,publicUrl: "."}},additionalReporters: [{packageName: '@parcel/reporter-cli',resolveFrom: __filename}]});try{// Run the bundler to build the projectconst{ bundleGraph }=awaitbundler.run();// Extract the mapping of files to hashesconstfileObject={}bundleGraph.getBundles().forEach(bundle=>{bundle.getEntryAssets().forEach(asset=>{fileObject[path.basename(asset.filePath)]=path.basename(bundle.filePath);});});// Save the mapping to a JSON file inside the dist directoryconstmappingsFilePath=path.join(distDir,'mappings.json');awaitwriteFile(mappingsFilePath,JSON.stringify(fileObject,null,2));console.log(chalk.green.bold("\n✨ File to hash mapping saved to ")+chalk.dim("build/")+chalk.white.bold(path.basename(mappingsFilePath))+chalk.green.bold("."));}catch(error){console.error('Build failed:',error);}}buildAndRetrieveHashes();
We use the Parcel API bundler to compile the project and make use of the getBundles() and getEntryAssets() functions in order to map the relations between certain files to their bundled variants. The mappings.json file is then used to retrieve those files and create a custom HTML file to our business' needs.
💻 Code Sample
Here is the main TS file (index.ts) that is included in the HTML and where the CSS gets imported:
import{Loader,LoaderConfig}from"core/src/Loader"import{Game}from"./Game"import"core/src/assets/style.css"import"core/src/assets/dev.css"importmanifestfrom"./manifest"importmainfrom"./configs/placements/placement.main"importdesktopfrom"./configs/placements/placement.desktop"importmobilefrom"./configs/placements/placement.mobile"importverticalfrom"./configs/placements/placement.vertical"importlanguagesfrom"./configs/languages/main"constconfig: LoaderConfig={placements: {
main,
desktop,
mobile,
vertical
},
languages
}newLoader(manifest,config).init((...params)=>newGame(...params))//@ts-ignoreif(module.hot){module.hot.accept(function(){location.reload()})}
Interestingly enough, everything gets bundled correctly, it is just that the getEntryAssets() function does not return any assets when bundling the CSS file. It is also important to note that when I used console.log() to inspect, when printing the bundle.filePath, everything is outputted, but when printing the bundle.getMainEntry() or bundle.getEntryAssets(), it returns undefined ([] for getEntryAssets()) for the style.css.
🌍 Your Environment
This seems to happen on the newer version of the bundler. When looking at some games that we installed packages at an older date (@parcel/bundler-default version 2.10.3) it works just fine, meanwhile in the current version when running npm i (@parcel/bundler-default version 2.12.0) this issue exists.
Software
Version(s)
Parcel
2.8.3
Node
18.16.0
npm/Yarn
9.5.1
Operating System
Kubuntu 22.04
The text was updated successfully, but these errors were encountered:
🐛 bug report
The Parcel API
Bundle.getEntryAssets()
seems to ignore (or fail to create the appropriate properties) CSS files. This is present in the newer versions of the bundler.🎛 Configuration (.babelrc, package.json, cli command)
package.json
parcel-build.mjs
🤔 Expected Behavior
The
mappings.json
file should look like this:😯 Current Behavior
The
mappings.json
file looks like this:💁 Possible Solution
N/A
🔦 Context
We use the Parcel API bundler to compile the project and make use of the
getBundles()
andgetEntryAssets()
functions in order to map the relations between certain files to their bundled variants. Themappings.json
file is then used to retrieve those files and create a custom HTML file to our business' needs.💻 Code Sample
Here is the main TS file (
index.ts
) that is included in the HTML and where the CSS gets imported:And here is the HTML file (
index.html
):Interestingly enough, everything gets bundled correctly, it is just that the
getEntryAssets()
function does not return any assets when bundling the CSS file. It is also important to note that when I usedconsole.log()
to inspect, when printing thebundle.filePath
, everything is outputted, but when printing thebundle.getMainEntry()
orbundle.getEntryAssets()
, it returnsundefined
([]
forgetEntryAssets()
) for thestyle.css
.🌍 Your Environment
This seems to happen on the newer version of the bundler. When looking at some games that we installed packages at an older date (
@parcel/bundler-default
version2.10.3
) it works just fine, meanwhile in the current version when runningnpm i
(@parcel/bundler-default
version2.12.0
) this issue exists.The text was updated successfully, but these errors were encountered: