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

Fix the bug "failing to update when using browserify" #128

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ npm install vueify --save-dev
browserify -t vueify -e src/main.js -o build/build.js
```

If you are using npm 3+, it no longer auto install the peer dependencies. So you will also have to also install the babel-related dependencies:
If you are using npm 3+ and **babel**, it no longer auto install the peer dependencies. So you will also have to also install the babel-related dependencies:

``` bash
npm install\
Expand Down Expand Up @@ -121,9 +121,9 @@ Make sure to have the `NODE_ENV` environment variable set to `"production"` when

If you are using Gulp, note that `gulp --production` **does not** affect vueify; you still need to explicitly set `NODE_ENV=production`.

## ES2015 by Default
## ES2015 when `babel-core` installed

Vueify automatically transforms the JavaScript in your `*.vue` components using Babel. Write ES2015 today!
Vueify automatically transforms the JavaScript in your `*.vue` components using Babel when it is installed. Write ES2015 today!

The default Babel (6) options used for Vue.js components are:

Expand Down
12 changes: 10 additions & 2 deletions lib/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ try {
hotReloadAPIPath = 'vueify/node_modules/vue-hot-reload-api'
}

var hasBabel = true
try {
require('babel-core')
} catch (e) {
hasBabel = false
}

var htmlMinifyOptions = {
collapseWhitespace: true,
removeComments: true,
Expand Down Expand Up @@ -149,7 +156,7 @@ compiler.compile = function (content, filePath, cb) {
' hotAPI.install(require("vue"), true)\n' +
' if (!hotAPI.compatible) return\n' +
// remove style tag on dispose
(style
((style && 'object' === typeof(__vueify_style__) && __vueify_style__ instanceof Node)
? ' module.hot.dispose(function () {\n' +
' __vueify_insert__.cache[' + style + '] = false\n' +
' document.head.removeChild(__vueify_style__)\n' +
Expand Down Expand Up @@ -291,7 +298,8 @@ function processStyle (node, filePath, id) {
*/

function processScript (node, filePath, content) {
var lang = checkLang(node) || 'babel'
var lang = checkLang(node) || (hasBabel ? 'babel' : null)

var script = checkSrc(node, filePath)
if (!script) {
script = parse5.serialize(node)
Expand Down
16 changes: 12 additions & 4 deletions lib/style-rewriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,16 @@ module.exports = function (id, css, scoped) {
if (val) {
return Promise.resolve(val)
} else {
var plugins = options.postcss
? options.postcss.slice()
: []
var plugins = []
var opts = {}

if (options.postcss instanceof Array) {
plugins = options.postcss.slice()
} else if (options.postcss instanceof Object) {
plugins = options.postcss.plugins || []
opts = options.postcss.options
}

// scoped css rewrite
if (scoped) {
plugins.push(addId)
Expand All @@ -66,7 +73,7 @@ module.exports = function (id, css, scoped) {
}
currentId = id
return postcss(plugins)
.process(css)
.process(css, opts)
.then(function (res) {
var val = {
source: res.css,
Expand All @@ -77,3 +84,4 @@ module.exports = function (id, css, scoped) {
})
}
}

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vueify",
"version": "8.5.4",
"version": "8.7.0",
"description": "Vue component transform for Browserify",
"main": "index.js",
"repository": {
Expand Down