package/.babelrc000644 0000000067 3560116604 010656 0ustar00000000 000000 { "plugins": ["transform-es2015-modules-commonjs"] } package/LICENSE000644 0000002057 3560116604 010271 0ustar00000000 000000 Copyright 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/lib/addStylesClient.js000644 0000014130 3560116604 013456 0ustar00000000 000000 /* MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra Modified by Evan You @yyx990803 */ import listToStyles from './listToStyles' var hasDocument = typeof document !== 'undefined' if (typeof DEBUG !== 'undefined' && DEBUG) { if (!hasDocument) { throw new Error( 'vue-style-loader cannot be used in a non-browser environment. ' + "Use { target: 'node' } in your Webpack config to indicate a server-rendering environment." ) } } /* type StyleObject = { id: number; parts: Array } type StyleObjectPart = { css: string; media: string; sourceMap: ?string } */ var stylesInDom = {/* [id: number]: { id: number, refs: number, parts: Array<(obj?: StyleObjectPart) => void> } */} var head = hasDocument && (document.head || document.getElementsByTagName('head')[0]) var singletonElement = null var singletonCounter = 0 var isProduction = false var noop = function () {} var options = null var ssrIdKey = 'data-vue-ssr-id' // Force single-tag solution on IE6-9, which has a hard limit on the # of ' } return css } package/lib/addStylesShadow.js000644 0000003564 3560116604 013476 0ustar00000000 000000 import listToStyles from './listToStyles' export default function addStylesToShadowDOM (parentId, list, shadowRoot) { var styles = listToStyles(parentId, list) addStyles(styles, shadowRoot) } /* type StyleObject = { id: number; parts: Array } type StyleObjectPart = { css: string; media: string; sourceMap: ?string } */ function addStyles (styles /* Array */, shadowRoot) { const injectedStyles = shadowRoot._injectedStyles || (shadowRoot._injectedStyles = {}) for (var i = 0; i < styles.length; i++) { var item = styles[i] var style = injectedStyles[item.id] if (!style) { for (var j = 0; j < item.parts.length; j++) { addStyle(item.parts[j], shadowRoot) } injectedStyles[item.id] = true } } } function createStyleElement (shadowRoot) { var styleElement = document.createElement('style') styleElement.type = 'text/css' shadowRoot.appendChild(styleElement) return styleElement } function addStyle (obj /* StyleObjectPart */, shadowRoot) { var styleElement = createStyleElement(shadowRoot) var css = obj.css var media = obj.media var sourceMap = obj.sourceMap if (media) { styleElement.setAttribute('media', media) } if (sourceMap) { // https://developer.chrome.com/devtools/docs/javascript-debugging // this makes source maps inside style tags work properly in Chrome css += '\n/*# sourceURL=' + sourceMap.sources[0] + ' */' // http://stackoverflow.com/a/26603875 css += '\n/*# sourceMappingURL=data:application/json;base64,' + btoa(unescape(encodeURIComponent(JSON.stringify(sourceMap)))) + ' */' } if (styleElement.styleSheet) { styleElement.styleSheet.cssText = css } else { while (styleElement.firstChild) { styleElement.removeChild(styleElement.firstChild) } styleElement.appendChild(document.createTextNode(css)) } } package/index.js000644 0000010034 3560116604 010723 0ustar00000000 000000 /* 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 ` + `` + `` + `` ) }) 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) } package/package.json000644 0000001242 3560116604 011545 0ustar00000000 000000 { "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" } } package/CHANGELOG.md000644 0000005224 3560116604 011074 0ustar00000000 000000 ## [4.1.3](https://github.com/vuejs/vue-style-loader/compare/v4.0.1...v4.1.3) (2021-03-03) ### Bug Fixes * also support passed ES modules from `css-loader` in addition to CommonJS format ([#47](https://github.com/vuejs/vue-style-loader/issues/47)) ([8b584bd](https://github.com/vuejs/vue-style-loader/commit/8b584bd)) * es module interop in HMR code ([8bc2fe3](https://github.com/vuejs/vue-style-loader/commit/8bc2fe3)) * fix addStyleShadow when same style object is inserted multiple times ([12846a6](https://github.com/vuejs/vue-style-loader/commit/12846a6)) * fix inconsistent hashes between Windows and POSIX systems ([#28](https://github.com/vuejs/vue-style-loader/issues/28)) ([cf8b6e8](https://github.com/vuejs/vue-style-loader/commit/cf8b6e8)) ### Features * support vue-loader 15 ([0c7ee9d](https://github.com/vuejs/vue-style-loader/commit/0c7ee9d)) ## [4.1.2](https://github.com/vuejs/vue-style-loader/compare/v4.1.1...v4.1.2) (2018-08-13) ### Bug Fixes * fix inconsistent hashes between Windows and POSIX systems ([#28](https://github.com/vuejs/vue-style-loader/issues/28)) ([cf8b6e8](https://github.com/vuejs/vue-style-loader/commit/cf8b6e8)) ## [4.1.1](https://github.com/vuejs/vue-style-loader/compare/v4.1.0...v4.1.1) (2018-07-17) ### Bug Fixes * fix addStyleShadow when same style object is inserted multiple times ([12846a6](https://github.com/vuejs/vue-style-loader/commit/12846a6)) # [4.1.0](https://github.com/vuejs/vue-style-loader/compare/v4.0.2...v4.1.0) (2018-03-20) ### Features * support vue-loader 15 ([0c7ee9d](https://github.com/vuejs/vue-style-loader/commit/0c7ee9d)) ## [4.0.2](https://github.com/vuejs/vue-style-loader/compare/v4.0.1...v4.0.2) (2018-02-13) ## [4.0.1](https://github.com/vuejs/vue-style-loader/compare/v4.0.0...v4.0.1) (2018-01-31) ### Bug Fixes * typo ([00087b7](https://github.com/vuejs/vue-style-loader/commit/00087b7)) # [4.0.0](https://github.com/vuejs/vue-style-loader/compare/v3.1.1...v4.0.0) (2018-01-31) ### Features * shadowMode ([94737e5](https://github.com/vuejs/vue-style-loader/commit/94737e5)) * use ESM for runtime files ([18d0ae4](https://github.com/vuejs/vue-style-loader/commit/18d0ae4)) ## [3.1.1](https://github.com/vuejs/vue-style-loader/compare/v3.1.0...v3.1.1) (2018-01-24) # [3.1.0](https://github.com/vuejs/vue-style-loader/compare/v3.0.3...v3.1.0) (2018-01-24) ### Features * add `ssrId` option for rendering ssr id on client ([5281305](https://github.com/vuejs/vue-style-loader/commit/5281305)) package/.github/ISSUE_TEMPLATE.md000644 0000001335 3560116604 013327 0ustar00000000 000000 **Do you want to request a *feature* or report a *bug*?** **What is the current behavior?** **If the current behavior is a bug, please provide the steps to reproduce.** **What is the expected behavior?** **If this is a feature request, what is motivation or use case for changing the behavior?** **Please mention other relevant information such as your webpack version, Node.js version and Operating System.** package/.github/PULL_REQUEST_TEMPLATE.md000644 0000001314 3560116604 014420 0ustar00000000 000000 **What kind of change does this PR introduce?** **Did you add tests for your changes?** **If relevant, did you update the README?** **Summary** **Does this PR introduce a breaking change?** **Other information** package/README.md000644 0000005155 3560116604 010545 0ustar00000000 000000 # vue-style-loader [![Build Status](https://circleci.com/gh/vuejs/vue-style-loader/tree/master.svg?style=shield)](https://circleci.com/gh/vuejs/vue-loader/tree/master) [![npm package](https://img.shields.io/npm/v/vue-style-loader.svg)](https://www.npmjs.com/package/vue-style-loader) This is a fork based on [style-loader](https://github.com/webpack/style-loader). Similar to `style-loader`, you can chain it after `css-loader` to dynamically inject CSS into the document as style tags. However, since this is included as a dependency and used by default in `vue-loader`, in most cases you don't need to configure this loader yourself. ## Options - **manualInject** (3.1.0+): Type: `boolean`. When importing the style from a non-vue-file, by default the style is injected as a side effect of the import. When `manualInject` is true, the imported style object exposes a `__inject__` method, which can then be called manually at appropriate timing. If called on the server, the method expects one argument which is the `ssrContext` to attach styles to. ``` js import styles from 'styles.scss' export default { beforeCreate() { // or create a mixin for this purpose if(styles.__inject__) { styles.__inject__(this.$ssrContext) } } render() { return
Hello World
} } ``` Note this behavior is enabled automatically when `vue-style-loader` is used on styles imported within a `*.vue` file. The option is only exposed for advanced usage. - **ssrId** (3.1.0+): Type: `boolean`. Add `data-vue-ssr-id` attribute to injected `