diff --git a/11-前端模块化开发/04-webpack_Loader使用/node_modules/style-loader/CHANGELOG.md b/11-前端模块化开发/04-webpack_Loader使用/node_modules/style-loader/CHANGELOG.md deleted file mode 100644 index 9d119cc..0000000 --- a/11-前端模块化开发/04-webpack_Loader使用/node_modules/style-loader/CHANGELOG.md +++ /dev/null @@ -1,287 +0,0 @@ -# Changelog - -All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. - -### [1.0.2](https://github.com/webpack-contrib/style-loader/compare/v1.0.1...v1.0.2) (2019-12-17) - - -### Bug Fixes - -* support ES module syntax ([#435](https://github.com/webpack-contrib/style-loader/issues/435)) ([dcbfadb](https://github.com/webpack-contrib/style-loader/commit/dcbfadb4245e7f0ce888aafc138cbac27d053915)) - -### [1.0.1](https://github.com/webpack-contrib/style-loader/compare/v1.0.0...v1.0.1) (2019-11-28) - - -### Bug Fixes - -* compatibility `linkTag` with ES module syntax ([#429](https://github.com/webpack-contrib/style-loader/issues/429)) ([2cdb9c3](https://github.com/webpack-contrib/style-loader/commit/2cdb9c3f51edebec69e8b22ff43b520a5e1c679b)) - -## [1.0.0](https://github.com/webpack-contrib/style-loader/compare/v0.23.1...v1.0.0) (2019-08-06) - - -### Bug Fixes - -* es3 compatibility ([#390](https://github.com/webpack-contrib/style-loader/issues/390)) ([ae24ec2](https://github.com/webpack-contrib/style-loader/commit/ae24ec2)) -* restore original hot reloading behaviour for locals ([#419](https://github.com/webpack-contrib/style-loader/issues/419)) ([f026429](https://github.com/webpack-contrib/style-loader/commit/f026429)) -* better handle source maps ([#383](https://github.com/webpack-contrib/style-loader/issues/383)) ([84ec8e5](https://github.com/webpack-contrib/style-loader/commit/84ec8e5)) - - -### Features - -* new `injectType` option ([e2664e9](https://github.com/webpack-contrib/style-loader/commit/e2664e9)) -* remove type `text/css` from style and link element ([#399](https://github.com/webpack-contrib/style-loader/issues/399)) ([b0187d6](https://github.com/webpack-contrib/style-loader/commit/b0187d6)) - - -### BREAKING CHANGES - -* minimum required Node.js version is `8.9.0` -* minimum required `wepback` version is `4.0.0` -* the `convertToAbsoluteUrls` option was removed, you don't need this anymore -* the `attrs` option was renamed to the `attributes` option -* the `transform` option was removed without replacement -* the `hmr` option was removed, `webpack` automatically inject HMR code when it is required (when the `HotModuleReplacementPlugin` plugin was used) -* the `sourceMap` option was removed. The loader automatically inject source maps if the previous loader emit them -* the `ref`/`unref` api methods were removed for `useable` loader, please use the `use`/`unuse` api methods -* the `style-loader/url` loader was removed in favor `injectType` option (look the documentation about the `injectType` option) -* the `style-loader/useable` loader was removed in favor `injectType` option (look the documentation about the `injectType` option) -* the `singleton` option was removed (look documentation about the `injectType` option) -* the `insertAt` option was removed in favor the `insert` option (look the documentation about the `insert` option and examples) -* the `insertInto` options was removed in favor the `insert` option (look the documentation about the `insert` option and examples) - - - -## [0.23.1](https://github.com/webpack-contrib/style-loader/compare/v0.23.0...v0.23.1) (2018-10-08) - - -### Bug Fixes - -* **addStyles:** support exports of transpiled transforms (`options.transform`) ([#333](https://github.com/webpack-contrib/style-loader/issues/333)) ([33aebed](https://github.com/webpack-contrib/style-loader/commit/33aebed)) - - - - -# [0.23.0](https://github.com/webpack-contrib/style-loader/compare/v0.22.1...v0.23.0) (2018-08-27) - - -### Features - -* **useable:** add `insertInto` support (`options.insertInto`) ([#341](https://github.com/webpack-contrib/style-loader/issues/341)) ([2588aca](https://github.com/webpack-contrib/style-loader/commit/2588aca)) - - - - -## [0.22.1](https://github.com/webpack-contrib/style-loader/compare/v0.22.0...v0.22.1) (2018-08-08) - - -### Bug Fixes - -* **addStyles:** use `var` instead of `const` (IE fix) ([#338](https://github.com/webpack-contrib/style-loader/issues/338)) ([1ca12ab](https://github.com/webpack-contrib/style-loader/commit/1ca12ab)) - - - - -# [0.22.0](https://github.com/webpack-contrib/style-loader/compare/v0.21.0...v0.22.0) (2018-08-07) - - -### Bug Fixes - -* insertInto and insertAt collaboration ([#325](https://github.com/webpack-contrib/style-loader/issues/325)) ([c7d8fec](https://github.com/webpack-contrib/style-loader/commit/c7d8fec)) - - -### Features - -* add support for __webpack_nonce__ ([#319](https://github.com/webpack-contrib/style-loader/issues/319)) ([fc24512](https://github.com/webpack-contrib/style-loader/commit/fc24512)) - - - - -# [0.21.0](https://github.com/webpack-contrib/style-loader/compare/v0.20.3...v0.21.0) (2018-04-18) - - -### Features - -* enable tag type configuration ([#316](https://github.com/webpack-contrib/style-loader/issues/316)) ([892cba5](https://github.com/webpack-contrib/style-loader/commit/892cba5)) - - - - -## [0.20.3](https://github.com/webpack-contrib/style-loader/compare/v0.20.2...v0.20.3) (2018-03-09) - - -### Bug Fixes - -* **package:** update `schema-utils` v0.4.3...0.4.5 (`dependencies`) ([#308](https://github.com/webpack-contrib/style-loader/issues/308)) ([9455888](https://github.com/webpack-contrib/style-loader/commit/9455888)) - - - - -## [0.20.2](https://github.com/webpack-contrib/style-loader/compare/v0.20.1...v0.20.2) (2018-02-15) - - -### Bug Fixes - -* **urls:** skip empty `url()` handling ([#304](https://github.com/webpack-contrib/style-loader/issues/304)) ([64f12dc](https://github.com/webpack-contrib/style-loader/commit/64f12dc)) - - - - -## [0.20.1](https://github.com/webpack-contrib/style-loader/compare/v0.20.0...v0.20.1) (2018-01-26) - - -### Bug Fixes - -* **index:** source code indentation ([#299](https://github.com/webpack-contrib/style-loader/issues/299)) ([b4642e7](https://github.com/webpack-contrib/style-loader/commit/b4642e7)) - - - - -# [0.20.0](https://github.com/webpack-contrib/style-loader/compare/v0.19.1...v0.20.0) (2018-01-26) - - -### Bug Fixes - -* **addStyles:** check if `HTMLIFrameElement` exist ([#296](https://github.com/webpack-contrib/style-loader/issues/296)) ([9b46128](https://github.com/webpack-contrib/style-loader/commit/9b46128)) -* **index:** enable HMR in case `locals` (`css-modules`) are unchanged ([#298](https://github.com/webpack-contrib/style-loader/issues/298)) ([3a4cb53](https://github.com/webpack-contrib/style-loader/commit/3a4cb53)) -* **options:** add `transform` option validation (`{String}`) ([23c3567](https://github.com/webpack-contrib/style-loader/commit/23c3567)) -* **options:** support passing a `{Function}` (`options.insertInto`) ([e0c4b19](https://github.com/webpack-contrib/style-loader/commit/e0c4b19)) - - -### Features - -* support passing a `{Function}` (`options.insertInto`) ([#279](https://github.com/webpack-contrib/style-loader/issues/279)) ([0eb8fe7](https://github.com/webpack-contrib/style-loader/commit/0eb8fe7)) - - - - -## [0.19.1](https://github.com/webpack/style-loader/compare/v0.19.0...v0.19.1) (2017-12-14) - - -### Bug Fixes - -* **addStyles:** correctly check `singleton` behavior when `{Boolean}` (`options.singleton`) ([#285](https://github.com/webpack/style-loader/issues/285)) ([2bfc93e](https://github.com/webpack/style-loader/commit/2bfc93e)) - - - - -# [0.19.0](https://github.com/webpack/style-loader/compare/v0.18.2...v0.19.0) (2017-10-03) - - -### Features - -* add option to enable/disable HMR (`options.hmr`) ([#264](https://github.com/webpack/style-loader/issues/264)) ([378e906](https://github.com/webpack/style-loader/commit/378e906)) -* add support for iframes (`options.insertInto`) ([#248](https://github.com/webpack/style-loader/issues/248)) ([25e8e89](https://github.com/webpack/style-loader/commit/25e8e89)) -* support 'before' insertions (`options.insertAt`) ([#253](https://github.com/webpack/style-loader/issues/253)) ([67120f8](https://github.com/webpack/style-loader/commit/67120f8)) - - - - -## [0.18.2](https://github.com/webpack/style-loader/compare/v0.18.1...v0.18.2) (2017-06-05) - - -### Bug Fixes - -* **url:** use `loaderUtils.stringifyRequest` to avoid invalidating hashes due to absolute paths ([#242](https://github.com/webpack/style-loader/issues/242)) ([97508ec](https://github.com/webpack/style-loader/commit/97508ec)) -* Add `null` check to `removeStyleElement` ([#245](https://github.com/webpack/style-loader/issues/245)) ([0a4845c](https://github.com/webpack/style-loader/commit/0a4845c)) - - - - -## [0.18.1](https://github.com/webpack/style-loader/compare/v0.18.0...v0.18.1) (2017-05-23) - - -### Bug Fixes - -* **addStyles:** revert merged loops ([#236](https://github.com/webpack/style-loader/issues/236)) ([fbd04b1](https://github.com/webpack/style-loader/commit/fbd04b1)) - - - - -# [0.18.0](https://github.com/webpack/style-loader/compare/v0.17.0...v0.18.0) (2017-05-22) - - -### Bug Fixes - -* stringify the options.transform request ([#230](https://github.com/webpack/style-loader/issues/230)) ([5888095](https://github.com/webpack/style-loader/commit/5888095)) - - -### Features - -* add options validation ([#224](https://github.com/webpack/style-loader/issues/224)) ([4b6b70d](https://github.com/webpack/style-loader/commit/4b6b70d)) - - - - -# [0.17.0](https://github.com/webpack/style-loader/compare/v0.16.1...v0.17.0) (2017-05-01) - - -### Features - -* add option.base ([#164](https://github.com/webpack/style-loader/issues/164)) ([e4ac886](https://github.com/webpack/style-loader/commit/e4ac886)) -* add option.transform ([#146](https://github.com/webpack/style-loader/issues/146)) ([1c3943f](https://github.com/webpack/style-loader/commit/1c3943f)) - - - - -## [0.16.1](https://github.com/webpack/style-loader/compare/v0.16.0...v0.16.1) (2017-03-28) - - -### Bug Fixes - -* negative refs ([#122](https://github.com/webpack/style-loader/issues/122)) ([f6f577a](https://github.com/webpack/style-loader/commit/f6f577a)) - - - - -# [0.16.0](https://github.com/webpack/style-loader/compare/v0.15.0...v0.16.0) (2017-03-22) - - -### Bug Fixes - -* **addStyles:** update for test for old IE versions ([#196](https://github.com/webpack/style-loader/issues/196)) ([1f68495](https://github.com/webpack/style-loader/commit/1f68495)) - - -### Features - -* Set custom attributes for tag in url mode ([#198](https://github.com/webpack/style-loader/issues/198)) ([2c4f427](https://github.com/webpack/style-loader/commit/2c4f427)) - - - - -# [0.15.0](https://github.com/webpack/style-loader/compare/v0.14.1...v0.15.0) (2017-03-21) - - -### Bug Fixes - -* match parens recursively on URLs to not fix embeded calls ([#192](https://github.com/webpack/style-loader/issues/192)) ([71e0908](https://github.com/webpack/style-loader/commit/71e0908)) - - -### Features - -* add insertInto option ([#135](https://github.com/webpack/style-loader/issues/135)) ([6636868](https://github.com/webpack/style-loader/commit/6636868)) - - - - -## [0.14.1](https://github.com/webpack/style-loader/compare/v0.14.0...v0.14.1) (2017-03-15) - - -### Bug Fixes - -* syntax error in IE10 and below because of `const` keyword ([#190](https://github.com/webpack/style-loader/issues/190)) ([01080cf](https://github.com/webpack/style-loader/commit/01080cf)) - - - - -# [0.14.0](https://github.com/webpack/style-loader/compare/v0.13.1...v0.14.0) (2017-03-15) - - -### Bug Fixes - -* Adds type attr. to the generated link element ([2a2f261](https://github.com/webpack/style-loader/commit/2a2f261)) -* **fixUrls:** add param to fix relative urls ([#186](https://github.com/webpack/style-loader/issues/186)) ([19959ee](https://github.com/webpack/style-loader/commit/19959ee)) -* **usable:** Export locals if available([#128](https://github.com/webpack/style-loader/issues/128)) ([e280cb6](https://github.com/webpack/style-loader/commit/e280cb6)) - - -### Features - -* **tag-attribute:** Add support for custom tag attribute ([995f3de](https://github.com/webpack/style-loader/commit/995f3de)) diff --git a/11-前端模块化开发/04-webpack_Loader使用/node_modules/style-loader/README.md b/11-前端模块化开发/04-webpack_Loader使用/node_modules/style-loader/README.md deleted file mode 100644 index 6ba1791..0000000 --- a/11-前端模块化开发/04-webpack_Loader使用/node_modules/style-loader/README.md +++ /dev/null @@ -1,785 +0,0 @@ -
- - - -

Style Loader

-
- -[![npm][npm]][npm-url] -[![node][node]][node-url] -[![deps][deps]][deps-url] -[![tests][tests]][tests-url] -[![coverage][cover]][cover-url] -[![chat][chat]][chat-url] -[![size][size]][size-url] - -# style-loader - -Inject CSS into the DOM. - -## Getting Started - -To begin, you'll need to install `style-loader`: - -```console -npm install --save-dev style-loader -``` - -It's recommended to combine `style-loader` with the [`css-loader`](https://github.com/webpack-contrib/css-loader) - -Then add the loader to your `webpack` config. For example: - -**style.css** - -```css -body { - background: green; -} -``` - -**component.js** - -```js -import './style.css'; -``` - -**webpack.config.js** - -```js -module.exports = { - module: { - rules: [ - { - test: /\.css$/i, - use: ['style-loader', 'css-loader'], - }, - ], - }, -}; -``` - -## Options - -| Name | Type | Default | Description | -| :--------------: | :------------------: | :--------: | :------------------------------------------------------- | -| **`injectType`** | `{String}` | `styleTag` | Allows to setup how styles will be injected into the DOM | -| **`attributes`** | `{Object}` | `{}` | Adds custom attributes to tag | -| **`insert`** | `{String\|Function}` | `head` | Inserts tag at the given position into the DOM | -| **`base`** | `{Number}` | `true` | Sets module ID base (DLLPlugin) | - -### `injectType` - -Type: `String` -Default: `styleTag` - -Allows to setup how styles will be injected into the DOM. - -Possible values: - -- `styleTag` -- `singletonStyleTag` -- `lazyStyleTag` -- `lazySingletonStyleTag` -- `linkTag` - -#### `styleTag` - -Automatically injects styles into the DOM using multiple ``. It is **default** behaviour. - -**component.js** - -```js -import './styles.css'; -``` - -Example with c Locals (CSS Modules): - -**component-with-css-modules.js** - -```js -import styles from './styles.css'; - -const divElement = document.createElement('div'); -divElement.className = styles['my-class']; -``` - -All locals (class names) stored in imported object. - -**webpack.config.js** - -```js -module.exports = { - module: { - rules: [ - { - test: /\.css$/i, - use: [ - // The `injectType` option can be avoided because it is default behaviour - { loader: 'style-loader', options: { injectType: 'styleTag' } }, - 'css-loader', - ], - }, - ], - }, -}; -``` - -The loader inject styles like: - -```html - - -``` - -#### `singletonStyleTag` - -Automatically injects styles into the DOM using one ``. - -> ⚠ Source maps do not work. - -**component.js** - -```js -import './styles.css'; -``` - -**component-with-css-modules.js** - -```js -import styles from './styles.css'; - -const divElement = document.createElement('div'); -divElement.className = styles['my-class']; -``` - -All locals (class names) stored in imported object. - -**webpack.config.js** - -```js -module.exports = { - module: { - rules: [ - { - test: /\.css$/i, - use: [ - { - loader: 'style-loader', - options: { injectType: 'singletonStyleTag' }, - }, - 'css-loader', - ], - }, - ], - }, -}; -``` - -The loader inject styles like: - -```html - -``` - -#### `lazyStyleTag` - -Injects styles into the DOM using multiple `` on demand. -We recommend following `.lazy.css` naming convention for lazy styles and the `.css` for basic `style-loader` usage (similar to other file types, i.e. `.lazy.less` and `.less`). -When you `lazyStyleTag` value the `style-loader` injects the styles lazily making them useable on-demand via `style.use()` / `style.unuse()`. - -> ⚠️ Behavior is undefined when `unuse` is called more often than `use`. Don't do that. - -**component.js** - -```js -import styles from './styles.lazy.css'; - -styles.use(); -// For removing styles you can use -// styles.unuse(); -``` - -**component-with-css-modules.js** - -```js -import styles from './styles.lazy.css'; - -styles.use(); - -const divElement = document.createElement('div'); -divElement.className = styles.locals['my-class']; -``` - -All locals (class names) stored in `locals` property of imported object. - -**webpack.config.js** - -```js -module.exports = { - module: { - rules: [ - { - test: /\.css$/i, - exclude: /\.lazy\.css$/i, - use: ['style-loader', 'css-loader'], - }, - { - test: /\.lazy\.css$/i, - use: [ - { loader: 'style-loader', options: { injectType: 'lazyStyleTag' } }, - 'css-loader', - ], - }, - ], - }, -}; -``` - -The loader inject styles like: - -```html - - -``` - -#### `lazySingletonStyleTag` - -Injects styles into the DOM using one `` on demand. -We recommend following `.lazy.css` naming convention for lazy styles and the `.css` for basic `style-loader` usage (similar to other file types, i.e. `.lazy.less` and `.less`). -When you `lazySingletonStyleTag` value the `style-loader` injects the styles lazily making them useable on-demand via `style.use()` / `style.unuse()`. - -> ⚠️ Source maps do not work. - -> ⚠️ Behavior is undefined when `unuse` is called more often than `use`. Don't do that. - -**component.js** - -```js -import styles from './styles.css'; - -styles.use(); -// For removing styles you can use -// styles.unuse(); -``` - -**component-with-css-modules.js** - -```js -import styles from './styles.lazy.css'; - -styles.use(); - -const divElement = document.createElement('div'); -divElement.className = styles.locals['my-class']; -``` - -All locals (class names) stored in `locals` property of imported object. - -**webpack.config.js** - -```js -module.exports = { - module: { - rules: [ - { - test: /\.css$/i, - exclude: /\.lazy\.css$/i, - use: ['style-loader', 'css-loader'], - }, - { - test: /\.lazy\.css$/i, - use: [ - { loader: 'style-loader', options: { injectType: 'lazyStyleTag' } }, - 'css-loader', - ], - }, - ], - }, -}; -``` - -The loader generate this: - -```html - -``` - -#### `linkTag` - -Injects styles into the DOM using multiple `` . - -> ℹ️ The loader will dynamically insert the `` tag at runtime via JavaScript. You should use [MiniCssExtractPlugin](https://webpack.js.org/plugins/mini-css-extract-plugin/) if you want to include a static ``. - -```js -import './styles.css'; -import './other-styles.css'; -``` - -**webpack.config.js** - -```js -module.exports = { - module: { - rules: [ - { - test: /\.link\.css$/i, - use: [ - { loader: 'style-loader', options: { injectType: 'linkTag' } }, - { loader: 'file-loader' }, - ], - }, - ], - }, -}; -``` - -The loader generate this: - -```html - - -``` - -### `attributes` - -Type: `Object` -Default: `{}` - -If defined, the `style-loader` will attach given attributes with their values on ` -``` - -### `insert` - -Type: `String|Function` -Default: `head` - -By default, the `style-loader` appends ` -``` - -#### `__webpack_nonce__` - -**create-nonce.js** - -```js -__webpack_nonce__ = '12345678'; -``` - -**component.js** - -```js -import './create-nonce.js'; -import './style.css'; -``` - -Alternative example for `require`: - -**component.js** - -```js -__webpack_nonce__ = '12345678'; - -require('./style.css'); -``` - -**webpack.config.js** - -```js -module.exports = { - module: { - rules: [ - { - test: /\.css$/i, - use: ['style-loader', 'css-loader'], - }, - ], - }, -}; -``` - -The loader generate: - -```html - -``` - -#### Insert styles at top - -Inserts styles at top of `head` tag. - -**webpack.config.js** - -```js -module.exports = { - module: { - rules: [ - { - test: /\.css$/i, - use: [ - { - loader: 'style-loader', - options: { - insert: function insertAtTop(element) { - var parent = document.querySelector('head'); - var lastInsertedElement = - window._lastElementInsertedByStyleLoader; - - if (!lastInsertedElement) { - parent.insertBefore(element, parent.firstChild); - } else if (lastInsertedElement.nextSibling) { - parent.insertBefore(element, lastInsertedElement.nextSibling); - } else { - parent.appendChild(element); - } - - window._lastElementInsertedByStyleLoader = element; - }, - }, - }, - 'css-loader', - ], - }, - ], - }, -}; -``` - -#### Insert styles before target element - -Inserts styles before `#id` element. - -**webpack.config.js** - -```js -module.exports = { - module: { - rules: [ - { - test: /\.css$/i, - use: [ - { - loader: 'style-loader', - options: { - insert: function insertBeforeAt(element) { - const parent = document.querySelector('head'); - const target = document.querySelector('#id'); - - const lastInsertedElement = - window._lastElementInsertedByStyleLoader; - - if (!lastInsertedElement) { - parent.insertBefore(element, target); - } else if (lastInsertedElement.nextSibling) { - parent.insertBefore(element, lastInsertedElement.nextSibling); - } else { - parent.appendChild(element); - } - - window._lastElementInsertedByStyleLoader = element; - }, - }, - }, - 'css-loader', - ], - }, - ], - }, -}; -``` - -## Contributing - -Please take a moment to read our contributing guidelines if you haven't yet done so. - -[CONTRIBUTING](./.github/CONTRIBUTING.md) - -## License - -[MIT](./LICENSE) - -[npm]: https://img.shields.io/npm/v/style-loader.svg -[npm-url]: https://npmjs.com/package/style-loader -[node]: https://img.shields.io/node/v/style-loader.svg -[node-url]: https://nodejs.org -[deps]: https://david-dm.org/webpack-contrib/style-loader.svg -[deps-url]: https://david-dm.org/webpack-contrib/style-loader -[tests]: https://dev.azure.com/webpack-contrib/style-loader/_apis/build/status/webpack-contrib.style-loader?branchName=master -[tests-url]: https://dev.azure.com/webpack-contrib/style-loader/_build/latest?definitionId=18&branchName=master -[cover]: https://codecov.io/gh/webpack-contrib/style-loader/branch/master/graph/badge.svg -[cover-url]: https://codecov.io/gh/webpack-contrib/style-loader -[chat]: https://badges.gitter.im/webpack/webpack.svg -[chat-url]: https://gitter.im/webpack/webpack -[size]: https://packagephobia.now.sh/badge?p=style-loader -[size-url]: https://packagephobia.now.sh/result?p=style-loader diff --git a/11-前端模块化开发/04-webpack_Loader使用/node_modules/style-loader/dist/index.js b/11-前端模块化开发/04-webpack_Loader使用/node_modules/style-loader/dist/index.js deleted file mode 100644 index 5034adb..0000000 --- a/11-前端模块化开发/04-webpack_Loader使用/node_modules/style-loader/dist/index.js +++ /dev/null @@ -1,165 +0,0 @@ -"use strict"; - -var _path = _interopRequireDefault(require("path")); - -var _loaderUtils = _interopRequireDefault(require("loader-utils")); - -var _schemaUtils = _interopRequireDefault(require("schema-utils")); - -var _options = _interopRequireDefault(require("./options.json")); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -module.exports = () => {}; - -module.exports.pitch = function loader(request) { - const options = _loaderUtils.default.getOptions(this) || {}; - (0, _schemaUtils.default)(_options.default, options, { - name: 'Style Loader', - baseDataPath: 'options' - }); - const insert = typeof options.insert === 'undefined' ? '"head"' : typeof options.insert === 'string' ? JSON.stringify(options.insert) : options.insert.toString(); - const injectType = options.injectType || 'styleTag'; - - switch (injectType) { - case 'linkTag': - { - const hmrCode = this.hot ? ` -if (module.hot) { - module.hot.accept( - ${_loaderUtils.default.stringifyRequest(this, `!!${request}`)}, - function() { - var newContent = require(${_loaderUtils.default.stringifyRequest(this, `!!${request}`)}); - newContent = newContent.__esModule ? newContent.default : newContent; - - update(newContent); - } - ); - - module.hot.dispose(function() { - update(); - }); -}` : ''; - return `var options = ${JSON.stringify(options)}; - -options.insert = ${insert}; - -var content = require(${_loaderUtils.default.stringifyRequest(this, `!!${request}`)}); -content = content.__esModule ? content.default : content; - -var update = require(${_loaderUtils.default.stringifyRequest(this, `!${_path.default.join(__dirname, 'runtime/injectStylesIntoLinkTag.js')}`)})(content, options); -${hmrCode}`; - } - - case 'lazyStyleTag': - case 'lazySingletonStyleTag': - { - const isSingleton = injectType === 'lazySingletonStyleTag'; - const hmrCode = this.hot ? ` -if (module.hot) { - var lastRefs = module.hot.data && module.hot.data.refs || 0; - - if (lastRefs) { - exports.use(); - - if (!content.locals) { - refs = lastRefs; - } - } - - if (!content.locals) { - module.hot.accept(); - } - - module.hot.dispose(function(data) { - data.refs = content.locals ? 0 : refs; - - if (dispose) { - dispose(); - } - }); -}` : ''; - return `var refs = 0; -var dispose; -var content = require(${_loaderUtils.default.stringifyRequest(this, `!!${request}`)}); -content = content.__esModule ? content.default : content; - -var options = ${JSON.stringify(options)}; - -options.insert = ${insert}; -options.singleton = ${isSingleton}; - -if (typeof content === 'string') { - content = [[module.id, content, '']]; -} - -if (content.locals) { - exports.locals = content.locals; -} - -exports.use = function() { - if (!(refs++)) { - dispose = require(${_loaderUtils.default.stringifyRequest(this, `!${_path.default.join(__dirname, 'runtime/injectStylesIntoStyleTag.js')}`)})(content, options); - } - - return exports; -}; - -exports.unuse = function() { - if (refs > 0 && !--refs) { - dispose(); - dispose = null; - } -}; -${hmrCode} -`; - } - - case 'styleTag': - case 'singletonStyleTag': - default: - { - const isSingleton = injectType === 'singletonStyleTag'; - const hmrCode = this.hot ? ` -if (module.hot) { - if (!content.locals) { - module.hot.accept( - ${_loaderUtils.default.stringifyRequest(this, `!!${request}`)}, - function () { - var newContent = require(${_loaderUtils.default.stringifyRequest(this, `!!${request}`)}); - newContent = newContent.__esModule ? newContent.default : newContent; - - if (typeof newContent === 'string') { - newContent = [[module.id, newContent, '']]; - } - - update(newContent); - } - ) - } - - module.hot.dispose(function() { - update(); - }); -}` : ''; - return `var content = require(${_loaderUtils.default.stringifyRequest(this, `!!${request}`)}); -content = content.__esModule ? content.default : content; - -if (typeof content === 'string') { - content = [[module.id, content, '']]; -} - -var options = ${JSON.stringify(options)} - -options.insert = ${insert}; -options.singleton = ${isSingleton}; - -var update = require(${_loaderUtils.default.stringifyRequest(this, `!${_path.default.join(__dirname, 'runtime/injectStylesIntoStyleTag.js')}`)})(content, options); - -if (content.locals) { - module.exports = content.locals; -} -${hmrCode}`; - } - } -}; \ No newline at end of file diff --git a/11-前端模块化开发/04-webpack_Loader使用/node_modules/style-loader/dist/options.json b/11-前端模块化开发/04-webpack_Loader使用/node_modules/style-loader/dist/options.json deleted file mode 100644 index c68ad61..0000000 --- a/11-前端模块化开发/04-webpack_Loader使用/node_modules/style-loader/dist/options.json +++ /dev/null @@ -1,35 +0,0 @@ -{ - "type": "object", - "properties": { - "injectType": { - "description": "Allows to setup how styles will be injected into DOM (https://github.com/webpack-contrib/style-loader#injecttype).", - "enum": [ - "styleTag", - "singletonStyleTag", - "lazyStyleTag", - "lazySingletonStyleTag", - "linkTag" - ] - }, - "attributes": { - "description": "Adds custom attributes to tag (https://github.com/webpack-contrib/style-loader#attributes).", - "type": "object" - }, - "insert": { - "description": "Inserts `