Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions crates/pack-core/src/shared/transforms/inline_css/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,9 @@ impl InlineCssModuleType {
follow_reexports: module_options_context.follow_reexports,
module_fragments_enabled: module_options_context.module_fragments_enabled,
mangle_export_names: module_options_context.ecmascript.mangle_export_names,
source_map_generation_options: module_options_context
.ecmascript
.source_map_generation_options,
..Default::default()
}
.resolved_cell(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const assert = require("node:assert/strict");
const fs = require("node:fs");
const path = require("node:path");
const vm = require("node:vm");

const outputDir = path.join(__dirname, "output");
assert.deepEqual(
fs.readdirSync(outputDir),
["main.min.js"],
"minified inline CSS must emit its JavaScript bundle without CSS or map files",
);

const injectedStyles = [];
const document = {
querySelector(selector) {
assert.equal(selector, "head");
return {
appendChild(style) {
injectedStyles.push(style);
},
};
},
createElement(tagName) {
assert.equal(tagName, "style");
return {
textContent: "",
appendChild(node) {
this.textContent += node.textContent;
},
removeAttribute(name) {
assert.equal(name, "media");
},
};
},
createTextNode(textContent) {
return { textContent };
},
};

const filename = path.join(outputDir, "main.min.js");
const bundle = fs.readFileSync(filename, "utf8");
const sandbox = { URL, window: {}, document };
vm.runInNewContext(bundle, sandbox, { filename, timeout: 2000 });

assert.equal(sandbox.InlineCssMinifiedLibrary.getValue(), 42);
assert.equal(injectedStyles.length, 1, "the stylesheet must auto-inject");
assert.match(
injectedStyles[0].textContent,
/\.minified-inline-css\s*\{\s*color:\s*red/,
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"runtimeType": "Production",
"config": {
"entry": [
{
"import": "input/index.js",
"name": "main",
"library": {
"name": "InlineCssMinifiedLibrary"
}
}
],
"optimization": {
"minify": true,
"moduleIds": "named"
},
"output": {
"filename": "main.min.js"
},
"sourceMaps": false,
"styles": {
"inlineCss": {}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import "./style.css";

export function getValue() {
return 42;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.minified-inline-css {
color: red;
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading