Skip to content
Permalink
Browse files

fix: support chunks that don't depend on css (#544)

Fixes #543
  • Loading branch information...
tivac committed Jan 18, 2019
1 parent 5665237 commit 10074e3dc3f748160ebd8f4f5c0a0d65ecf5e1fb
@@ -313,7 +313,7 @@ module.exports = (opts) => {
});
}
}

if(options.json) {
const dest = typeof options.json === "string" ? options.json : "exports.json";

@@ -333,7 +333,12 @@ module.exports = (opts) => {

out.forEach(({ dest : file, dependencies }, entry) => {
meta[entry] = {
dependencies : [ file, ...dependencies.map((key) => out.get(key).dest) ]
dependencies : [
file,
...dependencies
.filter((key) => out.has(key))
.map((key) => out.get(key).dest),
]
};
});

@@ -303,34 +303,86 @@ Array [

exports[`/rollup.js code splitting should support outputting metadata about CSS dependencies 1`] = `
Array [
Object {
"file": "a.css",
"text": "/* packages/rollup/test/specimens/metadata/a.css */
.a { color: aqua; }
",
},
Object {
"file": "b.css",
"text": "/* packages/rollup/test/specimens/metadata/b.css */
.b { color: blue; }
",
},
Object {
"file": "chunk.css",
"text": "/* packages/rollup/test/specimens/simple.css */
.fooga {
color: red;
}
"text": "/* packages/rollup/test/specimens/metadata/d.css */
.d { color: darkkhaki; }
",
},
Object {
"file": "dependencies.css",
"text": "/* packages/rollup/test/specimens/dependencies.css */
.wooga {
"file": "metadata.json",
"text": "{
\\"chunk2.js\\": {
\\"dependencies\\": [
\\"assets/chunk.css\\"
]
},
\\"a.js\\": {
\\"dependencies\\": [
\\"assets/a.css\\",
\\"assets/chunk.css\\"
]
},
\\"b.js\\": {
\\"dependencies\\": [
\\"assets/b.css\\",
\\"assets/chunk.css\\"
]
}
}",
},
]
`;

background: blue;
}
exports[`/rollup.js code splitting should support outputting metadata about CSS dependencies to a named file 1`] = `
Array [
Object {
"file": "a.css",
"text": "/* packages/rollup/test/specimens/metadata/a.css */
.a { color: aqua; }
",
},
Object {
"file": "metadata.json",
"file": "b.css",
"text": "/* packages/rollup/test/specimens/metadata/b.css */
.b { color: blue; }
",
},
Object {
"file": "chunk.css",
"text": "/* packages/rollup/test/specimens/metadata/d.css */
.d { color: darkkhaki; }
",
},
Object {
"file": "chunks.json",
"text": "{
\\"chunk.js\\": {
\\"chunk2.js\\": {
\\"dependencies\\": [
\\"assets/chunk.css\\"
]
},
\\"a.js\\": {
\\"dependencies\\": [
\\"assets/a.css\\",
\\"assets/chunk.css\\"
]
},
\\"dependencies.js\\": {
\\"b.js\\": {
\\"dependencies\\": [
\\"assets/dependencies.css\\",
\\"assets/b.css\\",
\\"assets/chunk.css\\"
]
}
@@ -0,0 +1 @@
.a { color: aqua; }
@@ -0,0 +1,4 @@
import c from "./c.js";
import css from "./a.css";

console.log(css, c);
@@ -0,0 +1 @@
.b { color: blue; }
@@ -0,0 +1,4 @@
import c from "./c.js";
import css from "./b.css";

console.log(css, c);
@@ -0,0 +1,3 @@
import("./d.js").then(console.log);

export default "c";
@@ -0,0 +1 @@
.d { color: darkkhaki; }
@@ -0,0 +1,5 @@
import css from "./d.css";

console.log(css);

export default "d";
@@ -55,12 +55,12 @@ describe("/rollup.js", () => {

expect(dir("./splitting/assets")).toMatchSnapshot();
});

it("should support outputting metadata about CSS dependencies", async () => {
const bundle = await rollup({
input : [
require.resolve("./specimens/simple.js"),
require.resolve("./specimens/dependencies.js"),
require.resolve("./specimens/metadata/a.js"),
require.resolve("./specimens/metadata/b.js"),
],

plugins : [
@@ -85,6 +85,35 @@ describe("/rollup.js", () => {
expect(dir("./css-metadata/assets")).toMatchSnapshot();
});

it("should support outputting metadata about CSS dependencies to a named file ", async () => {
const bundle = await rollup({
input : [
require.resolve("./specimens/metadata/a.js"),
require.resolve("./specimens/metadata/b.js"),
],

plugins : [
plugin({
namer,
map,
meta : "chunks.json",
}),
],
});

await bundle.write({
format,
sourcemap,

assetFileNames,
chunkFileNames,

dir : prefix(`./output/css-metadata-named`),
});

expect(dir("./css-metadata-named/assets")).toMatchSnapshot();
});

it("should support splitting up CSS files w/ shared assets", async () => {
const bundle = await rollup({
input : [
@@ -359,15 +388,15 @@ describe("/rollup.js", () => {
require.resolve("./specimens/circular-dependencies/a.js"),
require.resolve("./specimens/circular-dependencies/b.js"),
],

plugins : [
plugin({
namer,
map,
}),
],
});

await bundle.write({
format,
sourcemap,
@@ -377,7 +406,7 @@ describe("/rollup.js", () => {

dir : prefix(`./output/circular-dependencies`)
});

expect(dir(`./circular-dependencies`)).toMatchSnapshot();
});
});

0 comments on commit 10074e3

Please sign in to comment.
You can’t perform that action at this time.