first commit

This commit is contained in:
jefferyzhao
2025-07-31 17:44:12 +08:00
commit b9bdc8598b
42390 changed files with 4467935 additions and 0 deletions

202
node_modules/@vue/preload-webpack-plugin/LICENSE generated vendored Normal file
View File

@ -0,0 +1,202 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright 2014 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

301
node_modules/@vue/preload-webpack-plugin/README.md generated vendored Normal file
View File

@ -0,0 +1,301 @@
@vue/preload-webpack-plugin
============
[![NPM version][npm-img]][npm-url]
This is a fork of [preload-webpack-plugin](https://github.com/GoogleChromeLabs/preload-webpack-plugin) with a number of changes:
- Uses a combination of `htmlWebpackPluginBeforeHtmlProcessing` and `htmlWebpackPluginAlterAssetTags` hooks to inject links as objects rather than strings. This allows for more flexibility when the tags need to be altered by other plugins.
- `include` option can be an object in the shape of `{ type?, chunks?, entries? }`. For example, to prefetch async chunks for a specific entry point:
``` js
{
rel: 'prefetch',
include: {
type: 'asyncChunks',
entries: ['app']
}
}
```
- Added an `includeHtmlNames` option so that the plugin is only applied to a specific HTML file.
- Drops support for webpack v3.
- Drops support for Node < 6.
---
![preloads-plugin-compressor](https://cloud.githubusercontent.com/assets/110953/22451103/7700b812-e720-11e6-89e8-a6d4e3533159.png)
A Webpack plugin for automatically wiring up asynchronous (and other types) of JavaScript
chunks using `<link rel='preload'>`. This helps with lazy-loading.
Note: This is an extension plugin for [html-webpack-plugin](https://github.com/ampedandwired/html-webpack-plugin) - a plugin that
simplifies the creation of HTML files to serve your webpack bundles.
This plugin is a stop-gap until we add support for asynchronous chunk wiring to
[script-ext-html-webpack-plugin](https://github.com/numical/script-ext-html-webpack-plugin/pull/9).
Introduction
------------
[Preload](https://w3c.github.io/preload/) is a web standard aimed at improving performance
and granular loading of resources. It is a declarative fetch that can tell a browser to start fetching a
source because a developer knows the resource will be needed soon. [Preload: What is it good for?](https://www.smashingmagazine.com/2016/02/preload-what-is-it-good-for/)
is a recommended read if you haven't used the feature before.
In simple web apps, it's straight-forward to specify static paths to scripts you
would like to preload - especially if their names or locations are unlikely to change. In more complex apps,
JavaScript can be split into "chunks" (that represent routes or components) at with dynamic
names. These names can include hashes, numbers and other properties that can change with each build.
For example, `chunk.31132ae6680e598f8879.js`.
To make it easier to wire up async chunks for lazy-loading, this plugin offers a drop-in way to wire them up
using `<link rel='preload'>`.
Pre-requisites
--------------
This module requires Webpack 2.2.0 and above. It also requires that you're using
[html-webpack-plugin](https://github.com/ampedandwired/html-webpack-plugin) in your Webpack project.
Installation
---------------
First, install the package as a dependency in your package.json:
```sh
$ npm install --save-dev preload-webpack-plugin
```
Alternatively, using yarn:
```sh
yarn add -D preload-webpack-plugin
```
Usage
-----------------
Next, in your Webpack config, `require()` the preload plugin as follows:
```js
const PreloadWebpackPlugin = require('preload-webpack-plugin');
```
and finally, configure the plugin in your Webpack `plugins` array after `HtmlWebpackPlugin`:
```js
plugins: [
new HtmlWebpackPlugin(),
new PreloadWebpackPlugin()
]
```
When preloading files, the plugin will use different `as` attribute depends on the type of each
file. For each file ends with `.css`, the plugin will preload it with `as=style`, for each file ends
with `.woff2`, the plugin will preload it with `as=font`, while for all other files, `as=script`
will be used.
If you do not prefer to determine `as` attribute depends on suffix of filename, you can also
explicitly name it using `as`:
```javascript
plugins: [
new HtmlWebpackPlugin(),
new PreloadWebpackPlugin({
rel: 'preload',
as: 'script'
})
]
```
In case you need more fine-grained control of the `as` atribute, you could also provide a function here.
When using it, entry name will be provided as the parameter, and function itself should return a
string for `as` attribute:
```javascript
plugins: [
new HtmlWebpackPlugin(),
new PreloadWebpackPlugin({
rel: 'preload',
as(entry) {
if (/\.css$/.test(entry)) return 'style';
if (/\.woff$/.test(entry)) return 'font';
if (/\.png$/.test(entry)) return 'image';
return 'script';
}
})
]
```
Notice that if `as=font` is used in preload, crossorigin will be added, otherwise the font resource
might be double fetched. Explains can be found in [this article](https://medium.com/reloading/preload-prefetch-and-priorities-in-chrome-776165961bbf).
By default, the plugin will assume async script chunks will be preloaded. This is the equivalent of:
```js
plugins: [
new HtmlWebpackPlugin(),
new PreloadWebpackPlugin({
rel: 'preload',
include: 'asyncChunks'
})
]
```
For a project generating two async scripts with dynamically generated names, such as
`chunk.31132ae6680e598f8879.js` and `chunk.d15e7fdfc91b34bb78c4.js`, the following preloads
will be injected into the document `<head>`:
```html
<link rel="preload" as="script" href="chunk.31132ae6680e598f8879.js">
<link rel="preload" as="script" href="chunk.d15e7fdfc91b34bb78c4.js">
```
You can also configure the plugin to preload all chunks (vendor, async, normal chunks) using `include: 'all'`, or only preload initial chunks with `include: 'initial'`:
```js
plugins: [
new HtmlWebpackPlugin(),
new PreloadWebpackPlugin({
rel: 'preload',
include: 'all' // or 'initial'
})
]
```
In case you work with named chunks, you can explicitly specify which ones to `include` by passing an array:
```js
plugins: [
new HtmlWebpackPlugin(),
new PreloadWebpackPlugin({
rel: 'preload',
include: ['home']
})
]
```
will inject just this:
```html
<link rel="preload" as="script" href="home.31132ae6680e598f8879.js">
```
Filtering chunks
---------------------
There may be chunks that you don't want to have preloaded (sourcemaps, for example). Before preloading each chunk, this plugin checks that the file does not match any regex in the `fileBlacklist` option. The default value of this blacklist is `[/\.map/]`, meaning no sourcemaps will be preloaded. You can easily override this:
```js
new PreloadWebpackPlugin({
fileBlacklist: [/\.whatever/]
})
```
Passing your own array will override the default, so if you want to continue filtering sourcemaps along with your own custom settings, you'll need to include the regex for sourcemaps:
```js
new PreloadWebpackPlugin({
fileBlacklist: [/\.map/, /\.whatever/]
})
```
Resource Hints
---------------------
Should you wish to use Resource Hints (such as `prefetch`) instead of `preload`, this plugin also supports wiring those up.
Prefetch:
```js
plugins: [
new HtmlWebpackPlugin(),
new PreloadWebpackPlugin({
rel: 'prefetch'
})
]
```
For the async chunks mentioned earlier, the plugin would update your HTML to the following:
```html
<link rel="prefetch" href="chunk.31132ae6680e598f8879.js">
<link rel="prefetch" href="chunk.d15e7fdfc91b34bb78c4.js">
```
Demo
----------------------
A demo application implementing the [PRPL pattern](https://developers.google.com/web/fundamentals/performance/prpl-pattern/) with React that uses this plugin can be found in the `demo`
directory.
Support
-------
If you've found an error in this sample, please file an issue:
[https://github.com/googlechrome/preload-webpack-plugin/issues](https://github.com/googlechrome/preload-webpack-plugin/issues)
Patches are encouraged, and may be submitted by forking this project and
submitting a pull request through GitHub.
Contributing workflow
---------------------
`index.js` contains the primary source for the plugin, `test` contains tests and `demo` contains demo code.
Test the plugin:
```sh
$ npm install
$ npm run test
```
Lint the plugin:
```sh
$ npm run lint
$ npm run lint-fix # fix linting issues
```
The project is written in ES2015, but does not use a build-step. This may change depending on
any Node version support requests posted to the issue tracker.
Additional Notes
---------------------------
* Be careful not to `preload` resources a user is unlikely to need. This can waste their bandwidth.
* Use `preload` for the current session if you think a user is likely to visit the next page. There is no
100% guarantee preloaded items will end up in the HTTP Cache and read locally beyond this session.
* If optimising for future sessions, use `prefetch` and `preconnect`. Prefetched resources are maintained
in the HTTP Cache for at least 5 minutes (in Chrome) regardless of the resource's cachability.
Related plugins
--------------------------
* [script-ext-html-webpack-plugin](https://github.com/numical/script-ext-html-webpack-plugin) - Enhances html-webpack-plugin with options including 'async', 'defer', 'module' and preload (no async chunk support yet)
* [resource-hints-webpack-plugin](https://github.com/jantimon/resource-hints-webpack-plugin) - Automatically wires resource hints for your resources (similarly no async chunk support)
License
-------
Copyright 2017 Google, Inc.
Licensed to the Apache Software Foundation (ASF) under one or more contributor
license agreements. See the NOTICE file distributed with this work for
additional information regarding copyright ownership. The ASF licenses this
file to you under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.
[npm-url]: https://www.npmjs.com/package/@vue/preload-webpack-plugin
[npm-img]: https://badge.fury.io/js/%40vue%2Fpreload-webpack-plugin.svg

51
node_modules/@vue/preload-webpack-plugin/package.json generated vendored Normal file
View File

@ -0,0 +1,51 @@
{
"name": "@vue/preload-webpack-plugin",
"version": "1.1.2",
"description": "A webpack plugin for injecting <link rel='preload|prefecth'> into HtmlWebpackPlugin pages, with async chunk support",
"author": "Addy Osmani <addy.osmani@gmail.com> (https://github.com/addyosmani)",
"license": "Apache-2.0",
"bugs": {
"url": "https://github.com/vuejs/preload-webpack-plugin/issues"
},
"homepage": "https://github.com/vuejs/preload-webpack-plugin",
"repository": {
"type": "git",
"url": "https://github.com/vuejs/preload-webpack-plugin.git"
},
"keywords": [
"webpack",
"plugin",
"html-webpack-plugin",
"script",
"preload",
"resource hints"
],
"engines": {
"node": ">=6.0.0"
},
"scripts": {
"lint": "eslint --format=codeframe .",
"test": "npm run lint && jasmine test/unit/* test/e2e/index.js",
"coverage": "nyc npm run test",
"prepublishOnly": "npm run test"
},
"main": "src/index.js",
"files": [
"src"
],
"devDependencies": {
"eslint": "^4.19.1",
"eslint-plugin-vue-libs": "^2.1.0",
"html-webpack-plugin": "^3.2.0",
"jasmine": "^3.1.0",
"jsdom": "^11.9.0",
"memory-fs": "^0.4.1",
"nyc": "^11.7.1",
"rimraf": "^2.6.2",
"webpack": "^4.0.0"
},
"peerDependencies": {
"html-webpack-plugin": ">=2.26.0",
"webpack": ">=4.0.0"
}
}

145
node_modules/@vue/preload-webpack-plugin/src/index.js generated vendored Normal file
View File

@ -0,0 +1,145 @@
/**
* @license
* Copyright 2018 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const defaultOptions = require('./lib/default-options')
const determineAsValue = require('./lib/determine-as-value')
const doesChunkBelongToHTML = require('./lib/does-chunk-belong-to-html')
const extractChunks = require('./lib/extract-chunks')
class PreloadPlugin {
constructor (options) {
this.options = Object.assign({}, defaultOptions, options)
}
generateLinks (compilation, htmlPluginData) {
const options = this.options
const extractedChunks = extractChunks({
compilation,
optionsInclude: options.include
})
const htmlChunks = options.include === 'allAssets'
// Handle all chunks.
? extractedChunks
// Only handle chunks imported by this HtmlWebpackPlugin.
: extractedChunks.filter((chunk) => doesChunkBelongToHTML({
chunk,
compilation,
htmlAssetsChunks: Object.values(htmlPluginData.assets.chunks)
}))
// Flatten the list of files.
const allFiles = htmlChunks.reduce((accumulated, chunk) => {
return accumulated.concat(chunk.files)
}, [])
const uniqueFiles = new Set(allFiles)
const filteredFiles = [...uniqueFiles].filter(file => {
return (
!this.options.fileWhitelist ||
this.options.fileWhitelist.some(regex => regex.test(file))
)
}).filter(file => {
return (
!this.options.fileBlacklist ||
this.options.fileBlacklist.every(regex => !regex.test(file))
)
})
// Sort to ensure the output is predictable.
const sortedFilteredFiles = filteredFiles.sort()
const links = []
const publicPath = compilation.outputOptions.publicPath || ''
for (const file of sortedFilteredFiles) {
const href = `${publicPath}${file}`
const attributes = {
href,
rel: options.rel
}
// If we're preloading this resource (as opposed to prefetching),
// then we need to set the 'as' attribute correctly.
if (options.rel === 'preload') {
attributes.as = determineAsValue({
href,
file,
optionsAs: options.as
})
// On the off chance that we have a cross-origin 'href' attribute,
// set crossOrigin on the <link> to trigger CORS mode. Non-CORS
// fonts can't be used.
if (attributes.as === 'font') {
attributes.crossorigin = ''
}
}
links.push({
tagName: 'link',
attributes
})
}
this.resourceHints = links
return htmlPluginData
}
apply (compiler) {
const skip = data => {
const htmlFilename = data.plugin.options.filename
const exclude = this.options.excludeHtmlNames
const include = this.options.includeHtmlNames
return (
(include && !(include.includes(htmlFilename))) ||
(exclude && exclude.includes(htmlFilename))
)
}
compiler.hooks.compilation.tap(
this.constructor.name,
compilation => {
compilation.hooks.htmlWebpackPluginBeforeHtmlProcessing.tap(
this.constructor.name,
(htmlPluginData) => {
if (skip(htmlPluginData)) {
return
}
this.generateLinks(compilation, htmlPluginData)
}
)
compilation.hooks.htmlWebpackPluginAlterAssetTags.tap(
this.constructor.name,
(htmlPluginData) => {
if (skip(htmlPluginData)) {
return
}
if (this.resourceHints) {
htmlPluginData.head = [
...this.resourceHints,
...htmlPluginData.head
]
}
return htmlPluginData
}
)
}
)
}
}
module.exports = PreloadPlugin

View File

@ -0,0 +1,25 @@
/**
* @license
* Copyright 2018 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const defaultOptions = {
rel: 'preload',
include: 'asyncChunks',
excludeHtmlNames: [],
fileBlacklist: [/\.map/]
}
module.exports = defaultOptions

View File

@ -0,0 +1,60 @@
/**
* @license
* Copyright 2018 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const assert = require('assert')
const path = require('path')
const { URL } = require('url')
function determineAsValue ({ optionsAs, href, file }) {
assert(href, `The 'href' parameter was not provided.`)
switch (typeof optionsAs) {
case 'string': {
return optionsAs
}
case 'function': {
return optionsAs(href)
}
case 'undefined': {
// If `as` value is not provided in option, dynamically determine the correct
// value based on the suffix of filename.
// We only care about the pathname, so just use any domain when constructing the URL.
// Use file instead of href option because the publicPath part may be malformed.
// See https://github.com/vuejs/vue-cli/issues/5672
const url = new URL(file || href, 'https://example.com')
const extension = path.extname(url.pathname)
if (extension === '.css') {
return 'style'
}
if (extension === '.woff2') {
return 'font'
}
return 'script'
}
default:
throw new Error(`The 'as' option isn't set to a recognized value: ${optionsAs}`)
}
}
module.exports = determineAsValue

View File

@ -0,0 +1,30 @@
/**
* @license
* Copyright 2018 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
module.exports = function doesChunkBelongToHtml ({ chunk, htmlAssetsChunks, compilation }) {
// Get all the hashes of the HTML assets.
const rootHashes = Object.values(htmlAssetsChunks).map(({ hash }) => hash)
// Get a list of chunk groups that contain one of those hashes.
const rootChunkGroups = compilation.chunkGroups.filter((chunkGroup) => {
return chunkGroup.chunks.filter((chunk) => rootHashes.includes(chunk.renderedHash))
})
// Get an id for each of those chunk groups.
const rootChunkGroupsIds = new Set(rootChunkGroups.map(({ id }) => id))
// Return true iff the chunk we're passed belongs to a group whose id is in
// the list of root chunk groups.
return Array.from(chunk.groupsIterable).some(({ id }) => rootChunkGroupsIds.has(id))
}

View File

@ -0,0 +1,108 @@
/**
* @license
* Copyright 2018 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
function isAsync (chunk) {
if ('canBeInitial' in chunk) {
return !chunk.canBeInitial()
} else {
return !chunk.isInitial()
}
}
function getChunkEntryNames (chunk) {
if ('groupsIterable' in chunk) {
return Array.from(new Set(getNames(chunk.groupsIterable)))
} else {
return chunk.entrypoints.map(e => e.options.name)
}
}
function getNames (groups, processed = new Set()) {
const Entrypoint = require('webpack/lib/Entrypoint')
const names = []
for (const group of groups) {
if (group instanceof Entrypoint) {
// entrypoint
if (group.options.name) {
names.push(group.options.name)
}
} else if (!processed.has(group)) {
processed.add(group)
names.push(...getNames(group.parentsIterable, processed))
}
}
return names
}
function extractChunks ({ compilation, optionsInclude }) {
let includeChunks
let includeType
let includeEntryPoints
if (optionsInclude && typeof optionsInclude === 'object') {
includeType = optionsInclude.type
includeChunks = optionsInclude.chunks
includeEntryPoints = optionsInclude.entries
} else {
if (Array.isArray(optionsInclude)) {
includeChunks = optionsInclude
} else {
includeType = optionsInclude
}
}
let chunks = compilation.chunks
if (Array.isArray(includeChunks)) {
chunks = chunks.filter((chunk) => {
return chunk.name && includeChunks.includes(chunk.name)
})
}
if (Array.isArray(includeEntryPoints)) {
chunks = chunks.filter(chunk => {
const names = getChunkEntryNames(chunk)
return names.some(name => includeEntryPoints.includes(name))
})
}
// 'asyncChunks' are chunks intended for lazy/async loading usually generated as
// part of code-splitting with import() or require.ensure(). By default, asyncChunks
// get wired up using link rel=preload when using this plugin. This behaviour can be
// configured to preload all types of chunks or just prefetch chunks as needed.
if (includeType === undefined || includeType === 'asyncChunks') {
return chunks.filter(isAsync)
}
if (includeType === 'initial') {
return chunks.filter(chunk => !isAsync(chunk))
}
if (includeType === 'allChunks') {
// Async chunks, vendor chunks, normal chunks.
return chunks
}
if (includeType === 'allAssets') {
// Every asset, regardless of which chunk it's in.
// Wrap it in a single, "psuedo-chunk" return value.
return [{ files: Object.keys(compilation.assets) }]
}
return chunks
}
module.exports = extractChunks