rollup-plugin-css-lit
Version:
Rollup plugin for importing CSS sources as constructable stylesheets to projects using lit (lit-html and lit-element) or fast-element.
1 lines • 4.97 kB
Source Map (JSON)
{"version":3,"file":"index.cjs","sources":["escape-tag-template.js","css-to-module.js","error.js","index.js"],"sourcesContent":["export default function escapeTaggedTemplate(source) {\n return source\n .replaceAll('\\\\', '\\\\\\\\')\n .replaceAll('`', '\\\\`')\n .replaceAll('$', '\\\\$')\n}\n","import escapeTaggedTemplate from './escape-tag-template.js'\n\nexport default function cssToModule(css, tag, specifier) {\n return `import { ${tag} } from '${specifier}';\nexport default ${tag}\\`${escapeTaggedTemplate(css)}\\`;`\n}\n","export default function handleError({ message, reason, column, line }) {\n if (reason) {\n this.error(reason,{ column, line })\n /* c8 ignore next 3 */\n } else {\n this.error(message)\n }\n}\n","import { createFilter } from '@rollup/pluginutils'\nimport { resolve } from 'node:path'\nimport { createProcessor } from 'rollup-copy-transform-css'\nimport cssToModule from './css-to-module.js'\nimport handleError from './error.js'\n\n/**\n * lit CSS rollup plugin\n *\n * @param {Object} opts Options\n * @param {string[]} [opts.include] Pattern to match files which will be processed by the plugin.\n * @param {string[]} [opts.exclude] Pattern to match files which will be ignored by the plugin.\n * @param {Object} [opts.options] Options for the Sass compiler. Use any options supported by the `compileString`\n * method from the Sass package.\n * @param {boolean|Object} [opts.minify] Enables minifying of the transformed CSS output. If an object is specified, it\n * will be passed to the cssnano plugin.\n * @param {boolean|Object} [opts.inline] Enables inlining of stylesheets and other assets. If an object is specified,\n * it will have to include two properties pointing to objects: { stylesheets, assets }. The stylesheets objects will\n * be passed to the postcss-import plugin. The assets objects will be passed to the postcss-url plugin.\n * @param {Object[]} [opts.plugins] An array of PostCSS plugins to fully customise the transformation of the CSS input.\n * @param {string} [opts.tag='css'] The tag used for the tagged template literal exported from the generated module.\n * Use 'css' (default) with both lit-html and fast-element.\n * @param {string} [opts.specifier='lit'] The import specifier used in the import declaration of the tag above. Use\n * 'lit' (default) with lit-html and '@microsoft/fast-element' with fast-element.\n * @returns {import('rollup').Plugin}\n */\nexport function litCss({\n include = ['**/*.css'], exclude, minify, inline, plugins,\n tag = 'css', specifier = 'lit'\n} = {}) {\n const filter = createFilter(include, exclude)\n if (!(minify || plugins)) {\n inline = true\n }\n const processor = createProcessor({ minify, inline, plugins })\n\n return {\n name: 'lit-css',\n\n load(id) {\n if (filter(id)) {\n this.addWatchFile(resolve(id))\n }\n },\n\n async transform(source, id) {\n if (filter(id)) {\n try {\n const { css } = await processor.process(source, { from: id, map: false })\n return { code: cssToModule(css, tag, specifier), map: { mappings: '' } }\n } catch (err) {\n handleError.call(this, err)\n }\n }\n }\n }\n}\n"],"names":["createFilter","createProcessor","resolve"],"mappings":";;;;;;AAAe,SAAS,oBAAoB,CAAC,MAAM,EAAE;AACrD,EAAE,OAAO;AACT,KAAK,UAAU,CAAC,IAAI,EAAE,MAAM;AAC5B,KAAK,UAAU,CAAC,GAAG,EAAE,KAAK;AAC1B,KAAK,UAAU,CAAC,GAAG,EAAE,KAAK;AAC1B;;ACHe,SAAS,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,SAAS,EAAE;AACzD,EAAE,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC,SAAS,EAAE,SAAS,CAAC;AAC9C,eAAe,EAAE,GAAG,CAAC,EAAE,EAAE,oBAAoB,CAAC,GAAG,CAAC,CAAC,GAAG;AACtD;;ACLe,SAAS,WAAW,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE;AACvE,EAAE,IAAI,MAAM,EAAE;AACd,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE;AACtC;AACA,GAAG,MAAM;AACT,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO;AACtB;AACA;;ACDA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SA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