A starter set of CSS files for building modular web components and layouts.
at main 1.3 kB view raw
1const pkg = require('./package.json'); 2 3// Custom banner plugin that runs first 4const addBannerFirst = { 5 postcssPlugin: 'add-version-banner-first', 6 Once(root) { 7 root.prepend({ type: 'comment', text: `stylebase v${pkg.version}` }); 8 } 9}; 10 11// Custom banner plugin that runs last 12const addBannerLast = { 13 postcssPlugin: 'add-version-banner-last', 14 OnceExit(root) { 15 // Get the first node 16 const firstNode = root.first; 17 18 // If it's not already our version comment, add it 19 if (!firstNode || firstNode.type !== 'comment' || !firstNode.text.includes(`stylebase v${pkg.version}`)) { 20 root.prepend({ type: 'comment', text: `stylebase v${pkg.version}` }); 21 } 22 } 23}; 24 25module.exports = (ctx) => { 26 const isProduction = ctx.env !== 'preview'; 27 28 return { 29 plugins: [ 30 // Add banner first 31 addBannerFirst, 32 33 // Process @import statements 34 require('postcss-import'), 35 36 // Minify in production build only 37 isProduction && require('cssnano')({ 38 preset: ['default', { 39 discardComments: { 40 removeAll: false, // Don't remove all comments 41 removeAllButFirst: true // Keep the first comment 42 } 43 }] 44 }), 45 46 // Add banner again at the end in case it was removed 47 addBannerLast 48 ].filter(Boolean) 49 }; 50};