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

Style: Support for /deep/ and >>> combinator #198

Open
wants to merge 52 commits into
base: 8.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
aa0c205
drop promise polyfill
yyx990803 Jun 15, 2016
63b3f7b
support Vue 2.0
yyx990803 Jun 15, 2016
615dded
fix scoped CSS
yyx990803 Jun 15, 2016
15c99ed
better babel warning
yyx990803 Jun 15, 2016
3914e57
fix optional parts / strict mode
yyx990803 Jun 15, 2016
e5cb32a
new test setup
yyx990803 Jun 15, 2016
0ec591d
refactor tests
yyx990803 Jun 15, 2016
3301ec7
better template error warnings
yyx990803 Jun 15, 2016
8d60723
9.0.0
yyx990803 Jun 15, 2016
5909cb9
include mkdirp as dep
yyx990803 Jun 15, 2016
9666af2
move changelog into releases
yyx990803 Jun 15, 2016
b26e25b
simplify insert-css
yyx990803 Jun 16, 2016
34830f9
more granular hot-reload
yyx990803 Jun 16, 2016
daf4294
9.0.1
yyx990803 Jun 16, 2016
13291e2
support CSS extraction
yyx990803 Jun 18, 2016
a916805
refactor compiler options
yyx990803 Jun 19, 2016
beedf57
add source map support
yyx990803 Jun 19, 2016
2e7a2f1
remove unused
yyx990803 Jun 19, 2016
b0621f9
pad output
yyx990803 Jun 19, 2016
8350490
update readme
yyx990803 Jun 19, 2016
98ec0b2
eslint
yyx990803 Jun 19, 2016
5f1cf6a
add docs for css extraction
yyx990803 Jun 19, 2016
27a7e7a
support out stream for css extraction
yyx990803 Jun 19, 2016
d391b9f
9.1.0
yyx990803 Jun 19, 2016
1b05390
Test extract css (#101)
zigomir Jun 23, 2016
1b2659a
Add the ability to specify other postcss options (#99)
Jun 24, 2016
34ccdd5
9.2.0
yyx990803 Jun 24, 2016
ab38663
add functional component warning
yyx990803 Jun 28, 2016
dc6de0b
9.2.1
yyx990803 Jun 28, 2016
cda407d
Don't make .babelrc a requirement. (#103)
zigomir Jun 30, 2016
8c5e9ed
9.2.2
yyx990803 Jun 30, 2016
68694e9
add a note about building for production
yyx990803 Jun 30, 2016
8550260
skip css and hot-reload in server mode
yyx990803 Jun 30, 2016
b527242
9.2.3
yyx990803 Jun 30, 2016
bd6c094
map all render errors to the template
yyx990803 Jul 15, 2016
a3465bb
9.2.4
yyx990803 Jul 15, 2016
6223643
add version notice
yyx990803 Sep 28, 2016
9ce0fb1
fix dep
yyx990803 Sep 29, 2016
fa235bd
include vue-template-es2015-compiler
yyx990803 Nov 12, 2016
97741fd
fix tests
yyx990803 Nov 12, 2016
357f581
9.3.0
yyx990803 Nov 12, 2016
4e9eea8
Load configuration from vue.config.js (#146)
AdamNiederer Dec 8, 2016
f77be62
Fixed Node deprecated warning (#163)
mgrinspan Dec 8, 2016
620e90e
Fix link to browserify-simple (#155)
danieldiekmeier Dec 8, 2016
f25fb22
Fix errors with scoped modules (#154)
danieldiekmeier Dec 8, 2016
1c2dce7
use hash-sum for module id generation (#160)
gzzhanghao Dec 8, 2016
79793ef
Parse babelrc with json5 (#161)
gzzhanghao Dec 8, 2016
6c518d5
Remove listener leading to memory leak (#156)
danieldiekmeier Dec 8, 2016
80e168a
9.4.0
yyx990803 Dec 8, 2016
6992fc7
Fix: invalid warning about babel (#183)
mysticatea Mar 9, 2017
8d3159f
9.4.1
yyx990803 Mar 9, 2017
0bcabf1
Update README.md
LinusBorg Dec 25, 2018
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
Prev Previous commit
Next Next commit
new test setup
  • Loading branch information
yyx990803 committed Jun 15, 2016
commit e5cb32a015f506ea5df0e07bcb64ae2d51d0801c
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.DS_Store
node_modules
node_modules
test/temp
3 changes: 3 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
machine:
node:
version: 6
30 changes: 12 additions & 18 deletions lib/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var Emitter = require('events').EventEmitter
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')
Expand All @@ -18,8 +19,9 @@ try {
hasBabel = false
}

// determine hot-reload-api location
var hotReloadAPIPath = normalizeDep('vue-hot-reload-api')
// determine dynamic script paths
var hotReloadAPIPath = normalize.dep('vue-hot-reload-api')
var insertCSSPath = normalize.lib('insert-css')

// expose compiler
var compiler = module.exports = new Emitter()
Expand Down Expand Up @@ -83,7 +85,7 @@ compiler.compile = function (content, filePath, cb) {
if (style) {
style = JSON.stringify(style)
output +=
'var __vueify_insert__ = require("vueify/lib/insert-css")\n' +
'var __vueify_insert__ = require("' + insertCSSPath + '")\n' +
'var __vueify_style__ = __vueify_insert__.insert(' + style + ')\n'
}
// script
Expand Down Expand Up @@ -144,9 +146,13 @@ function processTemplate (part, filePath, parts) {
return compileAsPromise('template', template, part.lang, filePath)
.then(function (res) {
var compiled = vueCompiler.compile(res)
parts.template = {
render: toFunction(compiled.render),
staticRenderFns: '[' + compiled.staticRenderFns.map(toFunction).join(',') + ']'
if (compiled.errors.length) {
throw new Error(compiled.errors.join('\n\n'))
} else {
parts.template = {
render: toFunction(compiled.render),
staticRenderFns: '[' + compiled.staticRenderFns.map(toFunction).join(',') + ']'
}
}
})
}
Expand Down Expand Up @@ -216,15 +222,3 @@ function compileAsPromise (type, source, lang, filePath) {
function toFunction (code) {
return 'function(){' + code + '}'
}

function normalizeDep (dep) {
if (process.env.VUEIFY_TEST) {
return dep
} else if (fs.existsSync(path.resolve(__dirname, '../node_modules', dep))) {
// npm 2 or npm linked
return 'vueify/node_modules/' + dep
} else {
// npm 3
return dep
}
}
4 changes: 4 additions & 0 deletions lib/ensure-require.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ module.exports = function (name, deps) {
req = req[0]
}
try {
// hack for babel-runtime because it does not expose "main" field
if (req === 'babel-runtime') {
req = 'babel-runtime/core-js'
}
require.resolve(req)
} catch (e) {
missing.push(mis)
Expand Down
23 changes: 23 additions & 0 deletions lib/normalize.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
var IS_TEST = !!process.env.VUEIFY_TEST
var fs = require('fs')
var path = require('path')

exports.lib = function (file) {
if (IS_TEST) {
return path.resolve(__dirname, file)
} else {
return 'vueify/lib/' + file
}
}

exports.dep = function (dep) {
if (IS_TEST) {
return dep
} else if (fs.existsSync(path.resolve(__dirname, '../node_modules', dep))) {
// npm 2 or npm linked
return 'vueify/node_modules/' + dep
} else {
// npm 3
return dep
}
}
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"url": "https://github.com/vuejs/vueify/issues"
},
"scripts": {
"test": "NODE_ENV=production mocha test/test.js --slow=5000 --timeout=10000"
"test": "mocha test/test.js --slow=5000 --timeout=10000"
},
"homepage": "https://github.com/vuejs/vueify",
"dependencies": {
Expand All @@ -37,13 +37,16 @@
"babel-plugin-transform-runtime": "^6.0.0",
"babel-preset-es2015": "^6.0.0",
"babel-runtime": "^6.0.0",
"browserify": "^13.0.1",
"chai": "^3.5.0",
"coffee-script": "^1.10.0",
"jade": "^1.11.0",
"jsdom": "^9.2.1",
"less": "^2.5.1",
"mocha": "^2.3.3",
"node-sass": "^3.3.3",
"pug": "^2.0.0-alpha6",
"rewire": "^2.5.1",
"rimraf": "^2.5.2",
"stylus": "^0.52.4"
}
}
5 changes: 0 additions & 5 deletions test/fixtures/autoprefix.vue

This file was deleted.

28 changes: 11 additions & 17 deletions test/fixtures/basic.vue
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
<style>
html {
font-size: 20px;
}
</style>

<template>
<h1 :id="id" @click="hi">hello</h1>
<input type="text">
<button :disabled="loading">hihi</button>
<h2 class="red">{{msg}}</h2>
</template>

<script>
class Test {
ok() {}
}

var evens = [2,4,6,8]
var odds = evens.map(v => v + 1)
export default {
data() {
return odds
data () {
return {
msg: 'Hello from Component A!'
}
}
}
</script>

<style>
comp-a h2 {
color: #f00;
}
</style>
117 changes: 47 additions & 70 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,75 +1,52 @@
var fs = require('fs')
var path = require('path')
var compiler = require('../lib/compiler')
var assert = require('assert')
var hash = require('hash-sum')

// test custom transform
compiler.applyConfig({
customCompilers: {
test: function (content, cb) {
content = content.replace('not ', '')
cb(null, content)
}
}
})

function read (file) {
return fs.readFileSync(path.resolve(__dirname, file), 'utf-8')
}

function test (name) {
it(name, function (done) {
var filePath = 'fixtures/' + name + '.vue'
var fileContent = read(filePath)
var expected = read('expects/' + name + '.js')
.replace(/\{\{id\}\}/g, '_v-' + hash(require.resolve('./' + filePath)))

// test registering dependency
var deps = []
function addDep (file) {
deps.push(file)
}
compiler.on('dependency', addDep)

process.env.VUEIFY_TEST = true
process.env.NODE_ENV = name === 'non-minified'
? 'development'
: 'production'

compiler.compile(
fileContent,
path.resolve(__dirname, filePath),
function (err, result) {
// the cb is handled by a Promise, so the assertion
// errors gets swallowed and the test never fails.
// do it in a separate tick.
setTimeout(function () {
if (err) throw err
assert.equal(result, expected, 'should compile correctly')

// check src
if (name === 'src') {
assert.equal(deps[0], __dirname + '/fixtures/test.html')
assert.equal(deps[1], __dirname + '/fixtures/test.styl')
assert.equal(deps[2], __dirname + '/fixtures/src/test.js')
}

if (name === 'less' || name === 'sass' || name === 'styl') {
assert.equal(deps[0], __dirname + '/fixtures/imports/import.' + name)
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')
const vueify = require('../index')
const jsdom = require('jsdom')
const vueCompiler = require('vue-template-compiler')

const tempDir = path.resolve(__dirname, './temp')
const mockEntry = path.resolve(tempDir, 'entry.js')
rimraf.sync(tempDir)
mkdirp.sync(tempDir)

function test (file, assert) {
it(file, done => {
fs.writeFileSync(mockEntry, 'window.vueModule = require("../fixtures/' + file + '.vue")')
browserify(mockEntry)
.transform(vueify)
.bundle((err, buf) => {
if (err) return done(err)
jsdom.env({
html: '<!DOCTYPE html><html><head></head><body></body></html>',
src: [buf.toString()],
done: (err, window) => {
if (err) return done(err)
assert(window)
done()
}

compiler.removeListener('dependency', addDep)
done()
}, 0)
}
)
})
})
})
}

describe('Vueify compiler', function () {
fs.readdirSync(path.resolve(__dirname, 'expects'))
.forEach(function (file) {
test(path.basename(file, '.js'))
})
function assertRenderFn (options, template) {
const compiled = vueCompiler.compile(template)
expect(options.render.toString()).to.equal('function (){' + compiled.render + '}')
}

describe('vueify', () => {
test('basic', window => {
const module = window.vueModule
assertRenderFn(module, '<h2 class="red">{{msg}}</h2>')
expect(module.data().msg).to.contain('Hello from Component A!')
const style = window.document.querySelector('style').textContent
expect(style).to.contain('comp-a h2 {\n color: #f00;\n}')
})
})
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