UNPKG

@lwc/style-compiler

Version:

Transform style sheet to be consumed by the LWC engine

46 lines 2.09 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); /* * Copyright (c) 2018, salesforce.com, inc. * All rights reserved. * SPDX-License-Identifier: MIT * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ const postcss_1 = __importDefault(require("postcss")); const cssnano_1 = __importDefault(require("cssnano")); const serialize_1 = __importDefault(require("./serialize")); const lwc_postcss_plugin_1 = __importDefault(require("./lwc-postcss-plugin")); const CSS_NANO_CONFIG = { preset: ['default'], // Disable SVG compression, since it prevent the compiler to be bundle by webpack since // it dynamically require the svgo package: https://github.com/svg/svgo svgo: false, // Disable zindex normalization, since it only works when it works only if the rules // css file contains all the selectors applied on the page. zindex: false, }; function transform(src, id, config = {}) { if (src === '') { return { code: 'export default undefined' }; } const allowDefinition = !config.customProperties || config.customProperties.allowDefinition; const collectVarFunctions = Boolean(config.customProperties && config.customProperties.resolverModule); const minify = config.outputConfig && config.outputConfig.minify; const plugins = [ lwc_postcss_plugin_1.default({ customProperties: { allowDefinition, collectVarFunctions }, }) ]; if (minify) { // We are unshifting to ensure minification runs before lwc // This is important because we clone declarations that can't be mangled by the minifier. plugins.unshift(cssnano_1.default(CSS_NANO_CONFIG)); } const result = postcss_1.default(plugins).process(src, { from: id }); return { code: serialize_1.default(result, config) }; } exports.transform = transform; //# sourceMappingURL=transform.js.map