8889841ctest/test.js000066600000005751150513531750007061 0ustar00import addStylesClient from '../lib/addStylesClient' import addStylesServer from '../lib/addStylesServer' const mockedList = [ [1, 'h1 { color: red; }', ''], [1, 'p { color: green; }', ''], [2, 'span { color: blue; }', ''], [2, 'span { color: blue; }', 'print'] ] test('addStylesClient (dev)', () => { const update = addStylesClient('foo', mockedList, false) assertStylesMatch(mockedList) const mockedList2 = mockedList.slice(1, 3) update(mockedList2) assertStylesMatch(mockedList2) update() expect(document.querySelectorAll('style').length).toBe(0) }) test('addStylesClient (prod)', () => { const update = addStylesClient('foo', mockedList, true) assertStylesMatch(mockedList) const mockedList2 = mockedList.slice(2) update(mockedList2) assertStylesMatch(mockedList2) update() expect(document.querySelectorAll('style').length).toBe(0) }) test('addStylesClient (dev + ssr)', () => { mockSSRTags(mockedList, 'foo') const update = addStylesClient('foo', mockedList, false) assertStylesMatch(mockedList) update() expect(document.querySelectorAll('style').length).toBe(0) }) test('addStylesClient (prod + ssr)', () => { mockProdSSRTags(mockedList, 'foo') const update = addStylesClient('foo', mockedList, true) expect(document.querySelectorAll('style').length).toBe(1) }) test('addStylesServer (dev)', () => { const context = global.__VUE_SSR_CONTEXT__ = {} addStylesServer('foo', mockedList, false) expect(context.styles).toBe( `` + `` + `` + `` ) }) test('addStylesServer (prod)', () => { const context = global.__VUE_SSR_CONTEXT__ = {} addStylesServer('foo', mockedList, true) expect(context.styles).toBe( `` + `` ) }) // --- helpers --- function assertStylesMatch (list) { const styles = document.querySelectorAll('style') expect(styles.length).toBe(list.length) ;[].forEach.call(styles, (style, i) => { expect(style.textContent.indexOf(list[i][1]) > -1).toBe(true) }) } function mockSSRTags (list, parentId) { list.forEach((item, i) => { const style = document.createElement('style') style.setAttribute('data-vue-ssr-id', `${parentId}:${i}`) style.textContent = item[1] if (item[2]) { style.setAttribute('media', item[2]) } document.head.appendChild(style) }) } function mockProdSSRTags (list, parentId) { const style = document.createElement('style') style.setAttribute('data-vue-ssr-id', list.map((item, i) => `${parentId}:${i}`).join(' ')) style.textContent = list.map(item => item[1]).join('\n') document.head.appendChild(style) } index.js000066600000010034150513531750006220 0ustar00/* MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra Modified by Evan You @yyx990803 */ var loaderUtils = require('loader-utils') var path = require('path') var hash = require('hash-sum') var qs = require('querystring') module.exports = function () {} module.exports.pitch = function (remainingRequest) { var isServer = this.target === 'node' var isProduction = this.minimize || process.env.NODE_ENV === 'production' var addStylesClientPath = loaderUtils.stringifyRequest(this, '!' + path.join(__dirname, 'lib/addStylesClient.js')) var addStylesServerPath = loaderUtils.stringifyRequest(this, '!' + path.join(__dirname, 'lib/addStylesServer.js')) var addStylesShadowPath = loaderUtils.stringifyRequest(this, '!' + path.join(__dirname, 'lib/addStylesShadow.js')) var request = loaderUtils.stringifyRequest(this, '!!' + remainingRequest) var relPath = path.relative(__dirname, this.resourcePath).replace(/\\/g, '/') var id = JSON.stringify(hash(request + relPath)) var options = loaderUtils.getOptions(this) || {} // direct css import from js --> direct, or manually call `styles.__inject__(ssrContext)` with `manualInject` option // css import from vue file --> component lifecycle linked // style embedded in vue file --> component lifecycle linked var isVue = ( /"vue":true/.test(remainingRequest) || options.manualInject || qs.parse(this.resourceQuery.slice(1)).vue != null ) var shared = [ '// style-loader: Adds some css to the DOM by adding a ' } return css } LICENSE000066600000002057150513531750005566 0ustar00Copyright JS Foundation and other contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. package.json000066600000001242150513531750007042 0ustar00{ "name": "vue-style-loader", "version": "4.1.3", "author": "Evan You", "description": "Vue.js style loader module for webpack", "repository": { "type": "git", "url": "git@github.com:vuejs/vue-style-loader.git" }, "scripts": { "test": "jest", "prepublishOnly": "conventional-changelog -p angular -r 2 -i CHANGELOG.md -s" }, "license": "MIT", "dependencies": { "hash-sum": "^1.0.2", "loader-utils": "^1.0.2" }, "devDependencies": { "babel-core": "^6.26.0", "babel-jest": "^22.1.0", "babel-plugin-transform-es2015-modules-commonjs": "^6.26.0", "conventional-changelog-cli": "^2.0.1", "jest": "^22.1.4" } }