From 5909cb92215b4ccbc08e50da0224abb2b4ef2c2e Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 15 Jun 2016 19:49:38 -0400 Subject: [PATCH 01/43] include mkdirp as dep --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 42b6f4c..2ed6a3d 100644 --- a/package.json +++ b/package.json @@ -43,6 +43,7 @@ "jade": "^1.11.0", "jsdom": "^9.2.1", "less": "^2.5.1", + "mkdirp": "^0.5.1", "mocha": "^2.3.3", "node-sass": "^3.3.3", "pug": "^2.0.0-alpha6", From 9666af26f4c805371ce3c2ffcb3f00e897c8980a Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 15 Jun 2016 19:55:40 -0400 Subject: [PATCH 02/43] move changelog into releases --- README.md | 65 +------------------------------------------------------ 1 file changed, 1 insertion(+), 64 deletions(-) diff --git a/README.md b/README.md index da918e0..41f9f4e 100644 --- a/README.md +++ b/README.md @@ -327,70 +327,7 @@ If you use Webpack, there's also [vue-loader](https://github.com/vuejs/vue-loade ## Changelog -### 8.5.0 - -- Now also supports passing in Vueify options via browserify transform options. The options are exactly the same as `vue.config.js`. - -### 8.4.0 - -- Removed peer dependencies. Now vueify simply warns you when you are using a feature that requires a missing dependency. - -### 8.3.0 - -- Added compile-time template syntax validation that catches common errors. -- Code blocks with base indents are now de-indented before being processed. - -### 8.2.0 - -- Added `htmlMinifier` option in config that allows configuration of HTML minification in production mode. -- Fixed HTML minification removing `type` attribute for ``. - -### 8.1.0 - -- Vueify now respects `.babelrc` over default options. - -### 8.0.0 - -- `babel-core` is now a peer dependency. - -### 7.0.0 - -- Added relative `@import` path support and import dependency tracking for LESS, SASS & Stylus. Now you can `@import` files using relative paths to the file being edited, and editing these imported files will also trigger watchify rebuild. - -- Removed built-in compiler for `myth`. Prefer using PostCSS + CSSNext. - -### 6.0.0 - -- Upgraded to Babel 6. This is a breaking change because the babel configuration is now different. - -### 5.0.4 - -- Added `postcss` option for providing custom PostCSS plugins. - -### 5.0.0 - -- New: CSS output is now autoprefixed by default. -- Changed: [New config file format](#configuring-options) - -### 4.0.0 - -- Support ES2015 by default. - -### 3.0.0 - -- Added support for [scoped CSS](#scoped-css) and [component hot reloading](#hot-reload). - -### 2.0.1 - -- Built-in lang for ES2015 has been renamed from `es6` to `es`. - -- `es` transforms now uses loose mode and optional runtime by default. This means in addition to installing `babel`, you should also install `babel-runtime`. - -- Templates and CSS are now non-minified by default. To enable minification, run the build with `NODE_ENV=production`. - -- Options for built-in pre-processors can now be configured in `vue.config.js`. - -- `vue-component-compiler` has been merged into `vueify`. It is now exposed as `require('vueify').compiler`. +For version 9.0.0 and above, please see the [Releases](https://github.com/vuejs/vueify/releases) page for changes in each version. ## License From b26e25ba928c6f79cd673cc21ba6f386e7fff0a4 Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 15 Jun 2016 23:27:38 -0400 Subject: [PATCH 03/43] simplify insert-css --- lib/compiler.js | 21 +++++++++++---------- lib/insert-css.js | 9 +++++++-- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/lib/compiler.js b/lib/compiler.js index 01ae6c0..e3f3634 100644 --- a/lib/compiler.js +++ b/lib/compiler.js @@ -19,8 +19,10 @@ try { hasBabel = false } +var resolvedPartsCache = Object.create(null) + // determine dynamic script paths -var hotReloadAPIPath = normalize.dep('vue-hot-reload-api') +var hotReloadAPIPath = 'vue-hot-reload-api' //normalize.dep('vue-hot-reload-api') var insertCSSPath = normalize.lib('insert-css') // expose compiler @@ -79,14 +81,19 @@ compiler.compile = function (content, filePath, cb) { .catch(cb) function mergeParts () { + // check whether each part has changed + var prevParts = resolvedPartsCache[id] || {} + resolvedPartsCache[id] = resolvedParts + var scriptChanged = resolvedParts.script !== prevParts.script + var templateChanged = resolvedParts.template !== prevParts.template + var output = '' // styles var style = resolvedParts.styles.join('\n') if (style) { style = JSON.stringify(style) output += - 'var __vueify_insert__ = require("' + insertCSSPath + '")\n' + - 'var __vueify_style__ = __vueify_insert__.insert(' + style + ')\n' + 'var __vueify_style_dispose__ = require("' + insertCSSPath + '").insert(' + style + ')\n' } // script var script = resolvedParts.script @@ -120,13 +127,7 @@ compiler.compile = function (content, filePath, cb) { ' if (!hotAPI.compatible) return\n' + ' module.hot.accept()\n' + // remove style tag on dispose - (style - ? ' module.hot.dispose(function () {\n' + - ' __vueify_insert__.cache[' + style + '] = false\n' + - ' document.head.removeChild(__vueify_style__)\n' + - ' })\n' - : '' - ) + + (style ? ' module.hot.dispose(__vueify_style_dispose__)\n' : '') + ' if (!module.hot.data) {\n' + // initial insert ' hotAPI.createRecord("' + id + '", __vue__options__)\n' + diff --git a/lib/insert-css.js b/lib/insert-css.js index 69130e9..c3d3891 100644 --- a/lib/insert-css.js +++ b/lib/insert-css.js @@ -1,7 +1,9 @@ var inserted = exports.cache = {} +function noop () {} + exports.insert = function (css) { - if (inserted[css]) return + if (inserted[css]) return noop inserted[css] = true var elem = document.createElement('style') @@ -14,5 +16,8 @@ exports.insert = function (css) { } document.getElementsByTagName('head')[0].appendChild(elem) - return elem + return function () { + document.getElementsByTagName('head')[0].removeChild(elem) + inserted[css] = false + } } From 34830f98da82c5f48397f45baf10eebd9d019a6e Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 15 Jun 2016 23:32:04 -0400 Subject: [PATCH 04/43] more granular hot-reload --- lib/compiler.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/compiler.js b/lib/compiler.js index e3f3634..ec895dd 100644 --- a/lib/compiler.js +++ b/lib/compiler.js @@ -81,7 +81,7 @@ compiler.compile = function (content, filePath, cb) { .catch(cb) function mergeParts () { - // check whether each part has changed + // check whether script/template has changed var prevParts = resolvedPartsCache[id] || {} resolvedPartsCache[id] = resolvedParts var scriptChanged = resolvedParts.script !== prevParts.script @@ -133,7 +133,12 @@ compiler.compile = function (content, filePath, cb) { ' hotAPI.createRecord("' + id + '", __vue__options__)\n' + ' } else {\n' + // update - ' hotAPI.reload("' + id + '", __vue__options__)\n' + + (scriptChanged + ? ' hotAPI.reload("' + id + '", __vue__options__)\n' + : templateChanged + ? ' hotAPI.rerender("' + id + '", __vue__options__)\n' + : '' + ) + ' }\n' + '})()}' } From daf429460aa9326c5309d887de41b4c216526572 Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 15 Jun 2016 23:32:12 -0400 Subject: [PATCH 05/43] 9.0.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2ed6a3d..0fe586c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vueify", - "version": "9.0.0", + "version": "9.0.1", "description": "Vue component transform for Browserify", "main": "index.js", "repository": { From 13291e2a31f19f021580757aa642920d9f0ce726 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sat, 18 Jun 2016 13:38:17 -0400 Subject: [PATCH 06/43] support CSS extraction --- index.js | 7 +++++++ lib/compiler.js | 17 +++++++++++++---- plugins/extract-css.js | 29 +++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 4 deletions(-) create mode 100644 plugins/extract-css.js diff --git a/index.js b/index.js index 2e1b3a3..5374cfb 100644 --- a/index.js +++ b/index.js @@ -9,11 +9,16 @@ module.exports = function vueify (file, options) { var data = '' var stream = through(write, end) + stream.vueify = true function dependency(file) { stream.emit('file', file) } + function emitStyle (style) { + stream.emit('vueify-style', style) + } + function write(buf) { data += buf } @@ -21,9 +26,11 @@ module.exports = function vueify (file, options) { function end () { stream.emit('file', file) compiler.on('dependency', dependency) + compiler.on('style', emitStyle) compiler.compile(data, file, function(error, result) { compiler.removeListener('dependency', dependency) + compiler.removeListener('style', emitStyle) if (error) { stream.emit('error', error) // browserify doesn't log the stack by default... diff --git a/lib/compiler.js b/lib/compiler.js index ec895dd..4a8bd74 100644 --- a/lib/compiler.js +++ b/lib/compiler.js @@ -91,9 +91,16 @@ compiler.compile = function (content, filePath, cb) { // styles var style = resolvedParts.styles.join('\n') if (style) { - style = JSON.stringify(style) - output += - 'var __vueify_style_dispose__ = require("' + insertCSSPath + '").insert(' + style + ')\n' + // emit style + compiler.emit('style', { + file: filePath, + style: style + }) + if (!process.env.VUEIFY_EXTRACT_CSS) { + style = JSON.stringify(style) + output += + 'var __vueify_style_dispose__ = require("' + insertCSSPath + '").insert(' + style + ')\n' + } } // script var script = resolvedParts.script @@ -127,7 +134,9 @@ compiler.compile = function (content, filePath, cb) { ' if (!hotAPI.compatible) return\n' + ' module.hot.accept()\n' + // remove style tag on dispose - (style ? ' module.hot.dispose(__vueify_style_dispose__)\n' : '') + + (style && !process.env.VUEIFY_EXTRACT_CSS + ? ' module.hot.dispose(__vueify_style_dispose__)\n' + : '') + ' if (!module.hot.data) {\n' + // initial insert ' hotAPI.createRecord("' + id + '", __vue__options__)\n' + diff --git a/plugins/extract-css.js b/plugins/extract-css.js new file mode 100644 index 0000000..c0d7122 --- /dev/null +++ b/plugins/extract-css.js @@ -0,0 +1,29 @@ +process.env.VUEIFY_EXTRACT_CSS = true + +var fs = require('fs') + +module.exports = function (b, opts) { + var outPath = opts.out || opts.o || 'bundle.css' + var styles = Object.create(null) + + b.on('bundle', function (bs) { + bs.on('end', function () { + fs.writeFile(outPath, Object.keys(styles) + .map(function (file) { return styles[file] }) + .join('\n')) + }) + }) + + b.on('reset', listen) + listen() + + function listen () { + b.on('transform', function (tr, file) { + if (tr.vueify) { + tr.on('vueify-style', function (e) { + styles[e.file] = e.style + }) + } + }) + } +} From a916805df9682e3d40c3f230328c71a0566a5230 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sat, 18 Jun 2016 20:23:31 -0400 Subject: [PATCH 07/43] refactor compiler options --- index.js | 4 +++- lib/compiler.js | 10 ++++++---- lib/compilers/babel.js | 5 ++--- lib/compilers/coffee.js | 5 ++--- lib/compilers/jade.js | 5 ++--- lib/compilers/less.js | 3 +-- lib/compilers/options.js | 1 - lib/compilers/pug.js | 5 ++--- lib/compilers/sass.js | 3 +-- lib/compilers/stylus.js | 3 +-- lib/style-rewriter.js | 4 ++-- plugins/extract-css.js | 5 +++-- 12 files changed, 25 insertions(+), 28 deletions(-) delete mode 100644 lib/compilers/options.js diff --git a/index.js b/index.js index 5374cfb..f072524 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,9 @@ var through = require('through') var compiler = require('./lib/compiler') -compiler.loadConfig() +compiler.loadConfig({ + extractCss: true +}) module.exports = function vueify (file, options) { if (!/.vue$/.test(file)) return through() diff --git a/lib/compiler.js b/lib/compiler.js index 4a8bd74..aa55d7e 100644 --- a/lib/compiler.js +++ b/lib/compiler.js @@ -9,7 +9,6 @@ var vueCompiler = require('vue-template-compiler') var genId = require('./gen-id') var normalize = require('./normalize') var compilers = require('./compilers') -var options = require('./compilers/options') var rewriteStyle = require('./style-rewriter') var hasBabel = true @@ -29,6 +28,9 @@ var insertCSSPath = normalize.lib('insert-css') var compiler = module.exports = new Emitter() compiler.setMaxListeners(Infinity) +// options +var options = compiler.options = {} + // load user config compiler.loadConfig = function () { var fs = require('fs') @@ -96,7 +98,7 @@ compiler.compile = function (content, filePath, cb) { file: filePath, style: style }) - if (!process.env.VUEIFY_EXTRACT_CSS) { + if (!options.extractCSS) { style = JSON.stringify(style) output += 'var __vueify_style_dispose__ = require("' + insertCSSPath + '").insert(' + style + ')\n' @@ -134,7 +136,7 @@ compiler.compile = function (content, filePath, cb) { ' if (!hotAPI.compatible) return\n' + ' module.hot.accept()\n' + // remove style tag on dispose - (style && !process.env.VUEIFY_EXTRACT_CSS + (style && !options.extractCSS ? ' module.hot.dispose(__vueify_style_dispose__)\n' : '') + ' if (!module.hot.data) {\n' + @@ -189,7 +191,7 @@ function processStyle (part, filePath, id, parts) { var style = getContent(part, filePath) return compileAsPromise('style', style, part.lang, filePath) .then(function (res) { - return rewriteStyle(id, res, part.scoped).then(function (res) { + return rewriteStyle(id, res, part.scoped, options).then(function (res) { parts.styles.push(res) }) }) diff --git a/lib/compilers/babel.js b/lib/compilers/babel.js index ebbb7bf..742465b 100644 --- a/lib/compilers/babel.js +++ b/lib/compilers/babel.js @@ -1,6 +1,5 @@ var fs = require('fs') var path = require('path') -var options = require('./options') var ensureRequire = require('../ensure-require') var defaultBabelOptions = { @@ -36,10 +35,10 @@ if (babelOptions === defaultBabelOptions) { } } -module.exports = function (raw, cb) { +module.exports = function (raw, cb, compiler) { try { var babel = require('babel-core') - var res = babel.transform(raw, options.babel || babelOptions) + var res = babel.transform(raw, compiler.options.babel || babelOptions) } catch (err) { return cb(err) } diff --git a/lib/compilers/coffee.js b/lib/compilers/coffee.js index 9f277a8..d0238e1 100644 --- a/lib/compilers/coffee.js +++ b/lib/compilers/coffee.js @@ -1,11 +1,10 @@ -var options = require('./options') var ensureRequire = require('../ensure-require.js') -module.exports = function (raw, cb) { +module.exports = function (raw, cb, compiler) { ensureRequire('coffee', ['coffee-script']) var coffee = require('coffee-script') try { - var js = coffee.compile(raw, options.coffee || { + var js = coffee.compile(raw, compiler.options.coffee || { bare: true }) } catch (err) { diff --git a/lib/compilers/jade.js b/lib/compilers/jade.js index 021e81f..1539816 100644 --- a/lib/compilers/jade.js +++ b/lib/compilers/jade.js @@ -1,11 +1,10 @@ -var options = require('./options') var ensureRequire = require('../ensure-require.js') -module.exports = function (raw, cb) { +module.exports = function (raw, cb, compiler) { ensureRequire('jade', 'jade') var jade = require('jade') try { - var html = jade.compile(raw, options.jade || {})() + var html = jade.compile(raw, compiler.options.jade || {})() } catch (err) { return cb(err) } diff --git a/lib/compilers/less.js b/lib/compilers/less.js index b9d5335..487777d 100644 --- a/lib/compilers/less.js +++ b/lib/compilers/less.js @@ -1,4 +1,3 @@ -var options = require('./options') var assign = require('object-assign') var path = require('path') var ensureRequire = require('../ensure-require.js') @@ -9,7 +8,7 @@ module.exports = function (raw, cb, compiler, filePath) { var opts = assign({ filename: path.basename(filePath) - }, options.less) + }, compiler.options.less) // provide import path var dir = path.dirname(filePath) diff --git a/lib/compilers/options.js b/lib/compilers/options.js deleted file mode 100644 index 4ba52ba..0000000 --- a/lib/compilers/options.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = {} diff --git a/lib/compilers/pug.js b/lib/compilers/pug.js index 7ed9d20..5740b0c 100644 --- a/lib/compilers/pug.js +++ b/lib/compilers/pug.js @@ -1,11 +1,10 @@ -var options = require('./options') var ensureRequire = require('../ensure-require.js') -module.exports = function (raw, cb) { +module.exports = function (raw, cb, compiler) { ensureRequire('pug', 'pug') var pug = require('pug') try { - var html = pug.compile(raw, options.pug || {})() + var html = pug.compile(raw, compiler.options.pug || {})() } catch (err) { return cb(err) } diff --git a/lib/compilers/sass.js b/lib/compilers/sass.js index 4a825c4..f7a8c89 100644 --- a/lib/compilers/sass.js +++ b/lib/compilers/sass.js @@ -1,4 +1,3 @@ -var options = require('./options') var assign = require('object-assign') var path = require('path') var ensureRequire = require('../ensure-require.js') @@ -19,7 +18,7 @@ module.exports = function (raw, cb, compiler, filePath) { error: function (err) { cb(err) } - }, options.sass || { + }, compiler.options.sass || { sourceComments: true }) diff --git a/lib/compilers/stylus.js b/lib/compilers/stylus.js index c63d174..c099ba6 100644 --- a/lib/compilers/stylus.js +++ b/lib/compilers/stylus.js @@ -1,4 +1,3 @@ -var options = require('./options') var assign = require('object-assign') var path = require('path') var ensureRequire = require('../ensure-require.js') @@ -9,7 +8,7 @@ module.exports = function (raw, cb, compiler, filePath) { var opts = assign({ filename: path.basename(filePath) - }, options.stylus || {}) + }, compiler.options.stylus || {}) var dir = path.dirname(filePath) var paths = [dir, process.cwd()] diff --git a/lib/style-rewriter.js b/lib/style-rewriter.js index 17a0250..9881524 100644 --- a/lib/style-rewriter.js +++ b/lib/style-rewriter.js @@ -2,7 +2,6 @@ var postcss = require('postcss') var selectorParser = require('postcss-selector-parser') var cache = require('lru-cache')(100) var assign = require('object-assign') -var options = require('./compilers/options') var currentId var addId = postcss.plugin('add-id', function () { @@ -36,10 +35,11 @@ var addId = postcss.plugin('add-id', function () { * @param {String} id * @param {String} css * @param {Boolean} scoped + * @param {Object} options * @return {Promise} */ -module.exports = function (id, css, scoped) { +module.exports = function (id, css, scoped, options) { var key = id + '!!' + css var val = cache.get(key) if (val) { diff --git a/plugins/extract-css.js b/plugins/extract-css.js index c0d7122..6b05bd7 100644 --- a/plugins/extract-css.js +++ b/plugins/extract-css.js @@ -1,6 +1,7 @@ -process.env.VUEIFY_EXTRACT_CSS = true - var fs = require('fs') +var compiler = require('../lib/compiler') + +compiler.options.extractCSS = true module.exports = function (b, opts) { var outPath = opts.out || opts.o || 'bundle.css' From beedf571f435ee0f4e3ca3531164ab4fb6b73088 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sat, 18 Jun 2016 22:13:24 -0400 Subject: [PATCH 08/43] add source map support --- index.js | 3 ++ lib/compiler.js | 66 +++++++++++++++++++++++++++++++++++++---- lib/compilers/babel.js | 11 +++++-- lib/compilers/coffee.js | 14 +++++++-- package.json | 2 ++ plugins/extract-css.js | 4 ++- 6 files changed, 87 insertions(+), 13 deletions(-) diff --git a/index.js b/index.js index f072524..c717627 100644 --- a/index.js +++ b/index.js @@ -8,6 +8,9 @@ compiler.loadConfig({ module.exports = function vueify (file, options) { if (!/.vue$/.test(file)) return through() compiler.applyConfig(options) + compiler.applyConfig({ + sourceMap: options._flags.debug + }) var data = '' var stream = through(write, end) diff --git a/lib/compiler.js b/lib/compiler.js index aa55d7e..181cef5 100644 --- a/lib/compiler.js +++ b/lib/compiler.js @@ -5,12 +5,18 @@ var hash = require('hash-sum') var assign = require('object-assign') var Emitter = require('events').EventEmitter var vueCompiler = require('vue-template-compiler') +var sourceMap = require('source-map') +var convert = require('convert-source-map') var genId = require('./gen-id') var normalize = require('./normalize') var compilers = require('./compilers') var rewriteStyle = require('./style-rewriter') +// determine dynamic script paths +var hotReloadAPIPath = 'vue-hot-reload-api' //normalize.dep('vue-hot-reload-api') +var insertCSSPath = normalize.lib('insert-css') + var hasBabel = true try { require('babel-core') @@ -18,12 +24,9 @@ try { hasBabel = false } +var splitRE = /\r?\n/g var resolvedPartsCache = Object.create(null) -// determine dynamic script paths -var hotReloadAPIPath = 'vue-hot-reload-api' //normalize.dep('vue-hot-reload-api') -var insertCSSPath = normalize.lib('insert-css') - // expose compiler var compiler = module.exports = new Emitter() compiler.setMaxListeners(Infinity) @@ -90,6 +93,7 @@ compiler.compile = function (content, filePath, cb) { var templateChanged = resolvedParts.template !== prevParts.template var output = '' + var map = null // styles var style = resolvedParts.styles.join('\n') if (style) { @@ -107,8 +111,11 @@ compiler.compile = function (content, filePath, cb) { // script var script = resolvedParts.script if (script) { + if (options.sourceMap) { + map = generateSourceMap(script, output) + } output += - ';(function(){' + script + '})()\n' + + ';(function(){\n' + script + '\n})()\n' + // babel 6 compat 'if (module.exports.__esModule) module.exports = module.exports.default\n' } @@ -153,8 +160,46 @@ compiler.compile = function (content, filePath, cb) { ' }\n' + '})()}' } + if (map) { + output += '\n' + convert.fromJSON(map.toString()).toComment() + } cb(null, output) } + + function generateSourceMap (script, output) { + // hot-reload source map busting + var hashedFilename = path.basename(filePath) + '?' + hash(filePath + content) + var map = new sourceMap.SourceMapGenerator() + map.setSourceContent(hashedFilename, content) + // check input source map from babel/coffee etc + var inMap = resolvedParts.map + var inMapConsumer = inMap && new sourceMap.SourceMapConsumer(inMap) + var generatedOffset = (output ? output.split(splitRE).length : 0) + 1 + var originalOffset = content.slice(0, parts.script.start).split(splitRE).length - 1 + script.split(splitRE).forEach(function (line, index) { + var ln = index + 1 + var originalLine = inMapConsumer + ? inMapConsumer.originalPositionFor({ + line: ln, + column: 0 + }).line + : ln + if (originalLine) { + map.addMapping({ + source: hashedFilename, + generated: { + line: ln + generatedOffset, + column: 0 + }, + original: { + line: originalLine + originalOffset, + column: 0 + } + }) + } + }) + return map + } } function processTemplate (part, filePath, parts) { @@ -183,7 +228,12 @@ function processScript (part, filePath, parts) { var script = getContent(part, filePath) return compileAsPromise('script', script, lang, filePath) .then(function (res) { - parts.script = res + if (typeof res === 'string') { + parts.script = res + } else { + parts.script = res.code + parts.map = res.map + } }) } @@ -242,3 +292,7 @@ function compileAsPromise (type, source, lang, filePath) { function toFunction (code) { return 'function(){' + code + '}' } + +function generateSourceMap (script, output, content, parts) { + +} diff --git a/lib/compilers/babel.js b/lib/compilers/babel.js index 742465b..57a676b 100644 --- a/lib/compilers/babel.js +++ b/lib/compilers/babel.js @@ -1,5 +1,6 @@ var fs = require('fs') var path = require('path') +var assign = require('object-assign') var ensureRequire = require('../ensure-require') var defaultBabelOptions = { @@ -35,12 +36,16 @@ if (babelOptions === defaultBabelOptions) { } } -module.exports = function (raw, cb, compiler) { +module.exports = function (raw, cb, compiler, filePath) { try { var babel = require('babel-core') - var res = babel.transform(raw, compiler.options.babel || babelOptions) + var options = assign({ + filename: filePath, + sourceMaps: compiler.options.sourceMap + }, compiler.options.babel || babelOptions) + var res = babel.transform(raw, options) } catch (err) { return cb(err) } - cb(null, res.code) + cb(null, res) } diff --git a/lib/compilers/coffee.js b/lib/compilers/coffee.js index d0238e1..f96b70c 100644 --- a/lib/compilers/coffee.js +++ b/lib/compilers/coffee.js @@ -3,12 +3,20 @@ var ensureRequire = require('../ensure-require.js') module.exports = function (raw, cb, compiler) { ensureRequire('coffee', ['coffee-script']) var coffee = require('coffee-script') + var compiled try { - var js = coffee.compile(raw, compiler.options.coffee || { - bare: true + compiled = coffee.compile(raw, compiler.options.coffee || { + bare: true, + sourceMap: compiler.options.sourceMap }) } catch (err) { return cb(err) } - cb(null, js) + if (compiler.options.sourceMap) { + compiled = { + code: compiled.js, + map: compiled.v3SourceMap + } + } + cb(null, compiled) } diff --git a/package.json b/package.json index 0fe586c..4eb6f3e 100644 --- a/package.json +++ b/package.json @@ -22,12 +22,14 @@ "homepage": "https://github.com/vuejs/vueify", "dependencies": { "chalk": "^1.1.1", + "convert-source-map": "^1.2.0", "cssnano": "^3.3.2", "hash-sum": "^1.0.2", "lru-cache": "^4.0.0", "object-assign": "^4.0.1", "postcss": "^5.0.10", "postcss-selector-parser": "^2.0.0", + "source-map": "^0.5.6", "through": "^2.3.6", "vue-hot-reload-api": "^2.0.1", "vue-template-compiler": "^2.0.0-alpha.3" diff --git a/plugins/extract-css.js b/plugins/extract-css.js index 6b05bd7..6f4e649 100644 --- a/plugins/extract-css.js +++ b/plugins/extract-css.js @@ -1,7 +1,9 @@ var fs = require('fs') var compiler = require('../lib/compiler') -compiler.options.extractCSS = true +compiler.applyConfig({ + extractCSS: true +}) module.exports = function (b, opts) { var outPath = opts.out || opts.o || 'bundle.css' From 2e7a2f13bcc6223d85392a8a575a19fae9352b6d Mon Sep 17 00:00:00 2001 From: Evan You Date: Sat, 18 Jun 2016 22:13:37 -0400 Subject: [PATCH 09/43] remove unused --- lib/compiler.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/compiler.js b/lib/compiler.js index 181cef5..2b26766 100644 --- a/lib/compiler.js +++ b/lib/compiler.js @@ -292,7 +292,3 @@ function compileAsPromise (type, source, lang, filePath) { function toFunction (code) { return 'function(){' + code + '}' } - -function generateSourceMap (script, output, content, parts) { - -} From b0621f9ae1f611c3573bf901a5dba52fa12b22fc Mon Sep 17 00:00:00 2001 From: Evan You Date: Sat, 18 Jun 2016 22:24:04 -0400 Subject: [PATCH 10/43] pad output --- lib/compiler.js | 6 +++--- lib/compilers/babel.js | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/compiler.js b/lib/compiler.js index 2b26766..6206803 100644 --- a/lib/compiler.js +++ b/lib/compiler.js @@ -63,7 +63,7 @@ compiler.compile = function (content, filePath, cb) { // generate css scope id var id = 'data-v-' + genId(filePath) // parse the component into parts - var parts = vueCompiler.parseComponent(content) + var parts = vueCompiler.parseComponent(content, { pad: true }) // check for scoped style nodes var hasScopedStyle = parts.styles.some(function (style) { @@ -175,7 +175,6 @@ compiler.compile = function (content, filePath, cb) { var inMap = resolvedParts.map var inMapConsumer = inMap && new sourceMap.SourceMapConsumer(inMap) var generatedOffset = (output ? output.split(splitRE).length : 0) + 1 - var originalOffset = content.slice(0, parts.script.start).split(splitRE).length - 1 script.split(splitRE).forEach(function (line, index) { var ln = index + 1 var originalLine = inMapConsumer @@ -192,7 +191,7 @@ compiler.compile = function (content, filePath, cb) { column: 0 }, original: { - line: originalLine + originalOffset, + line: originalLine, column: 0 } }) @@ -241,6 +240,7 @@ function processStyle (part, filePath, id, parts) { var style = getContent(part, filePath) return compileAsPromise('style', style, part.lang, filePath) .then(function (res) { + res = res.trim() return rewriteStyle(id, res, part.scoped, options).then(function (res) { parts.styles.push(res) }) diff --git a/lib/compilers/babel.js b/lib/compilers/babel.js index 57a676b..d999bfa 100644 --- a/lib/compilers/babel.js +++ b/lib/compilers/babel.js @@ -40,6 +40,7 @@ module.exports = function (raw, cb, compiler, filePath) { try { var babel = require('babel-core') var options = assign({ + comments: false, filename: filePath, sourceMaps: compiler.options.sourceMap }, compiler.options.babel || babelOptions) From 8350490ea6387c030d2e53b5d81218444b77c9cb Mon Sep 17 00:00:00 2001 From: Evan You Date: Sat, 18 Jun 2016 23:32:47 -0400 Subject: [PATCH 11/43] update readme --- README.md | 87 ++++++++++++++++--------------------------------------- 1 file changed, 25 insertions(+), 62 deletions(-) diff --git a/README.md b/README.md index 41f9f4e..25eb4b7 100644 --- a/README.md +++ b/README.md @@ -67,17 +67,6 @@ 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: - -``` bash -npm install\ - babel-core\ - babel-preset-es2015\ - babel-runtime\ - babel-plugin-transform-runtime\ - --save-dev -``` - And this is all you need to do in your main entry file: ``` js @@ -86,9 +75,9 @@ var Vue = require('vue') var App = require('./app.vue') new Vue({ - el: 'body', - components: { - app: App + el: '#app', + render: function (createElement) { + return createElement(App) } }) ``` @@ -97,7 +86,7 @@ In your HTML: ``` html - +
``` @@ -121,35 +110,34 @@ 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 - -Vueify automatically transforms the JavaScript in your `*.vue` components using Babel. Write ES2015 today! +## ES2015 with Babel -The default Babel (6) options used for Vue.js components are: +Vueify is pre-configured to work with Babel. Simply install Babel-related dependencies: -``` js -{ - "presets": ["es2015"], - "plugins": ["transform-runtime"] -} +``` bash +npm install\ + babel-core\ + babel-preset-es2015\ + --save-dev ``` -If you wish to override this, you can add a `.babelrc` file at the root of your project: +Then create a `.babelrc`: ``` json { - "presets": ["es2015", "stage-2"], - "plugins": ["transform-runtime"] + "presets": ["es2015"] } ``` +And voila! You can now write ES2015 in your `*.vue` files. Note if you want to use ES2015 on normal `*.js` files, you will also need [babelify](https://github.com/babel/babelify). + You can also configure babel with the `babel` field in `vue.config.js`, which will take the highest priority. -## Enabling Pre-Processors +## Enabling Other Pre-Processors -You need to install the corresponding node modules to enable the compilation. e.g. to get stylus compiled in your Vue components, do `npm install stylus --save-dev`. +For other pre-processors, you also need to install the corresponding node modules to enable the compilation. e.g. to get stylus compiled in your Vue components, do `npm install stylus --save-dev`. -These are the built-in preprocessors: +These are the preprocessors supported by vueify out of the box: - stylus - less @@ -158,13 +146,9 @@ These are the built-in preprocessors: - pug - coffee-script (use `coffee` in [config section](#configuring-options)) -## Autoprefix by Default - -Starting in 5.0.0, all CSS output via vueify will be autoprefixed by default. See [config section](#configuring-options) below on customizing the options. - ## PostCSS -Vueify uses PostCSS for scoped CSS rewrite and autoprefixing. You can also provide your own PostCSS plugins! See [config section](#configuring-options) below for an example. +Vueify uses PostCSS for scoped CSS rewrite. You can also provide your own PostCSS plugins! See [config section](#configuring-options) below for an example. ## Configuring Options @@ -178,15 +162,6 @@ module.exports = { }, // provide your own postcss plugins postcss: [...], - // configure autoprefixer - autoprefixer: { - browsers: ['last 2 versions'] - }, - // configure html minification in production mode - // see https://github.com/kangax/html-minifier#options-quick-reference - htmlMinifier: { - // ... - }, // register custom compilers customCompilers: { // for tags with lang="ts" @@ -209,9 +184,7 @@ Example using custom PostCSS plugin: var cssnext = require('cssnext') module.exports = { - postcss: [cssnext()], - // disable autoprefixer since cssnext comes with it - autoprefixer: false + postcss: [cssnext()] } ``` @@ -253,8 +226,6 @@ browserify('./main.js') ### Scoped CSS -> Experimental - When a ` diff --git a/test/test.js b/test/test.js index 5081c87..69d3e4b 100644 --- a/test/test.js +++ b/test/test.js @@ -3,7 +3,6 @@ process.env.VUEIFY_TEST = true const fs = require('fs') const path = require('path') const expect = require('chai').expect -const hash = require('hash-sum') const rimraf = require('rimraf') const mkdirp = require('mkdirp') const browserify = require('browserify') @@ -37,6 +36,18 @@ function test (file, assert) { }) } +function testCssExtract (file, assert) { + it(file, done => { + fs.writeFileSync(mockEntry, 'window.vueModule = require("../fixtures/' + file + '.vue")') + browserify(mockEntry) + .transform(vueify) + .plugin('./plugins/extract-css', { out: { write: assert, end: done }}) + .bundle((err, buf) => { + if (err) return done(err) + }) + }) +} + function assertRenderFn (options, template) { const compiled = vueCompiler.compile(template) expect(options.render.toString()).to.equal('function (){' + compiled.render + '}') @@ -122,4 +133,8 @@ describe('vueify', () => { var id = 'data-v-' + genId(require.resolve('./fixtures/media-query.vue')) expect(style).to.contain('@media print {\n .foo[' + id + '] {\n color: #000;\n }\n}') }) + + testCssExtract('style-export', css => { + expect(css).to.equal('h2 {color: red;}') + }) }) From 1b2659a1f87b8a8878135477641e00fd45ee42c2 Mon Sep 17 00:00:00 2001 From: Darius Tall Date: Fri, 24 Jun 2016 10:25:08 -0400 Subject: [PATCH 17/43] Add the ability to specify other postcss options (#99) * Add the ability to specify other postcss options * Fixed usage of postcss --- lib/style-rewriter.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/style-rewriter.js b/lib/style-rewriter.js index 9881524..c631857 100644 --- a/lib/style-rewriter.js +++ b/lib/style-rewriter.js @@ -45,9 +45,16 @@ module.exports = function (id, css, scoped, options) { 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) @@ -60,10 +67,11 @@ module.exports = function (id, css, scoped, options) { } currentId = id return postcss(plugins) - .process(css) + .process(css, opts) .then(function (res) { cache.set(key, res.css) return res.css }) } } + From 34ccdd5bc32aa78a6f26ae6f67677d2418a3efd2 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 24 Jun 2016 10:26:57 -0400 Subject: [PATCH 18/43] 9.2.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ecd6cb9..44c4723 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vueify", - "version": "9.1.0", + "version": "9.2.0", "description": "Vue component transform for Browserify", "main": "index.js", "repository": { From ab3866334c58d4256c802b7cf8ae3b67b5e65504 Mon Sep 17 00:00:00 2001 From: Evan You Date: Tue, 28 Jun 2016 15:05:43 -0400 Subject: [PATCH 19/43] add functional component warning --- lib/compiler.js | 7 +++++++ package.json | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/compiler.js b/lib/compiler.js index 4bf8f50..7fb0e2c 100644 --- a/lib/compiler.js +++ b/lib/compiler.js @@ -126,6 +126,13 @@ compiler.compile = function (content, filePath, cb) { // template var template = resolvedParts.template if (template) { + if (process.env.NODE_ENV !== 'production') { + output += + 'if (__vue__options__.functional) {console.error("' + + '[vueify] functional components are not supported and ' + + 'should be defined in plain js files using render functions.' + + '")}\n' + } output += '__vue__options__.render = ' + template.render + '\n' + '__vue__options__.staticRenderFns = ' + template.staticRenderFns + '\n' diff --git a/package.json b/package.json index 44c4723..3e65649 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "source-map": "^0.5.6", "through": "^2.3.6", "vue-hot-reload-api": "^2.0.1", - "vue-template-compiler": "^2.0.0-alpha.3" + "vue-template-compiler": "^2.0.0-alpha.8" }, "devDependencies": { "babel-core": "^6.0.0", From dc6de0be8a2854fb91a0b198f7e540bc03e159fa Mon Sep 17 00:00:00 2001 From: Evan You Date: Tue, 28 Jun 2016 15:05:48 -0400 Subject: [PATCH 20/43] 9.2.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3e65649..291f3c8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vueify", - "version": "9.2.0", + "version": "9.2.1", "description": "Vue component transform for Browserify", "main": "index.js", "repository": { From cda407d2b69fe543f5225639118dbb738b478eb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=BDiga=20Vidic?= Date: Wed, 29 Jun 2016 18:43:44 -0700 Subject: [PATCH 21/43] Don't make .babelrc a requirement. (#103) * Don't make .babelrc a requirement. If you don't have a .babelrc file in your project you still get babel warning: "You are trying to use "babel". babel-preset-es2015, babel-runtime and babel-plugin-transform-runtime are missing." * Move only comparison to exported function. --- lib/compilers/babel.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/compilers/babel.js b/lib/compilers/babel.js index d999bfa..d237ed6 100644 --- a/lib/compilers/babel.js +++ b/lib/compilers/babel.js @@ -23,20 +23,20 @@ function getBabelRc () { return rc } -if (babelOptions === defaultBabelOptions) { - try { - ensureRequire('babel', ['babel-preset-es2015', 'babel-runtime', 'babel-plugin-transform-runtime']) - } catch (e) { - console.error(e.message) - console.error( - '\n^^^ You are seeing this because you are using Vueify\'s default babel ' + - 'configuration. You can override this with .babelrc or the babel option ' + - 'in vue.config.js.' - ) +module.exports = function (raw, cb, compiler, filePath) { + if (babelOptions === defaultBabelOptions) { + try { + ensureRequire('babel', ['babel-preset-es2015', 'babel-runtime', 'babel-plugin-transform-runtime']) + } catch (e) { + console.error(e.message) + console.error( + '\n^^^ You are seeing this because you are using Vueify\'s default babel ' + + 'configuration. You can override this with .babelrc or the babel option ' + + 'in vue.config.js.' + ) + } } -} -module.exports = function (raw, cb, compiler, filePath) { try { var babel = require('babel-core') var options = assign({ From 8c5e9ed3f992a16fcb82c8c86522eebc01399f02 Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 29 Jun 2016 21:45:16 -0400 Subject: [PATCH 22/43] 9.2.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 291f3c8..5be8f1a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vueify", - "version": "9.2.1", + "version": "9.2.2", "description": "Vue component transform for Browserify", "main": "index.js", "repository": { From 68694e9d94f3537af243eb8bd30e878f4bd89114 Mon Sep 17 00:00:00 2001 From: Evan You Date: Thu, 30 Jun 2016 10:27:21 -0400 Subject: [PATCH 23/43] add a note about building for production --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 66fa388..949599a 100644 --- a/README.md +++ b/README.md @@ -294,6 +294,14 @@ browserify('./main.js') This only works for vueify 9+. For Vue 1.x / vueify 8.x you can use [vueify-extract-css](https://github.com/rawcreative/vueify-extract-css). +## Building for Production + +When building for production, follow these steps to ensure smaller bundle size: + +1. Make sure `process.env.NODE_ENV === "production"`. This tells `vueify` to avoid including hot-reload related code. + +2. Apply a global [envify](https://github.com/hughsk/envify) transform to your bundle. This allows the minifier to strip out all the warnings in Vue's source code wrapped in env variable conditional blocks. + ## Compiler API The compiler API (originally `vue-component-compiler`) is also exposed: From 8550260612de4338714802fd014cc5f7dfc84dbf Mon Sep 17 00:00:00 2001 From: Evan You Date: Thu, 30 Jun 2016 10:33:53 -0400 Subject: [PATCH 24/43] skip css and hot-reload in server mode --- lib/compiler.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/compiler.js b/lib/compiler.js index 7fb0e2c..d743004 100644 --- a/lib/compiler.js +++ b/lib/compiler.js @@ -60,6 +60,10 @@ compiler.applyConfig = function (config) { } compiler.compile = function (content, filePath, cb) { + var isProduction = process.env.NODE_ENV === 'production' + var isServer = process.env.VUE_ENV === 'server' + var isTest = !!process.env.VUEIFY_TEST + // generate css scope id var id = 'data-v-' + genId(filePath) // parse the component into parts @@ -96,7 +100,7 @@ compiler.compile = function (content, filePath, cb) { var map = null // styles var style = resolvedParts.styles.join('\n') - if (style) { + if (style && !isServer) { // emit style compiler.emit('style', { file: filePath, @@ -126,7 +130,7 @@ compiler.compile = function (content, filePath, cb) { // template var template = resolvedParts.template if (template) { - if (process.env.NODE_ENV !== 'production') { + if (!isProduction && !isServer) { output += 'if (__vue__options__.functional) {console.error("' + '[vueify] functional components are not supported and ' + @@ -142,7 +146,7 @@ compiler.compile = function (content, filePath, cb) { output += '__vue__options__._scopeId = "' + id + '"\n' } // hot reload - if (process.env.NODE_ENV !== 'production' && !process.env.VUEIFY_TEST) { + if (!isProduction && !isTest && !isServer) { output += 'if (module.hot) {(function () {' + ' var hotAPI = require("' + hotReloadAPIPath + '")\n' + From b527242e57aaeda6a19f6a5ad0823eb11ccd2ae6 Mon Sep 17 00:00:00 2001 From: Evan You Date: Thu, 30 Jun 2016 10:33:59 -0400 Subject: [PATCH 25/43] 9.2.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5be8f1a..d012e33 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vueify", - "version": "9.2.2", + "version": "9.2.3", "description": "Vue component transform for Browserify", "main": "index.js", "repository": { From bd6c09400b36741f3c7f05cc0156e4b9bd493bd5 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 15 Jul 2016 18:25:59 -0400 Subject: [PATCH 26/43] map all render errors to the template --- lib/compiler.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/lib/compiler.js b/lib/compiler.js index d743004..cde3d99 100644 --- a/lib/compiler.js +++ b/lib/compiler.js @@ -137,9 +137,16 @@ compiler.compile = function (content, filePath, cb) { 'should be defined in plain js files using render functions.' + '")}\n' } + var beforeLines + if (map) { + beforeLines = output.split(splitRE).length + } output += '__vue__options__.render = ' + template.render + '\n' + '__vue__options__.staticRenderFns = ' + template.staticRenderFns + '\n' + if (map) { + addTemplateMapping(content, parts, output, map, beforeLines) + } } // scoped CSS id if (hasScopedStyle) { @@ -205,10 +212,29 @@ compiler.compile = function (content, filePath, cb) { }) } }) + map._hashedFilename = hashedFilename return map } } +function addTemplateMapping (content, parts, output, map, beforeLines) { + var afterLines = output.split(splitRE).length + var templateLine = content.slice(0, parts.template.start).split(splitRE).length + for (; beforeLines < afterLines; beforeLines++) { + map.addMapping({ + source: map._hashedFilename, + generated: { + line: beforeLines, + column: 0 + }, + original: { + line: templateLine, + column: 0 + } + }) + } +} + function processTemplate (part, filePath, parts) { if (!part) return Promise.resolve() var template = getContent(part, filePath) From a3465bb9d6bc695b0f70ba8f096d4c95c033d3cb Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 15 Jul 2016 18:26:03 -0400 Subject: [PATCH 27/43] 9.2.4 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d012e33..cc3bbde 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vueify", - "version": "9.2.3", + "version": "9.2.4", "description": "Vue component transform for Browserify", "main": "index.js", "repository": { From 62236436086e0d2fc76caf608b9c4f25540970ca Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 28 Sep 2016 19:13:20 -0400 Subject: [PATCH 28/43] add version notice --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 949599a..809c89e 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ > [Browserify](http://browserify.org/) transform for [Vue.js](http://vuejs.org/) components, with scoped CSS and component hot-reloading. +**NOTE: master branch now hosts version ^9.0, which only works with Vue ^2.0. Vueify 8.x which works with Vue 1.x is in the [8.x branch](https://github.com/vuejs/vueify/tree/8.x).** + This transform allows you to write your components in this format: ``` html From 9ce0fb10af26b108317c5913ee4549445cff7b0e Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 28 Sep 2016 20:12:53 -0400 Subject: [PATCH 29/43] fix dep --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index cc3bbde..1d8e9a6 100644 --- a/package.json +++ b/package.json @@ -44,6 +44,7 @@ "coffee-script": "^1.10.0", "eslint": "^2.13.0", "eslint-config-vue": "^1.0.3", + "eslint-plugin-html": "^1.5.3", "jade": "^1.11.0", "jsdom": "^9.2.1", "less": "^2.5.1", From fa235bd345779e52d7697c476de9a4393bc394e1 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sat, 12 Nov 2016 11:07:12 -0500 Subject: [PATCH 30/43] include vue-template-es2015-compiler --- lib/template-compiler.js | 3 ++- package.json | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/template-compiler.js b/lib/template-compiler.js index 3824c37..51314b9 100644 --- a/lib/template-compiler.js +++ b/lib/template-compiler.js @@ -1,5 +1,6 @@ var chalk = require('chalk') var vueCompiler = require('vue-template-compiler') +var transpile = require('vue-template-es2015-compiler') module.exports = function compileTemplate (template, compiler) { var compiled = vueCompiler.compile(template) @@ -17,5 +18,5 @@ module.exports = function compileTemplate (template, compiler) { } function toFunction (code) { - return 'function(){' + code + '}' + return transpile('function render () {' + code + '}') } diff --git a/package.json b/package.json index 1d8e9a6..db1dfae 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,8 @@ "source-map": "^0.5.6", "through": "^2.3.6", "vue-hot-reload-api": "^2.0.1", - "vue-template-compiler": "^2.0.0-alpha.8" + "vue-template-compiler": "^2.0.0-alpha.8", + "vue-template-es2015-compiler": "^1.2.2" }, "devDependencies": { "babel-core": "^6.0.0", From 97741fde0f6099ece99a07a6ef39d4283637642f Mon Sep 17 00:00:00 2001 From: Evan You Date: Sat, 12 Nov 2016 11:09:32 -0500 Subject: [PATCH 31/43] fix tests --- test/test.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/test.js b/test/test.js index 69d3e4b..dfcf92a 100644 --- a/test/test.js +++ b/test/test.js @@ -9,6 +9,7 @@ const browserify = require('browserify') const vueify = require('../index') const jsdom = require('jsdom') const vueCompiler = require('vue-template-compiler') +const transpile = require('vue-template-es2015-compiler') const genId = require('../lib/gen-id') const tempDir = path.resolve(__dirname, './temp') @@ -50,7 +51,7 @@ function testCssExtract (file, assert) { function assertRenderFn (options, template) { const compiled = vueCompiler.compile(template) - expect(options.render.toString()).to.equal('function (){' + compiled.render + '}') + expect(options.render.toString()).to.equal(transpile('function render() {' + compiled.render + '}')) } describe('vueify', () => { From 357f5818ccd968e98dfedfc6fb6b8a37726a0cdc Mon Sep 17 00:00:00 2001 From: Evan You Date: Sat, 12 Nov 2016 11:10:02 -0500 Subject: [PATCH 32/43] 9.3.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index db1dfae..4e0796a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vueify", - "version": "9.2.4", + "version": "9.3.0", "description": "Vue component transform for Browserify", "main": "index.js", "repository": { From 4e9eea85edd75dae080060ef7e9c693079c8b24c Mon Sep 17 00:00:00 2001 From: Adam Niederer Date: Thu, 8 Dec 2016 15:05:47 -0500 Subject: [PATCH 33/43] Load configuration from vue.config.js (#146) Resolves #116 and #145 --- index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/index.js b/index.js index 1bb2933..d789a83 100644 --- a/index.js +++ b/index.js @@ -6,6 +6,7 @@ module.exports = function vueify (file, options) { return through() } + compiler.loadConfig() compiler.applyConfig(options) compiler.applyConfig({ sourceMap: options._flags.debug From f77be6258c6fc47e8bd1af69c5724a179c8c1ab9 Mon Sep 17 00:00:00 2001 From: Mike Date: Thu, 8 Dec 2016 15:06:15 -0500 Subject: [PATCH 34/43] Fixed Node deprecated warning (#163) --- plugins/extract-css.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/extract-css.js b/plugins/extract-css.js index 740bb80..1b83eb6 100644 --- a/plugins/extract-css.js +++ b/plugins/extract-css.js @@ -18,7 +18,7 @@ module.exports = function (b, opts) { outPath.write(css) outPath.end() } else if (typeof outPath === 'string') { - fs.writeFile(outPath, css) + fs.writeFile(outPath, css, function () {}) } }) }) From 620e90e44ad779355fcd1150305fbcd3676e5567 Mon Sep 17 00:00:00 2001 From: Daniel Diekmeier Date: Thu, 8 Dec 2016 21:06:27 +0100 Subject: [PATCH 35/43] Fix link to browserify-simple (#155) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 809c89e..e55b78c 100644 --- a/README.md +++ b/README.md @@ -271,7 +271,7 @@ npm install browserify-hmr --save-dev watchify -p browserify-hmr index.js -o bundle.js ``` -You can scaffold a hot-reload enabled project easily using `vue-cli` and the [this template](https://github.com/vuejs-templates/browserify-simple-2.0). +You can scaffold a hot-reload enabled project easily using `vue-cli` and the [this template](https://github.com/vuejs-templates/browserify-simple). ## CSS Extraction From f25fb22856b762ca0eb0b82f49810fb55165dcae Mon Sep 17 00:00:00 2001 From: Daniel Diekmeier Date: Thu, 8 Dec 2016 21:08:49 +0100 Subject: [PATCH 36/43] Fix errors with scoped modules (#154) --- lib/style-rewriter.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/style-rewriter.js b/lib/style-rewriter.js index c631857..1195799 100644 --- a/lib/style-rewriter.js +++ b/lib/style-rewriter.js @@ -40,7 +40,7 @@ var addId = postcss.plugin('add-id', function () { */ module.exports = function (id, css, scoped, options) { - var key = id + '!!' + css + var key = id + '!!' + scoped + '!!' + css var val = cache.get(key) if (val) { return Promise.resolve(val) @@ -56,9 +56,16 @@ module.exports = function (id, css, scoped, options) { } // scoped css rewrite - if (scoped) { + // make sure the addId plugin is only pushed once + if (scoped && plugins.indexOf(addId) === -1) { plugins.push(addId) } + + // remove the addId plugin if the style block is not scoped + if (!scoped && plugins.indexOf(addId) !== -1) { + plugins.splice(plugins.indexOf(addId), 1) + } + // minification if (process.env.NODE_ENV === 'production') { plugins.push(require('cssnano')(assign({ From 1c2dce72248b36869b4144207f16da2e28f170bd Mon Sep 17 00:00:00 2001 From: Jason Date: Fri, 9 Dec 2016 04:10:25 +0800 Subject: [PATCH 37/43] use hash-sum for module id generation (#160) --- lib/gen-id.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/gen-id.js b/lib/gen-id.js index 25281ae..8c9621d 100644 --- a/lib/gen-id.js +++ b/lib/gen-id.js @@ -1,8 +1,8 @@ // utility for generating a uid for each component file // used in scoped CSS rewriting -var fileUid = 1 -var fileRegistry = Object.create(null) +var hash = require('hash-sum') +var cache = Object.create(null) module.exports = function genId (file) { - return fileRegistry[file] || (fileRegistry[file] = fileUid++) + return cache[file] || (cache[file] = hash(file)) } From 79793efcbc8a33af2162bfee784e7aac5141065a Mon Sep 17 00:00:00 2001 From: Jason Date: Fri, 9 Dec 2016 04:11:28 +0800 Subject: [PATCH 38/43] Parse babelrc with json5 (#161) * Parse babelrc with json5 * Include json5 in package.json --- lib/compilers/babel.js | 3 ++- package.json | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/compilers/babel.js b/lib/compilers/babel.js index d237ed6..323b23d 100644 --- a/lib/compilers/babel.js +++ b/lib/compilers/babel.js @@ -1,5 +1,6 @@ var fs = require('fs') var path = require('path') +var json = require('json5') var assign = require('object-assign') var ensureRequire = require('../ensure-require') @@ -16,7 +17,7 @@ var babelOptions = fs.existsSync(babelRcPath) function getBabelRc () { var rc try { - rc = JSON.parse(fs.readFileSync(babelRcPath, 'utf-8')) + rc = json.parse(fs.readFileSync(babelRcPath, 'utf-8')) } catch (e) { throw new Error('[vueify] Your .babelrc seems to be incorrectly formatted.') } diff --git a/package.json b/package.json index 4e0796a..8aaba5f 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ "postcss-selector-parser": "^2.0.0", "source-map": "^0.5.6", "through": "^2.3.6", + "json5": "^0.5.1", "vue-hot-reload-api": "^2.0.1", "vue-template-compiler": "^2.0.0-alpha.8", "vue-template-es2015-compiler": "^1.2.2" From 6c518d597385bab54d330482fd87835337626a85 Mon Sep 17 00:00:00 2001 From: Daniel Diekmeier Date: Thu, 8 Dec 2016 21:21:47 +0100 Subject: [PATCH 39/43] Remove listener leading to memory leak (#156) --- plugins/extract-css.js | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/plugins/extract-css.js b/plugins/extract-css.js index 1b83eb6..e3331e9 100644 --- a/plugins/extract-css.js +++ b/plugins/extract-css.js @@ -23,16 +23,11 @@ module.exports = function (b, opts) { }) }) - b.on('reset', listen) - listen() - - function listen () { - b.on('transform', function (tr, file) { - if (tr.vueify) { - tr.on('vueify-style', function (e) { - styles[e.file] = e.style - }) - } - }) - } + b.on('transform', function (tr, file) { + if (tr.vueify) { + tr.on('vueify-style', function (e) { + styles[e.file] = e.style + }) + } + }) } From 80e168ae34f9feee2eca5d76e386681442710753 Mon Sep 17 00:00:00 2001 From: Evan You Date: Thu, 8 Dec 2016 15:22:26 -0500 Subject: [PATCH 40/43] 9.4.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8aaba5f..c364b45 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vueify", - "version": "9.3.0", + "version": "9.4.0", "description": "Vue component transform for Browserify", "main": "index.js", "repository": { From 6992fc75de03b394d23b20983d08a6b81596a140 Mon Sep 17 00:00:00 2001 From: Toru Nagashima Date: Thu, 9 Mar 2017 11:42:31 +0900 Subject: [PATCH 41/43] Fix: invalid warning about babel (#183) --- lib/compilers/babel.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/compilers/babel.js b/lib/compilers/babel.js index 323b23d..be317b4 100644 --- a/lib/compilers/babel.js +++ b/lib/compilers/babel.js @@ -25,7 +25,7 @@ function getBabelRc () { } module.exports = function (raw, cb, compiler, filePath) { - if (babelOptions === defaultBabelOptions) { + if ((compiler.options.babel || babelOptions) === defaultBabelOptions) { try { ensureRequire('babel', ['babel-preset-es2015', 'babel-runtime', 'babel-plugin-transform-runtime']) } catch (e) { From 8d3159ff7d41bfaf1662056436a4252ea07219aa Mon Sep 17 00:00:00 2001 From: Evan You Date: Thu, 9 Mar 2017 10:42:56 +0800 Subject: [PATCH 42/43] 9.4.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c364b45..c1caee7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vueify", - "version": "9.4.0", + "version": "9.4.1", "description": "Vue component transform for Browserify", "main": "index.js", "repository": { From 0bcabf17b6c44cbe0e4c4ff85e3c79d22a853bd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20L=C3=BCnborg?= Date: Tue, 25 Dec 2018 23:58:40 +0100 Subject: [PATCH 43/43] Update README.md --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e55b78c..9a42c15 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,8 @@ -# vueify [![Build Status](https://circleci.com/gh/vuejs/vueify.svg?style=shield)](https://circleci.com/gh/vuejs/vueify) [![npm version](https://badge.fury.io/js/vueify.svg)](http://badge.fury.io/js/vueify) +# THIS REPOSITORY IS DEPRECATED + +> Note: We are concentrating our efforts on supporting webpack and rollup. + +## vueify [![Build Status](https://circleci.com/gh/vuejs/vueify.svg?style=shield)](https://circleci.com/gh/vuejs/vueify) [![npm version](https://badge.fury.io/js/vueify.svg)](http://badge.fury.io/js/vueify) > [Browserify](http://browserify.org/) transform for [Vue.js](http://vuejs.org/) components, with scoped CSS and component hot-reloading.