parcel-bundler
Version:
<p align="center"> <a href="https://parceljs.org/" target="_blank"> <img alt="Parcel" src="https://user-images.githubusercontent.com/19409/31321658-f6aed0f2-ac3d-11e7-8100-1587e676e0ec.png" width="749"> </a> </p>
30 lines (24 loc) • 749 B
JavaScript
const Packager = require('./Packager');
class CSSPackager extends Packager {
async addAsset(asset) {
let css = asset.generated.css || '';
// Figure out which media types this asset was imported with.
// We only want to import the asset once, so group them all together.
let media = [];
for (let dep of asset.parentDeps) {
if (!dep.media) {
// Asset was imported without a media type. Don't wrap in @media.
media.length = 0;
break;
} else {
media.push(dep.media);
}
}
// If any, wrap in an @media block
if (media.length) {
css = `@media ${media.join(', ')} {\n${css.trim()}\n}\n`;
}
await this.dest.write(css);
}
}
module.exports = CSSPackager;