ipynb2html/patches/rollup-plugin-postcss+2.0.6.patch
2021-06-12 15:18:25 +02:00

85 lines
3.1 KiB
Diff

Ported from https://github.com/egoist/rollup-plugin-postcss/pull/226
diff --git a/node_modules/rollup-plugin-postcss/dist/index.js b/node_modules/rollup-plugin-postcss/dist/index.js
index 3d04b2e..01dda37 100644
--- a/node_modules/rollup-plugin-postcss/dist/index.js
+++ b/node_modules/rollup-plugin-postcss/dist/index.js
@@ -789,15 +789,14 @@ var index = ((options = {}) => {
},
generateBundle(opts, bundle) {
- return _asyncToGenerator(function* () {
- if (extracted.size === 0) return; // TODO: support `[hash]`
+ var _this2 = this;
+ return _asyncToGenerator(function* () {
+ if (extracted.size === 0) return;
const dir = opts.dir || path.dirname(opts.file);
const file = opts.file || path.join(opts.dir, Object.keys(bundle).find(fileName => bundle[fileName].isEntry));
const getExtracted = () => {
- const fileName = typeof postcssLoaderOptions.extract === 'string' ? normalizePath(path.relative(dir, postcssLoaderOptions.extract)) : `${path.basename(file, path.extname(file))}.css`;
- const concat = new Concat(true, fileName, '\n');
const entries = Array.from(extracted.values());
const modules = bundle[normalizePath(path.relative(dir, file))].modules;
@@ -806,6 +805,32 @@ var index = ((options = {}) => {
entries.sort((a, b) => fileList.indexOf(a.id) - fileList.indexOf(b.id));
}
+ let referenceId;
+
+ if (typeof postcssLoaderOptions.extract === 'string') {
+ referenceId = _this2.emitFile({
+ type: 'asset',
+ source: '',
+ // init
+ fileName: normalizePath(path.relative(dir, postcssLoaderOptions.extract))
+ });
+ } else {
+ const name = `${path.basename(file, path.extname(file))}.css`; // Base hash digest on concatenation of extracted code...
+
+ const source = entries.reduce((acc, {
+ code
+ }) => acc + code, '');
+ referenceId = _this2.emitFile({
+ type: 'asset',
+ source,
+ name
+ });
+ }
+
+ const fileName = _this2.getFileName(referenceId);
+
+ const concat = new Concat(true, fileName, '\n');
+
for (var _i = 0; _i < entries.length; _i++) {
const res = entries[_i];
const relative = normalizePath(path.relative(dir, res.id));
@@ -872,20 +897,14 @@ var index = ((options = {}) => {
}
}
- const codeFile = {
- fileName: codeFileName,
- isAsset: true,
- source: code
- };
- bundle[codeFile.fileName] = codeFile;
+ bundle[codeFileName].source = code; // update
if (map) {
- const mapFile = {
- fileName: mapFileName,
- isAsset: true,
- source: map
- };
- bundle[mapFile.fileName] = mapFile;
+ _this2.emitFile({
+ type: 'asset',
+ source: map,
+ fileName: mapFileName
+ });
}
})();
}