File tree Expand file tree Collapse file tree 3 files changed +774
-34
lines changed Expand file tree Collapse file tree 3 files changed +774
-34
lines changed Original file line number Diff line number Diff line change 11const { pathToFileURL } = require ( "node:url" )
22const postcssUrl = require ( "postcss-url" )
33const postcss = require ( "postcss" )
4+ const cssnano = require ( "cssnano" )
45const SVGSpriter = require ( 'svg-sprite' ) ;
56
67function startWebSocketServer ( ) {
@@ -29,16 +30,31 @@ const getTemplatesEndpoint = () => {
2930 }
3031}
3132
32- const postcssPlugins = [
33- postcssUrl ( {
34- url : asset => {
35- if ( asset . url . includes ( "assets/" ) ) {
36- return `${ getTemplatesEndpoint ( ) } /${ asset . url } `
33+ const getPostcssPlugins = ( env ) => {
34+ const plugins = [
35+ postcssUrl ( {
36+ url : asset => {
37+ if ( asset . url . includes ( "assets/" ) ) {
38+ return `${ getTemplatesEndpoint ( ) } /${ asset . url } `
39+ }
40+ return asset . url
3741 }
38- return asset . url
39- }
40- } )
41- ]
42+ } )
43+ ]
44+
45+ // Add cssnano for production and staging builds
46+ if ( env === "production" || env === "staging" ) {
47+ plugins . push ( cssnano ( {
48+ preset : [ 'default' , {
49+ discardComments : {
50+ removeAll : true
51+ }
52+ } ]
53+ } ) )
54+ }
55+
56+ return plugins
57+ }
4258
4359const config = {
4460 shape : {
@@ -146,7 +162,7 @@ async function buildAll() {
146162
147163 const combined = `${ result . css . toString ( ) } `
148164
149- const postCssResult = await postcss ( postcssPlugins ) . process ( combined , { from : item . relative ( ) } )
165+ const postCssResult = await postcss ( getPostcssPlugins ( env ) ) . process ( combined , { from : item . relative ( ) } )
150166 const postCssCombined = postCssResult . css
151167
152168 fs . writeFileSync ( `dist/${ item . parent . name } /widget.css` , postCssCombined )
You can’t perform that action at this time.
0 commit comments