Using ExtractTextPlugin for Webpack, how do you not extract css and create an empty file with a flag? -


basically want extract css in production, want leave in javascript file in development mode.

this can have sourcemap working shows sass files used.

i want able have:

<link href="~/dist/css/site.css" rel="stylesheet" /> <script type="text/javascript" src="~/dist/js/manifest.js"></script> <script type="text/javascript" src="~/dist/js/css.js"></script> 

documentation bit thin on ground.

so in dev mode site.css empty , won't cause error if didn't exist. css.js used style , source mapping.

in production mode css.js exist not because css extracted. means css load nice , , minified in site.css have no mapping.

what did this: installed , required webpack-create-file-plugin created css directory .empty file in because directory must exist.

this how have done it:

const extractsass = new extracttextplugin("css/site.css"); const sassoptions = removeempty([     ifnotprod({         loader: "style-loader"     }),     {         loader: "css-loader",         options: {             sourcemap: ifnotprod()         }     }, {         loader: "sass-loader",         options: {             outputstyle: ifprod("compressed", "expanded"),             sourcemap: ifnotprod()         }     } ]); 

the sass rule looks this:

{     test: /\.scss$/,     use: ifprod(extractsass.extract({         use: sassoptions,         fallback: "style-loader"     }), sassoptions) } 

added plugins ifnotprod(new createfileplugin({files: ["css/site.css"]})) , ifprod(extractsass)


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -