{{ docs }}
+{{ docs }}
++ This should be red +
+ +``` + +これは算出プロパティなので、`:class` の オブジェクト / 配列構文でも動作します: + +``` html + ++ Am I red? +
++ Red and bold +
+{{ docs }}
+{{ docs }}
++ Isto deve ser vermelho +
+ +``` + +Uma vez que a propriedade é computada, ela também funciona com a sintaxe object/array de `:class`: + +```html + ++ Eu sou vermelho? +
++ Vermelho e negrito +
+{{ docs }}
++ Этот текст будет красным +
+ +``` + +Поскольку это вычисляемое свойство, оно также будет работает с объектом/массивом в `:class`: + +``` html + ++ Буду ли я красным? +
++ Красный и жирный +
++ This should be red +
+ +``` + +由于它是一个计算属性,它也适用于 `:class` 的 object/array 语法: + +``` html + ++ Am I red? +
++ Red and bold +
+
+
+
@@ -326,7 +437,35 @@ describe('vue-loader', function () {
})
})
- it('postcss options', function (done) {
+ it('transformToRequire option', done => {
+ test({
+ entry: './test/fixtures/transform.vue',
+ module: {
+ rules: [
+ { test: /\.vue$/, loader: loaderPath },
+ {
+ test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
+ loader: 'url-loader'
+ }
+ ]
+ }
+ }, (window, module) => {
+ function includeDataURL (s) {
+ return !!s.match(/\s*data:([a-z]+\/[a-z]+(;[a-z\-]+\=[a-z\-]+)?)?(;base64)?,[a-z0-9\!\$\&\'\,\(\)\*\+\,\;\=\-\.\_\~\:\@\/\?\%\s]*\s*/i)
+ }
+ var vnode = mockRender(module)
+ // img tag
+ expect(includeDataURL(vnode.children[0].data.attrs.src)).to.equal(true)
+ // image tag (SVG)
+ expect(includeDataURL(vnode.children[2].children[0].data.attrs['xlink:href'])).to.equal(true)
+ var style = window.document.querySelector('style').textContent
+ // style
+ expect(includeDataURL(style)).to.equal(true)
+ done()
+ })
+ })
+
+ it('postcss options', done => {
test({
entry: './test/fixtures/postcss.vue',
vue: {
@@ -336,18 +475,31 @@ describe('vue-loader', function () {
}
}
}
- }, function (window) {
+ }, (window) => {
+ var style = window.document.querySelector('style').textContent
+ style = normalizeNewline(style)
+ expect(style).to.contain('h1 {\n color: red;\n font-size: 14px\n}')
+ done()
+ })
+ })
+
+ it('load postcss config file', done => {
+ fs.writeFileSync('.postcssrc', JSON.stringify({ parser: 'sugarss' }))
+ test({
+ entry: './test/fixtures/postcss.vue'
+ }, (window) => {
var style = window.document.querySelector('style').textContent
style = normalizeNewline(style)
expect(style).to.contain('h1 {\n color: red;\n font-size: 14px\n}')
+ fs.unlinkSync('.postcssrc')
done()
})
})
- it('transpile ES2015 features in template', function (done) {
+ it('transpile ES2015 features in template', done => {
test({
entry: './test/fixtures/es2015.vue'
- }, function (window, module) {
+ }, (window, module) => {
var vnode = mockRender(module, {
a: 'hello',
b: true
@@ -360,10 +512,10 @@ describe('vue-loader', function () {
})
})
- it('allows to export extended constructor', function (done) {
+ it('allows to export extended constructor', done => {
test({
entry: './test/fixtures/extend.vue'
- }, function (window, Module) {
+ }, (window, Module) => {
// extend.vue should export Vue constructor
var vnode = mockRender(Module.options, {
msg: 'success'
@@ -375,13 +527,13 @@ describe('vue-loader', function () {
})
})
- it('support es compatible modules', function (done) {
+ it('support es compatible modules', done => {
test({
entry: './test/fixtures/basic.vue',
vue: {
esModule: true
}
- }, function (window, module, rawModule) {
+ }, (window, module, rawModule) => {
expect(rawModule.__esModule).to.equal(true)
var vnode = mockRender(rawModule.default, {
msg: 'hi'
@@ -395,7 +547,7 @@ describe('vue-loader', function () {
})
})
- it('css-modules', function (done) {
+ it('css-modules', done => {
function testWithIdent (localIdentName, regexToMatch, cb) {
test({
entry: './test/fixtures/css-modules.vue',
@@ -404,15 +556,13 @@ describe('vue-loader', function () {
localIdentName: localIdentName
}
}
- }, function (window) {
- var module = window.vueModule
-
+ }, (window, module, raw, instance) => {
// get local class name
- var className = module.computed.style().red
+ var className = instance.style.red
expect(className).to.match(regexToMatch)
// class name in style
- var style = [].slice.call(window.document.querySelectorAll('style')).map(function (style) {
+ var style = [].slice.call(window.document.querySelectorAll('style')).map((style) => {
return style.textContent
}).join('\n')
style = normalizeNewline(style)
@@ -426,16 +576,16 @@ describe('vue-loader', function () {
expect(style).to.contain('animation: ' + animationName + ' 1s;')
// default module + pre-processor + scoped
- var anotherClassName = module.computed.$style().red
+ var anotherClassName = instance.$style.red
expect(anotherClassName).to.match(regexToMatch).and.not.equal(className)
- var id = 'data-v-' + genId(require.resolve('./fixtures/css-modules.vue'))
+ var id = 'data-v-' + hash('vue-loader/test/fixtures/css-modules.vue')
expect(style).to.contain('.' + anotherClassName + '[' + id + ']')
cb()
})
}
// default localIdentName
- testWithIdent(undefined, /^\w{23}/, function () {
+ testWithIdent(undefined, /^\w{23}/, () => {
// specified localIdentName
var ident = '[path][name]---[local]---[hash:base64:5]'
var regex = /^test-fixtures-css-modules---red---\w{5}/
@@ -443,25 +593,343 @@ describe('vue-loader', function () {
})
})
- it('css-modules in SSR', function (done) {
+ it('css-modules in SSR', done => {
bundle({
entry: './test/fixtures/css-modules.vue',
target: 'node',
output: Object.assign({}, globalConfig.output, {
libraryTarget: 'commonjs2'
})
- }, function (code) {
+ }, (code, warnings) => {
// http://stackoverflow.com/questions/17581830/load-node-js-module-from-string-in-memory
- function requireFromString(src, filename) {
- var Module = module.constructor;
- var m = new Module();
- m._compile(src, filename);
- return m.exports;
+ function requireFromString (src, filename) {
+ var Module = module.constructor
+ var m = new Module()
+ m._compile(src, filename)
+ return m.exports
}
- var output = requireFromString(code, './test.build.js')
- expect(output.computed.style().red).to.exist
+ var output = interopDefault(requireFromString(code, './test.build.js'))
+ var mockInstance = {}
+ output.beforeCreate.forEach(hook => hook.call(mockInstance))
+ expect(mockInstance.style.red).to.exist
+
+ done()
+ })
+ })
+
+ it('should allow adding custom html loaders', done => {
+ test({
+ entry: './test/fixtures/markdown.vue',
+ vue: {
+ loaders: {
+ html: 'marked'
+ }
+ }
+ }, (window, module) => {
+ var vnode = mockRender(module, {
+ msg: 'hi'
+ })
+ //