Skip to content

Commit

Permalink
fix: use this.emitFile() API from rollup (#666)
Browse files Browse the repository at this point in the history
  • Loading branch information
tivac committed Sep 15, 2019
1 parent 0a7996e commit 108a4a1
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 21 deletions.
36 changes: 27 additions & 9 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -44,7 +44,7 @@
"lerna": "^3.16.4",
"pegjs": "0.10.0",
"read-dir-deep": "^6.0.0",
"rollup": "^1.11.3",
"rollup": "^1.21.3",
"rollup-plugin-hypothetical": "^2.1.0",
"rollup-plugin-svelte": "^5.0.3",
"shelljs": "^0.8.3",
Expand Down
32 changes: 22 additions & 10 deletions packages/rollup/rollup.js
Expand Up @@ -257,7 +257,11 @@ module.exports = (opts) => {
continue;
}

const id = this.emitAsset(`${name}${ext}`, result.css);
const id = this.emitFile({
type : "asset",
name : `${name}${ext}`,
source : result.css,
});

// Save off the final name of this asset for later use
const dest = this.getAssetFileName(id);
Expand All @@ -266,21 +270,21 @@ module.exports = (opts) => {

log("css output", dest);

// Maps can't be written out via the asset APIs becuase they shouldn't ever be hashed.
// They shouldn't be hashed because they simply follow the name of their parent .css asset.
// So add them to the bundle directly.
if(result.map) {
// Make sure to use the rollup name as the base, otherwise it won't
// automatically handle duplicate names correctly
const fileName = dest.replace(ext, `${ext}.map`);

log("map output", fileName);

bundle[fileName] = {
isAsset : true,
source : result.map.toString(),
this.emitFile({
type : "asset",
source : result.map.toString(),

// Use fileName instead of name because this has to follow the parent
// file naming and can't be double-hashed
fileName,
};
});

// Had to re-add the map annotation to the end of the source files
// if the filename had a hash, since we stripped it out up above
Expand All @@ -297,7 +301,11 @@ module.exports = (opts) => {

const compositions = await processor.compositions;

this.emitAsset(dest, JSON.stringify(compositions, null, 4));
this.emitFile({
type : "asset",
name : dest,
source : JSON.stringify(compositions, null, 4),
});
}

const meta = {};
Expand Down Expand Up @@ -328,7 +336,11 @@ module.exports = (opts) => {

log("metadata output", dest);

this.emitAsset(dest, JSON.stringify(meta, null, 4));
this.emitFile({
type : "asset",
source : JSON.stringify(meta, null, 4),
name : dest,
});
}
},
};
Expand Down
2 changes: 1 addition & 1 deletion packages/rollup/test/__snapshots__/splitting.test.js.snap
Expand Up @@ -408,7 +408,7 @@ Object {
color: red;
}
",
"simple.96e4896f.js": "
"simple.336b919d.js": "
var css = {
\\"str\\": \\"\\\\\\"string\\\\\\"\\",
\\"fooga\\": \\"fooga\\"
Expand Down

0 comments on commit 108a4a1

Please sign in to comment.