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
include proper polyfills when needed by fs.readFileSync() or
leave the missing dependency unresolved
😯 Current Behavior
Parcel includes dependencies when mentioning global (class) names in a comment or string.
🔦 Context
According to question #1370 inlining CSS into Javascript is possible by using fs.readFileSync().
That example did not work out of box. While trying to fix this with a workaround:
const Buffer = atob;
... I step by step discovered that the word Buffer includes a lot of polyfill code if the line was commented out.
💻 Code Sample
index.js(causing a Uncaught ReferenceError: Buffer is not defined exception)
import fs from 'fs';
(function() {
var styles = fs.readFileSync('./index.css');
console.log(styles);
var head = document.getElementsByTagName("head")[0],
style;
style = document.createElement("style");
style.setAttribute("type", "text/css");
style.innerText = styles;
head.appendChild(style);
})();
index.js(causing no exception)
import fs from 'fs';
// Magically include missing dependency "Buffer" by merely mentioning the word. :O
(function() {
var styles = fs.readFileSync('./index.css');
console.log(styles);
var head = document.getElementsByTagName("head")[0],
style;
style = document.createElement("style");
style.setAttribute("type", "text/css");
style.innerText = styles;
head.appendChild(style);
})();
@devongovett It would be nice to document the fs.readFileSync inlining behavior somewhere in docs, at least the part of not working with binary files & browser targets.
🐛 bug report
Parcel will include polyfills/dependencies if classnames or keywords are mentioned in a comment or string.
🎛 Configuration (.babelrc, package.json, cli command)
No configuration, ran with:
🤔 Expected Behavior
Parcel shall either
fs.readFileSync()
or😯 Current Behavior
Parcel includes dependencies when mentioning global (class) names in a comment or string.
🔦 Context
According to question #1370 inlining CSS into Javascript is possible by using
fs.readFileSync()
.That example did not work out of box. While trying to fix this with a workaround:
... I step by step discovered that the word
Buffer
includes a lot of polyfill code if the line was commented out.💻 Code Sample
index.js (causing a
Uncaught ReferenceError: Buffer is not defined
exception)index.js (causing no exception)
test.html
🌍 Your Environment
The text was updated successfully, but these errors were encountered: