Skip to content
This repository was archived by the owner on Dec 26, 2018. It is now read-only.

Prevent empty css #218

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prevent empty css
Problems addressed:
- When there are no styles on a Vue single-file-component and there is an out path defined in the extract-css plugin, the file is created anyway.
- When the directory provided by the out path doesn't exist, the css file isn't created and the write action silently fails.

This proposal tries to block the write action on empty styles (can be bypassed with the allowEmpty option) and creates the directory if it does not exist.
  • Loading branch information
pedro-mm-pereira authored Jan 29, 2018
commit 11652bf532b5634cc9c8a1923902c63c875768ce
23 changes: 15 additions & 8 deletions plugins/extract-css.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var fs = require('fs')
var path = require('path')
var compiler = require('../lib/compiler')

module.exports = function (b, opts) {
Expand All @@ -8,17 +9,23 @@ module.exports = function (b, opts) {

var styles = Object.create(null)
var outPath = opts.out || opts.o || 'bundle.css'
var allowEmpty = opts.allowEmpty || opts.empty || false

b.on('bundle', function (bs) {
bs.on('end', function () {
var css = Object.keys(styles)
.map(function (file) { return styles[file] })
.join('\n')
if (typeof outPath === 'object' && outPath.write) {
outPath.write(css)
outPath.end()
} else if (typeof outPath === 'string') {
fs.writeFile(outPath, css, function () {})
if (allowEmpty || (!allowEmpty && Object.keys(styles)[0] !== undefined)) {
var css = Object.keys(styles)
.map(function (file) { return styles[file] })
.join('\n')
if (typeof outPath === 'object' && outPath.write) {
outPath.write(css)
outPath.end()
} else if (typeof outPath === 'string') {
if (!fs.existsSync(path.dirname(outPath))) {
fs.mkdirSync(path.dirname(outPath))
}
fs.writeFile(outPath, css, function () {})
}
}
})
})
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy