Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Permit plugins to add assets directly to the bundle in Rollup 1.x #3105

Merged
merged 1 commit into from Sep 9, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/rollup/index.ts
Expand Up @@ -272,6 +272,16 @@ export default async function rollup(rawInputOptions: GenericConfigObject): Prom
throw error;
}
await graph.pluginDriver.hookSeq('generateBundle', [outputOptions, outputBundle, isWrite]);
for (const key of Object.keys(outputBundle)) {
const file = outputBundle[key] as any;
if (!file.type) {
graph.warnDeprecation(
'A plugin is directly adding properties to the bundle object in the "generateBundle" hook. This is deprecated and will be removed in a future Rollup version, please use "this.emitAsset" instead.',
false
);
file.type = 'asset';
}
}
graph.pluginDriver.finaliseAssets();

timeEnd('GENERATE', 1);
Expand Down
16 changes: 16 additions & 0 deletions test/form/samples/deprecated/emit-asset-hacky/_config.js
@@ -0,0 +1,16 @@
module.exports = {
description: 'supports emitting assets in a hacky way by editing the bundle object',
options: {
strictDeprecations: false,
plugins: {
generateBundle(options, outputBundle) {
const file = {
fileName: 'my-hacky-asset.txt',
isAsset: true,
source: 'My Hacky Source'
};
outputBundle[file.fileName] = file;
}
}
}
};
@@ -0,0 +1,5 @@
define(function () { 'use strict';

console.log('main');

});
@@ -0,0 +1,3 @@
'use strict';

console.log('main');
@@ -0,0 +1 @@
console.log('main');
@@ -0,0 +1,6 @@
(function () {
'use strict';

console.log('main');

}());
@@ -0,0 +1 @@
My Hacky Source
10 changes: 10 additions & 0 deletions test/form/samples/deprecated/emit-asset-hacky/_expected/system.js
@@ -0,0 +1,10 @@
System.register([], function () {
'use strict';
return {
execute: function () {

console.log('main');

}
};
});
@@ -0,0 +1,8 @@
(function (factory) {
typeof define === 'function' && define.amd ? define(factory) :
factory();
}(function () { 'use strict';

console.log('main');

}));
1 change: 1 addition & 0 deletions test/form/samples/deprecated/emit-asset-hacky/main.js
@@ -0,0 +1 @@
console.log('main');