mirror of
https://github.com/pure-admin/vue-pure-admin.git
synced 2025-11-21 14:13:36 +08:00
docs:更新文档
This commit is contained in:
21
node_modules/rollup-plugin-web-worker-loader/.editorconfig
generated
vendored
Normal file
21
node_modules/rollup-plugin-web-worker-loader/.editorconfig
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
# EditorConfig helps developers define and maintain consistent
|
||||
# coding styles between different editors and IDEs
|
||||
# editorconfig.org
|
||||
|
||||
root = true
|
||||
|
||||
|
||||
[*]
|
||||
|
||||
# Change these settings to your own preference
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
|
||||
# We recommend you to keep these unchanged
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
||||
8
node_modules/rollup-plugin-web-worker-loader/.eslintignore
generated
vendored
Normal file
8
node_modules/rollup-plugin-web-worker-loader/.eslintignore
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
node_modules
|
||||
.*
|
||||
bamboo
|
||||
coverage
|
||||
dist
|
||||
example
|
||||
gulpfile.js
|
||||
tests
|
||||
454
node_modules/rollup-plugin-web-worker-loader/.eslintrc
generated
vendored
Normal file
454
node_modules/rollup-plugin-web-worker-loader/.eslintrc
generated
vendored
Normal file
@@ -0,0 +1,454 @@
|
||||
// Rules reference: http://eslint.org/docs/rules/
|
||||
{
|
||||
"extends": [],
|
||||
"env": {
|
||||
"browser": true,
|
||||
"node" : true,
|
||||
"es6": true,
|
||||
"mocha": true
|
||||
},
|
||||
|
||||
"globals": {
|
||||
"expect": true,
|
||||
"sinon": true,
|
||||
"module":true,
|
||||
"Snap":true,
|
||||
"_":true,
|
||||
"$":true,
|
||||
"require":true
|
||||
},
|
||||
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 2017,
|
||||
"sourceType": "module",
|
||||
// ES6 Language Features
|
||||
"ecmaFeatures": {
|
||||
"arrowFunctions": true,
|
||||
"blockBindings": true,
|
||||
"classes": true,
|
||||
"defaultParams": true,
|
||||
"destructuring": true,
|
||||
"forOf": true,
|
||||
"generators": true,
|
||||
"modules": true,
|
||||
"objectLiteralComputedProperties": true,
|
||||
"objectLiteralDuplicateProperties": false,
|
||||
"objectLiteralShorthandMethods": true,
|
||||
"objectLiteralShorthandProperties": true,
|
||||
"restParams": true,
|
||||
"spread": true,
|
||||
"superInFunctions": false,
|
||||
"templateStrings": true,
|
||||
}
|
||||
},
|
||||
|
||||
"rules": {
|
||||
|
||||
//=========================================================================
|
||||
//==================== Possible Errors ====================================
|
||||
//=========================================================================
|
||||
|
||||
// disallow trailing commas in object literals
|
||||
"comma-dangle": [2, "always-multiline"], //TODO: need discussion
|
||||
// disallow assignment in conditional expressions
|
||||
"no-cond-assign": [2, "always"],
|
||||
// disallow use of console
|
||||
"no-console": 1,
|
||||
// disallow use of constant expressions in conditions
|
||||
"no-constant-condition": [2, { "checkLoops": false }],
|
||||
// disallow control characters in regular expressions
|
||||
"no-control-regex": 2,
|
||||
// disallow use of debugger
|
||||
"no-debugger": 2,
|
||||
// disallow duplicate arguments in functions
|
||||
"no-dupe-args": 2,
|
||||
// disallow duplicate keys when creating object literals
|
||||
"no-dupe-keys": 2,
|
||||
// disallow a duplicate case label.
|
||||
"no-duplicate-case": 2,
|
||||
// disallow the use of empty character classes in regular expressions
|
||||
"no-empty-character-class": 2,
|
||||
// disallow empty statements
|
||||
"no-empty": 2,
|
||||
// disallow assigning to the exception in a catch block
|
||||
"no-ex-assign": 2,
|
||||
// disallow double-negation boolean casts in a boolean context
|
||||
"no-extra-boolean-cast": 2,
|
||||
// disallow unnecessary parentheses
|
||||
"no-extra-parens": [2, "functions"],
|
||||
// disallow unnecessary semicolons
|
||||
"no-extra-semi": 2,
|
||||
// disallow overwriting functions written as function declarations
|
||||
"no-func-assign": 2,
|
||||
// disallow function or variable declarations in nested blocks
|
||||
"no-inner-declarations": 2,
|
||||
// disallow invalid regular expression strings in the RegExp constructor
|
||||
"no-invalid-regexp": 2,
|
||||
// disallow irregular whitespace outside of strings and comments
|
||||
"no-irregular-whitespace": 2,
|
||||
// disallow negation of the left operand of an in expression
|
||||
"no-negated-in-lhs": 2,
|
||||
// disallow the use of object properties of the global object (Math and JSON) as functions
|
||||
"no-obj-calls": 2,
|
||||
// disallow multiple spaces in a regular expression literal
|
||||
"no-regex-spaces": 2,
|
||||
// disallow sparse arrays
|
||||
"no-sparse-arrays": 2,
|
||||
// Avoid code that looks like two expressions but is actually one
|
||||
"no-unexpected-multiline": 2,
|
||||
// disallow unreachable statements after a return, throw, continue, or break statement
|
||||
"no-unreachable": 2,
|
||||
// disallow comparisons with the value NaN
|
||||
"use-isnan": 2,
|
||||
// ensure JSDoc comments are valid
|
||||
"valid-jsdoc": [2, {
|
||||
"requireReturn": false,
|
||||
"requireReturnDescription": false
|
||||
}],
|
||||
// ensure that the results of typeof are compared against a valid string
|
||||
"valid-typeof": 2,
|
||||
|
||||
//=========================================================================
|
||||
//==================== Best Practices =====================================
|
||||
//=========================================================================
|
||||
// Enforces getter/setter pairs in objects
|
||||
"accessor-pairs": 2,
|
||||
// treat var statements as if they were block scoped
|
||||
"block-scoped-var": 2,
|
||||
// specify the maximum cyclomatic complexity allowed in a program
|
||||
"complexity": [0, 11],
|
||||
// require return statements to either always or never specify values
|
||||
"consistent-return": 2,
|
||||
// specify curly brace conventions for all control statements
|
||||
"curly": [2, "multi-line"],
|
||||
// require default case in switch statements
|
||||
"default-case": 2,
|
||||
// encourages use of dot notation whenever possible
|
||||
"dot-notation": [2, { "allowKeywords": true}],
|
||||
// enforces consistent newlines before or after dots
|
||||
"dot-location": [2, "property"],
|
||||
// require the use of === and !==
|
||||
"eqeqeq": 2,
|
||||
// make sure for-in loops have an if statement
|
||||
"guard-for-in": 2,
|
||||
// disallow the use of alert, confirm, and prompt
|
||||
"no-alert": 2,
|
||||
// disallow use of arguments.caller or arguments.callee
|
||||
"no-caller": 2,
|
||||
// disallow lexical declarations in case clauses
|
||||
"no-case-declarations": 2,
|
||||
// disallow division operators explicitly at beginning of regular expression
|
||||
"no-div-regex": 2,
|
||||
// disallow else after a return in an if
|
||||
"no-else-return": 2,
|
||||
// disallow use of empty destructuring patterns
|
||||
"no-empty-pattern": 2,
|
||||
// disallow comparisons to null without a type-checking operator
|
||||
"no-eq-null": 2,
|
||||
// disallow use of eval()
|
||||
"no-eval": 2,
|
||||
// disallow adding to native types
|
||||
"no-extend-native": 2,
|
||||
// disallow unnecessary function binding
|
||||
"no-extra-bind": 2,
|
||||
// disallow fallthrough of case statements
|
||||
"no-fallthrough": 2,
|
||||
// disallow the use of leading or trailing decimal points in numeric literals
|
||||
"no-floating-decimal": 2,
|
||||
// disallow the type conversions with shorter notations
|
||||
"no-implicit-coercion": 2,
|
||||
// disallow use of eval()-like methods
|
||||
"no-implied-eval": 2,
|
||||
// disallow this keywords outside of classes or class-like objects
|
||||
"no-invalid-this":0,
|
||||
// disallow usage of __iterator__ property
|
||||
"no-iterator": 2,
|
||||
// disallow use of labeled statements
|
||||
"no-labels": 2,
|
||||
// disallow unnecessary nested blocks
|
||||
"no-lone-blocks": 2,
|
||||
// disallow creation of functions within loops
|
||||
"no-loop-func": 2,
|
||||
// disallow the use of magic numbers
|
||||
"no-magic-numbers": 0, //TODO: need discussion
|
||||
// disallow use of multiple spaces
|
||||
"no-multi-spaces": 2,
|
||||
// disallow use of multiline strings
|
||||
"no-multi-str": 2,
|
||||
// disallow reassignments of native objects
|
||||
"no-native-reassign": 2,
|
||||
// disallow use of new operator for Function object
|
||||
"no-new-func": 2,
|
||||
// disallows creating new instances of String,Number, and Boolean
|
||||
"no-new-wrappers": 2,
|
||||
// disallow use of new operator when not part of the assignment or comparison
|
||||
"no-new": 2,
|
||||
// disallow use of octal escape sequences in string literals, such as
|
||||
// var foo = "Copyright \251";
|
||||
"no-octal-escape": 2,
|
||||
// disallow use of (old style) octal literals
|
||||
"no-octal": 2,
|
||||
// disallow reassignment of function parameters
|
||||
"no-param-reassign": 2,
|
||||
// disallow use of process.env
|
||||
"no-process-env": 2,
|
||||
// disallow usage of __proto__ property
|
||||
"no-proto": 2,
|
||||
// disallow declaring the same variable more then once
|
||||
"no-redeclare": 2,
|
||||
// disallow use of assignment in return statement
|
||||
"no-return-assign": 2,
|
||||
// disallow use of `javascript:` urls.
|
||||
"no-script-url": 2,
|
||||
// disallow comparisons where both sides are exactly the same
|
||||
"no-self-compare": 2,
|
||||
// disallow use of comma operator
|
||||
"no-sequences": 2,
|
||||
// restrict what can be thrown as an exception
|
||||
"no-throw-literal": 0,
|
||||
// disallow usage of expressions in statement position
|
||||
"no-unused-expressions": 2,
|
||||
// disallow unnecessary .call() and .apply()
|
||||
"no-useless-call": 2,
|
||||
// disallow unnecessary concatenation of literals or template literals
|
||||
"no-useless-concat": 2,
|
||||
// disallow use of void operator
|
||||
"no-void": 2,
|
||||
// disallow usage of configurable warning terms in comments: e.g. todo
|
||||
"no-warning-comments": [1, { "terms": ["todo", "fixme", "xxx"], "location": "start" }],
|
||||
// disallow use of the with statement
|
||||
"no-with": 2,
|
||||
// require use of the second argument for parseInt()
|
||||
"radix": 2,
|
||||
// requires to declare all vars on top of their containing scope
|
||||
"vars-on-top": 0,
|
||||
// require immediate function invocation to be wrapped in parentheses
|
||||
"wrap-iife": [2, "any"],
|
||||
// require or disallow Yoda conditions
|
||||
"yoda": 2,
|
||||
|
||||
// //=========================================================================
|
||||
// //==================== Strict Mode ========================================
|
||||
// //=========================================================================
|
||||
// require that all functions are run in strict mode
|
||||
// "strict": [2, "global"],
|
||||
//
|
||||
//=========================================================================
|
||||
//==================== Variables ==========================================
|
||||
//=========================================================================
|
||||
// enforce or disallow variable initializations at definition
|
||||
"init-declarations": 0,
|
||||
// disallow the catch clause parameter name being the same as a variable in the outer scope
|
||||
"no-catch-shadow": 0,
|
||||
// disallow deletion of variables
|
||||
"no-delete-var": 2,
|
||||
// disallow labels that share a name with a variable
|
||||
"no-label-var": 2,
|
||||
// disallow shadowing of names such as arguments
|
||||
"no-shadow-restricted-names": 2,
|
||||
// disallow declaration of variables already declared in the outer scope
|
||||
"no-shadow": 2,
|
||||
// disallow use of undefined when initializing variables
|
||||
"no-undef-init": 0,
|
||||
// disallow use of undeclared variables unless mentioned in a /*global */ block
|
||||
"no-undef": 2,
|
||||
// disallow use of undefined variable
|
||||
"no-undefined": 0,
|
||||
// disallow declaration of variables that are not used in the code
|
||||
"no-unused-vars": [1, {"vars": "local", "args": "after-used"}],
|
||||
// disallow use of variables before they are defined
|
||||
"no-use-before-define": 2,
|
||||
|
||||
//=========================================================================
|
||||
//==================== Node.js ============================================
|
||||
//=========================================================================
|
||||
// enforce return after a callback
|
||||
"callback-return": 0,
|
||||
// disallow require() outside of the top-level module scope
|
||||
"global-require": 2,
|
||||
// enforces error handling in callbacks (node environment)
|
||||
"handle-callback-err": 2,
|
||||
// disallow mixing regular variable and require declarations
|
||||
"no-mixed-requires": 2,
|
||||
// disallow use of new operator with the require function
|
||||
"no-new-require": 2,
|
||||
// disallow string concatenation with __dirname and __filename
|
||||
"no-path-concat": 1,
|
||||
// disallow process.exit()
|
||||
"no-process-exit": 2,
|
||||
// restrict usage of specified node modules
|
||||
"no-restricted-modules": 0,
|
||||
// disallow use of synchronous methods (off by default)
|
||||
"no-sync": 0,
|
||||
|
||||
//=========================================================================
|
||||
//==================== Stylistic Issues ===================================
|
||||
//=========================================================================
|
||||
// enforce spacing inside array brackets
|
||||
"array-bracket-spacing": 0,
|
||||
// disallow or enforce spaces inside of single line blocks
|
||||
"block-spacing": 1,
|
||||
// enforce one true brace style
|
||||
"brace-style": [1, "1tbs", {"allowSingleLine": true }],
|
||||
// require camel case names
|
||||
"camelcase": [1, {"properties": "always"}],
|
||||
// enforce spacing before and after comma
|
||||
"comma-spacing": [1, {"before": false, "after": true}],
|
||||
// enforce one true comma style
|
||||
"comma-style": [1, "last"],
|
||||
// require or disallow padding inside computed properties
|
||||
"computed-property-spacing": 0,
|
||||
// enforces consistent naming when capturing the current execution context
|
||||
"consistent-this": 0,
|
||||
// enforce newline at the end of file, with no multiple empty lines
|
||||
"eol-last": 1,
|
||||
// require function expressions to have a name
|
||||
"func-names": 0,
|
||||
// enforces use of function declarations or expressions
|
||||
"func-style": 0,
|
||||
// this option enforces minimum and maximum identifier lengths (variable names, property names etc.)
|
||||
"id-length": 0,
|
||||
// require identifiers to match the provided regular expression
|
||||
"id-match": 0,
|
||||
// this option sets a specific tab width for your code
|
||||
"indent": [1, 4, {"SwitchCase": 1}],
|
||||
// specify whether double or single quotes should be used in JSX attributes
|
||||
"jsx-quotes": [1, "prefer-double"],
|
||||
// enforces spacing between keys and values in object literal properties
|
||||
"key-spacing": [1, {"beforeColon": false, "afterColon": true}],
|
||||
// disallow mixed "LF" and "CRLF" as linebreaks
|
||||
"linebreak-style": 0,
|
||||
// enforces empty lines around comments
|
||||
"lines-around-comment": 0,
|
||||
// specify the maximum depth that blocks can be nested
|
||||
"max-depth": [0, 4],
|
||||
// specify the maximum length of a line in your program
|
||||
"max-len": [0, 80, 4],
|
||||
// specify the maximum depth callbacks can be nested
|
||||
"max-nested-callbacks": 0,
|
||||
// limits the number of parameters that can be used in the function declaration.
|
||||
"max-params": [0, 3],
|
||||
// specify the maximum number of statement allowed in a function
|
||||
"max-statements": [0, 10],
|
||||
// require a capital letter for constructors
|
||||
"new-cap": [1, {"newIsCap": true}],
|
||||
// disallow the omission of parentheses when invoking a constructor with no arguments
|
||||
"new-parens": 0,
|
||||
// allow/disallow an empty newline after var statement
|
||||
"newline-after-var": 0,
|
||||
// disallow use of the Array constructor
|
||||
"no-array-constructor": 0,
|
||||
// disallow use of bitwise operators
|
||||
"no-bitwise": 0,
|
||||
// disallow use of the continue statement
|
||||
"no-continue": 0,
|
||||
// disallow comments inline after code
|
||||
"no-inline-comments": 0,
|
||||
// disallow if as the only statement in an else block
|
||||
"no-lonely-if": 0,
|
||||
// disallow mixed spaces and tabs for indentation
|
||||
"no-mixed-spaces-and-tabs": 1,
|
||||
// disallow multiple empty lines
|
||||
"no-multiple-empty-lines": [1, {"max": 2, "maxEOF": 1}],
|
||||
// disallow negated conditions
|
||||
"no-negated-condition": 0,
|
||||
// disallow nested ternary expressions
|
||||
"no-nested-ternary": 1,
|
||||
// disallow use of the Object constructor
|
||||
"no-new-object": 1,
|
||||
// disallow use of unary operators, ++ and --
|
||||
"no-plusplus": 0,
|
||||
// disallow use of certain syntax in code
|
||||
"no-restricted-syntax": 0,
|
||||
// disallow space between function identifier and application
|
||||
"no-spaced-func": 1,
|
||||
// disallow the use of ternary operators
|
||||
"no-ternary": 0,
|
||||
// disallow trailing whitespace at the end of lines
|
||||
"no-trailing-spaces": 1,
|
||||
// disallow dangling underscores in identifiers
|
||||
"no-underscore-dangle": 0,
|
||||
// disallow the use of Boolean literals in conditional expressions
|
||||
"no-unneeded-ternary": 0,
|
||||
// require or disallow padding inside curly braces
|
||||
"object-curly-spacing": 0,
|
||||
// allow just one var statement per function
|
||||
"one-var": [1, "never"],
|
||||
// require assignment operator shorthand where possible or prohibit it entirely
|
||||
"operator-assignment": 0,
|
||||
// enforce operators to be placed before or after line breaks
|
||||
"operator-linebreak": 0,
|
||||
// enforce padding within blocks
|
||||
"padded-blocks": [1, "never"],
|
||||
// require quotes around object literal property names
|
||||
"quote-props": 0,
|
||||
// specify whether double or single quotes should be used
|
||||
"quotes": [1, "single", "avoid-escape"],
|
||||
// Require JSDoc comment
|
||||
"require-jsdoc": 0,
|
||||
// enforce spacing before and after semicolons
|
||||
"semi-spacing": [1, {"before": false, "after": true}],
|
||||
// require or disallow use of semicolons instead of ASI
|
||||
"semi": [1, "always"],
|
||||
// sort variables within the same declaration block
|
||||
"sort-vars": 0,
|
||||
// require a space after certain keywords
|
||||
"keyword-spacing": 1,
|
||||
// require or disallow space before blocks
|
||||
"space-before-blocks": 1,
|
||||
// require or disallow space before function opening parenthesis
|
||||
"space-before-function-paren": [0, {"anonymous": "always", "named": "never"}],
|
||||
// require or disallow space before blocks
|
||||
"space-in-parens": 0,
|
||||
// require spaces around operators
|
||||
"space-infix-ops": 1,
|
||||
// Require or disallow spaces before/after unary operators
|
||||
"space-unary-ops": 0,
|
||||
// require or disallow a space immediately following the // or /* in a comment
|
||||
"spaced-comment": [1, "always", {
|
||||
"exceptions": ["-", "+", "/", "="],
|
||||
"markers": ["=", "!"] // space here to support sprockets directives
|
||||
}],
|
||||
// require regex literals to be wrapped in parentheses
|
||||
"wrap-regex": 0,
|
||||
|
||||
//=========================================================================
|
||||
//==================== ES6 Rules ==========================================
|
||||
//=========================================================================
|
||||
"arrow-body-style": [1, "as-needed"],
|
||||
// require parens in arrow function arguments
|
||||
"arrow-parens": [1, "as-needed"],
|
||||
// require space before/after arrow function"s arrow
|
||||
"arrow-spacing": 1,
|
||||
// verify super() callings in constructors
|
||||
"constructor-super": 1,
|
||||
// enforce the spacing around the * in generator functions
|
||||
"generator-star-spacing": 1,
|
||||
// disallow arrow functions where a condition is expected
|
||||
"no-confusing-arrow": 1,
|
||||
// disallow modifying variables of class declarations
|
||||
"no-class-assign": 1,
|
||||
// disallow modifying variables that are declared using const
|
||||
"no-const-assign": 1,
|
||||
// disallow duplicate name in class members
|
||||
"no-dupe-class-members": 1,
|
||||
// disallow to use this/super before super() calling in constructors.
|
||||
"no-this-before-super": 1,
|
||||
// require let or const instead of var
|
||||
"no-var": 0, //TODO: enable on full migration to es6
|
||||
// require method and property shorthand syntax for object literals
|
||||
"object-shorthand": 0,
|
||||
// suggest using arrow functions as callbacks
|
||||
"prefer-arrow-callback": 0, //TODO: enable on full migration to es6
|
||||
// suggest using of const declaration for variables that are never modified after declared
|
||||
"prefer-const": 0, //TODO: enable on full migration to es6
|
||||
// suggest using Reflect methods where applicable
|
||||
"prefer-reflect": 0,
|
||||
// suggest using the spread operator instead of .apply()
|
||||
"prefer-spread": 0,
|
||||
// suggest using template literals instead of strings concatenation
|
||||
"prefer-template": 0, //TODO: enable on full migration to es6
|
||||
// disallow generator functions that do not have yield
|
||||
"require-yield": 0
|
||||
}
|
||||
}
|
||||
21
node_modules/rollup-plugin-web-worker-loader/LICENSE
generated
vendored
Normal file
21
node_modules/rollup-plugin-web-worker-loader/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2019 Dario Segura
|
||||
|
||||
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.
|
||||
101
node_modules/rollup-plugin-web-worker-loader/README.md
generated
vendored
Normal file
101
node_modules/rollup-plugin-web-worker-loader/README.md
generated
vendored
Normal file
@@ -0,0 +1,101 @@
|
||||
# rollup-plugin-web-worker-loader
|
||||
|
||||
Rollup plugin to handle Web Workers.
|
||||
|
||||
Can inline the worker code or emit a script file using code-splitting.
|
||||
Handles Worker dependencies and can emit source maps.
|
||||
Worker dependencies are added to Rollup's watch list.
|
||||
Supports bundling workers for Node.js environments
|
||||
|
||||
### Getting started
|
||||
|
||||
```
|
||||
yarn add rollup-plugin-web-worker-loader --dev
|
||||
```
|
||||
|
||||
Add the plugin to your rollup configuration:
|
||||
|
||||
```javascript
|
||||
import webWorkerLoader from 'rollup-plugin-web-worker-loader';
|
||||
|
||||
export default {
|
||||
entry: 'src/index.js',
|
||||
plugins: [
|
||||
webWorkerLoader(/* configuration */),
|
||||
],
|
||||
format: 'esm',
|
||||
};
|
||||
```
|
||||
|
||||
Bundle the worker code using the RegEx pattern specified in the plugin's configuration.
|
||||
By default you can add the prefix `web-worker:` to your imports:
|
||||
|
||||
```javascript
|
||||
// here we use the default pattern but any RegEx can be configured
|
||||
import DataWorker from 'web-worker:./DataWorker';
|
||||
|
||||
const dataWorker = new DataWorker();
|
||||
dataWorker.postMessage('Hello World!');
|
||||
```
|
||||
|
||||
### Configuration
|
||||
The plugin responds to the following configuration options:
|
||||
```javascript
|
||||
webWorkerLoader({
|
||||
targetPlatform?: string, // The platform workers should be built for, can be 'auto', 'browser' or 'node'.
|
||||
// specifying either 'browser' or 'node' reduces the amount of loader code.
|
||||
// Default: 'auto'
|
||||
|
||||
pattern?: RegEx, // A RegEx instance describing the pattern that matches the files to import as
|
||||
// web workers. If capturing groups are present, the plugin uses the contents of the
|
||||
// last capturing group as the path to the worker script. Default: /web-worker:(.+)/
|
||||
|
||||
extensions?: string[], // An array of strings to use as extensions when resolving worker files.
|
||||
// Default: ['.js']
|
||||
|
||||
|
||||
sourcemap?: boolean, // When inlined, should a source map be included in the final output. Default: false
|
||||
|
||||
inline?: boolean, // Should the worker code be inlined (Base64). Default: true
|
||||
|
||||
forceInline?: boolean, // *EXPERIMENTAL* when inlined, forces the code to be included every time it is imported
|
||||
// useful when using code splitting: Default: false
|
||||
|
||||
preserveSource?: boolean, // When inlined and this option is enabled, the full source code is included in the
|
||||
// built file, otherwise it's embedded as a base64 string. Default: false
|
||||
|
||||
enableUnicodeSupport?: boolean, // When inlined in Base64 format, this option enables unicode support (UTF16). This
|
||||
// flag is disabled by default because supporting UTF16 doubles the size of the final
|
||||
// payload. Default: false
|
||||
|
||||
outputFolder?: string, // When code splitting is used (`inline: false`), folder in which the worker scripts
|
||||
// should be written to. Default: '' (same as build output folder)
|
||||
|
||||
loadPath?: string, // This option is useful when the worker scripts need to be loaded from another folder.
|
||||
// Default: ''
|
||||
|
||||
skipPlugins?: Array // Plugin names to skip for web worker build
|
||||
// Default: [ 'liveServer', 'serve', 'livereload' ]
|
||||
})
|
||||
```
|
||||
|
||||
### TypeScript
|
||||
An example project that uses this plugin with TypeScript can be found [here](https://github.com/darionco/rollup-typescript-webworkers)
|
||||
|
||||
### Notes
|
||||
**WARNING:** To use code-splitting for the worker scripts, Rollup v1.9.2 or higher is required. See https://github.com/rollup/rollup/issues/2801 for more details.
|
||||
|
||||
The `sourcemap` configuration option is ignored when `inline` is set to `false`, in that case the project's sourcemap configuration is inherited.
|
||||
|
||||
`loadPath` is meant to be used in situations where code-splitting is used (`inline = false`) and the entry script is hosted in a different folder than the worker code.
|
||||
|
||||
|
||||
### Roadmap
|
||||
- [x] Bundle file as web worker blob
|
||||
- [x] Support for dependencies using `import`
|
||||
- [x] Include source map
|
||||
- [x] Configuration options to inline or code-split workers
|
||||
- [ ] ~~Provide capability checks and fallbacks~~ DROPPED (all modern environments support workers)
|
||||
- [ ] ~~Avoid code duplication~~ DROPPED (there are better solutions for this purpose)
|
||||
|
||||
|
||||
63
node_modules/rollup-plugin-web-worker-loader/package.json
generated
vendored
Normal file
63
node_modules/rollup-plugin-web-worker-loader/package.json
generated
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"rollup-plugin-web-worker-loader@1.4.0",
|
||||
"J:\\Github\\CURD-TS"
|
||||
]
|
||||
],
|
||||
"_development": true,
|
||||
"_from": "rollup-plugin-web-worker-loader@1.4.0",
|
||||
"_id": "rollup-plugin-web-worker-loader@1.4.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-tP1xERh1jCERww55Ti8nV7daJ7g=",
|
||||
"_location": "/rollup-plugin-web-worker-loader",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "rollup-plugin-web-worker-loader@1.4.0",
|
||||
"name": "rollup-plugin-web-worker-loader",
|
||||
"escapedName": "rollup-plugin-web-worker-loader",
|
||||
"rawSpec": "1.4.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "1.4.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/vite"
|
||||
],
|
||||
"_resolved": "http://192.168.250.101:4873/rollup-plugin-web-worker-loader/-/rollup-plugin-web-worker-loader-1.4.0.tgz",
|
||||
"_spec": "1.4.0",
|
||||
"_where": "J:\\Github\\CURD-TS",
|
||||
"author": {
|
||||
"name": "Dario Segura"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/darionco/rollup-plugin-web-worker-loader/issues"
|
||||
},
|
||||
"description": "Rollup plugin to handle Web Workers",
|
||||
"devDependencies": {
|
||||
"eslint": "^7.9.0"
|
||||
},
|
||||
"homepage": "https://github.com/darionco/rollup-plugin-web-worker-loader#readme",
|
||||
"keywords": [
|
||||
"rollup",
|
||||
"rollup-plugin",
|
||||
"webworker",
|
||||
"web-worker",
|
||||
"worker"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "src/index.js",
|
||||
"name": "rollup-plugin-web-worker-loader",
|
||||
"peerDependencies": {
|
||||
"rollup": "^1.9.2 || ^2.0.0"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/darionco/rollup-plugin-web-worker-loader.git"
|
||||
},
|
||||
"scripts": {
|
||||
"lint": "eslint src/**/*.js"
|
||||
},
|
||||
"version": "1.4.0"
|
||||
}
|
||||
10
node_modules/rollup-plugin-web-worker-loader/src/helper/auto/createBase64WorkerFactory.js
generated
vendored
Normal file
10
node_modules/rollup-plugin-web-worker-loader/src/helper/auto/createBase64WorkerFactory.js
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
import {createBase64WorkerFactory as nodeCreateBase64WorkerFactory} from '\0rollup-plugin-web-worker-loader::helper::node::createBase64WorkerFactory';
|
||||
import {createBase64WorkerFactory as browserCreateBase64WorkerFactory} from '\0rollup-plugin-web-worker-loader::helper::browser::createBase64WorkerFactory';
|
||||
import {isNodeJS} from '\0rollup-plugin-web-worker-loader::helper::auto::isNodeJS';
|
||||
|
||||
export function createBase64WorkerFactory(base64, sourcemapArg, enableUnicodeArg) {
|
||||
if (isNodeJS()) {
|
||||
return nodeCreateBase64WorkerFactory(base64, sourcemapArg, enableUnicodeArg);
|
||||
}
|
||||
return browserCreateBase64WorkerFactory(base64, sourcemapArg, enableUnicodeArg);
|
||||
}
|
||||
10
node_modules/rollup-plugin-web-worker-loader/src/helper/auto/createInlineWorkerFactory.js
generated
vendored
Normal file
10
node_modules/rollup-plugin-web-worker-loader/src/helper/auto/createInlineWorkerFactory.js
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
import {createInlineWorkerFactory as nodeCreateInlineWorkerFactory} from '\0rollup-plugin-web-worker-loader::helper::node::createInlineWorkerFactory';
|
||||
import {createInlineWorkerFactory as browserCreateInlineWorkerFactory} from '\0rollup-plugin-web-worker-loader::helper::browser::createInlineWorkerFactory';
|
||||
import {isNodeJS} from '\0rollup-plugin-web-worker-loader::helper::auto::isNodeJS';
|
||||
|
||||
export function createInlineWorkerFactory(fn, sourcemapArg) {
|
||||
if (isNodeJS()) {
|
||||
return nodeCreateInlineWorkerFactory(fn, sourcemapArg);
|
||||
}
|
||||
return browserCreateInlineWorkerFactory(fn, sourcemapArg);
|
||||
}
|
||||
10
node_modules/rollup-plugin-web-worker-loader/src/helper/auto/createURLWorkerFactory.js
generated
vendored
Normal file
10
node_modules/rollup-plugin-web-worker-loader/src/helper/auto/createURLWorkerFactory.js
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
import {createURLWorkerFactory as nodeCreateURLWorkerFactory} from '\0rollup-plugin-web-worker-loader::helper::node::createURLWorkerFactory';
|
||||
import {createURLWorkerFactory as browserCreateURLWorkerFactory} from '\0rollup-plugin-web-worker-loader::helper::browser::createURLWorkerFactory';
|
||||
import {isNodeJS} from '\0rollup-plugin-web-worker-loader::helper::auto::isNodeJS';
|
||||
|
||||
export function createURLWorkerFactory(url) {
|
||||
if (isNodeJS()) {
|
||||
return nodeCreateURLWorkerFactory(url);
|
||||
}
|
||||
return browserCreateURLWorkerFactory(url);
|
||||
}
|
||||
5
node_modules/rollup-plugin-web-worker-loader/src/helper/auto/isNodeJS.js
generated
vendored
Normal file
5
node_modules/rollup-plugin-web-worker-loader/src/helper/auto/isNodeJS.js
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
var kIsNodeJS = Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]';
|
||||
|
||||
export function isNodeJS() {
|
||||
return kIsNodeJS;
|
||||
}
|
||||
29
node_modules/rollup-plugin-web-worker-loader/src/helper/browser/createBase64WorkerFactory.js
generated
vendored
Normal file
29
node_modules/rollup-plugin-web-worker-loader/src/helper/browser/createBase64WorkerFactory.js
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
function decodeBase64(base64, enableUnicode) {
|
||||
var binaryString = atob(base64);
|
||||
if (enableUnicode) {
|
||||
var binaryView = new Uint8Array(binaryString.length);
|
||||
for (var i = 0, n = binaryString.length; i < n; ++i) {
|
||||
binaryView[i] = binaryString.charCodeAt(i);
|
||||
}
|
||||
return String.fromCharCode.apply(null, new Uint16Array(binaryView.buffer));
|
||||
}
|
||||
return binaryString;
|
||||
}
|
||||
|
||||
function createURL(base64, sourcemapArg, enableUnicodeArg) {
|
||||
var sourcemap = sourcemapArg === undefined ? null : sourcemapArg;
|
||||
var enableUnicode = enableUnicodeArg === undefined ? false : enableUnicodeArg;
|
||||
var source = decodeBase64(base64, enableUnicode);
|
||||
var start = source.indexOf('\n', 10) + 1;
|
||||
var body = source.substring(start) + (sourcemap ? '\/\/# sourceMappingURL=' + sourcemap : '');
|
||||
var blob = new Blob([body], { type: 'application/javascript' });
|
||||
return URL.createObjectURL(blob);
|
||||
}
|
||||
|
||||
export function createBase64WorkerFactory(base64, sourcemapArg, enableUnicodeArg) {
|
||||
var url;
|
||||
return function WorkerFactory(options) {
|
||||
url = url || createURL(base64, sourcemapArg, enableUnicodeArg);
|
||||
return new Worker(url, options);
|
||||
};
|
||||
}
|
||||
15
node_modules/rollup-plugin-web-worker-loader/src/helper/browser/createInlineWorkerFactory.js
generated
vendored
Normal file
15
node_modules/rollup-plugin-web-worker-loader/src/helper/browser/createInlineWorkerFactory.js
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
import {funcToSource} from '\0rollup-plugin-web-worker-loader::helper::funcToSource';
|
||||
|
||||
function createURL(fn, sourcemapArg) {
|
||||
var lines = funcToSource(fn, sourcemapArg);
|
||||
var blob = new Blob(lines, { type: 'application/javascript' });
|
||||
return URL.createObjectURL(blob);
|
||||
}
|
||||
|
||||
export function createInlineWorkerFactory(fn, sourcemapArg) {
|
||||
var url;
|
||||
return function WorkerFactory(options) {
|
||||
url = url || createURL(fn, sourcemapArg);
|
||||
return new Worker(url, options);
|
||||
};
|
||||
}
|
||||
5
node_modules/rollup-plugin-web-worker-loader/src/helper/browser/createURLWorkerFactory.js
generated
vendored
Normal file
5
node_modules/rollup-plugin-web-worker-loader/src/helper/browser/createURLWorkerFactory.js
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
export function createURLWorkerFactory(url) {
|
||||
return function WorkerFactory(options) {
|
||||
return new Worker(url, options);
|
||||
};
|
||||
}
|
||||
16
node_modules/rollup-plugin-web-worker-loader/src/helper/funcToSource.js
generated
vendored
Normal file
16
node_modules/rollup-plugin-web-worker-loader/src/helper/funcToSource.js
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
export function funcToSource(fn, sourcemapArg) {
|
||||
var sourcemap = sourcemapArg === undefined ? null : sourcemapArg;
|
||||
var source = fn.toString();
|
||||
var lines = source.split('\n');
|
||||
lines.pop();
|
||||
lines.shift();
|
||||
var blankPrefixLength = lines[0].search(/\S/);
|
||||
var regex = /(['"])__worker_loader_strict__(['"])/g;
|
||||
for (var i = 0, n = lines.length; i < n; ++i) {
|
||||
lines[i] = lines[i].substring(blankPrefixLength).replace(regex, '$1use strict$2') + '\n';
|
||||
}
|
||||
if (sourcemap) {
|
||||
lines.push('\/\/# sourceMappingURL=' + sourcemap + '\n');
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
11
node_modules/rollup-plugin-web-worker-loader/src/helper/node/WorkerClass.js
generated
vendored
Normal file
11
node_modules/rollup-plugin-web-worker-loader/src/helper/node/WorkerClass.js
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
var WorkerClass = null;
|
||||
|
||||
try {
|
||||
var WorkerThreads =
|
||||
typeof module !== 'undefined' && typeof module.require === 'function' && module.require('worker_threads') ||
|
||||
typeof __non_webpack_require__ === 'function' && __non_webpack_require__('worker_threads') ||
|
||||
typeof require === 'function' && require('worker_threads');
|
||||
WorkerClass = WorkerThreads.Worker;
|
||||
} catch(e) {} // eslint-disable-line
|
||||
|
||||
export {WorkerClass};
|
||||
16
node_modules/rollup-plugin-web-worker-loader/src/helper/node/createBase64WorkerFactory.js
generated
vendored
Normal file
16
node_modules/rollup-plugin-web-worker-loader/src/helper/node/createBase64WorkerFactory.js
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
import {WorkerClass} from '\0rollup-plugin-web-worker-loader::helper::node::WorkerClass';
|
||||
|
||||
function decodeBase64(base64, enableUnicode) {
|
||||
return Buffer.from(base64, 'base64').toString(enableUnicode ? 'utf16' : 'utf8');
|
||||
}
|
||||
|
||||
export function createBase64WorkerFactory(base64, sourcemapArg, enableUnicodeArg) {
|
||||
var sourcemap = sourcemapArg === undefined ? null : sourcemapArg;
|
||||
var enableUnicode = enableUnicodeArg === undefined ? false : enableUnicodeArg;
|
||||
var source = decodeBase64(base64, enableUnicode);
|
||||
var start = source.indexOf('\n', 10) + 1;
|
||||
var body = source.substring(start) + (sourcemap ? '\/\/# sourceMappingURL=' + sourcemap : '');
|
||||
return function WorkerFactory(options) {
|
||||
return new WorkerClass(body, Object.assign({}, options, { eval: true }));
|
||||
};
|
||||
}
|
||||
10
node_modules/rollup-plugin-web-worker-loader/src/helper/node/createInlineWorkerFactory.js
generated
vendored
Normal file
10
node_modules/rollup-plugin-web-worker-loader/src/helper/node/createInlineWorkerFactory.js
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
import {funcToSource} from '\0rollup-plugin-web-worker-loader::helper::funcToSource';
|
||||
import {WorkerClass} from '\0rollup-plugin-web-worker-loader::helper::node::WorkerClass';
|
||||
|
||||
export function createInlineWorkerFactory(fn, sourcemapArg) {
|
||||
var lines = funcToSource(fn, sourcemapArg);
|
||||
var concat = lines.join('\n');
|
||||
return function WorkerFactory(options) {
|
||||
return new WorkerClass(concat, Object.assign({}, options, { eval: true }));
|
||||
};
|
||||
}
|
||||
7
node_modules/rollup-plugin-web-worker-loader/src/helper/node/createURLWorkerFactory.js
generated
vendored
Normal file
7
node_modules/rollup-plugin-web-worker-loader/src/helper/node/createURLWorkerFactory.js
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
import {WorkerClass} from '\0rollup-plugin-web-worker-loader::helper::node::WorkerClass';
|
||||
|
||||
export function createURLWorkerFactory(url) {
|
||||
return function WorkerFactory(options) {
|
||||
return new WorkerClass(url, options);
|
||||
};
|
||||
}
|
||||
66
node_modules/rollup-plugin-web-worker-loader/src/index.js
generated
vendored
Normal file
66
node_modules/rollup-plugin-web-worker-loader/src/index.js
generated
vendored
Normal file
@@ -0,0 +1,66 @@
|
||||
const options = require('./plugin/options');
|
||||
const resolveId = require('./plugin/resolveId');
|
||||
const load = require('./plugin/load');
|
||||
const transform = require('./plugin/transform');
|
||||
const outputOptions = require('./plugin/outputOptions');
|
||||
const generateBundle = require('./plugin/generateBundle');
|
||||
|
||||
const defaultConfig = {
|
||||
targetPlatform: 'auto',
|
||||
sourcemap: 'false',
|
||||
loadPath: '',
|
||||
preserveSource: false,
|
||||
enableUnicode: false,
|
||||
pattern: /web-worker:(.+)/,
|
||||
inline: true,
|
||||
forceInline: false,
|
||||
extensions: [ '.js' ],
|
||||
outputFolder: '',
|
||||
skipPlugins: [
|
||||
'liveServer',
|
||||
'serve',
|
||||
'livereload',
|
||||
],
|
||||
};
|
||||
|
||||
module.exports = function workerLoaderPlugin(userConfig = null) {
|
||||
const config = Object.assign({}, defaultConfig, userConfig);
|
||||
config.skipPlugins = new Set(config.skipPlugins);
|
||||
|
||||
const state = {
|
||||
idMap: new Map(),
|
||||
exclude: new Set(),
|
||||
options: null,
|
||||
basePath: null,
|
||||
forceInlineCounter: 0,
|
||||
configuredFileName: null,
|
||||
};
|
||||
|
||||
return {
|
||||
name: 'rollup-plugin-web-worker-loader',
|
||||
|
||||
options(optionsArg) {
|
||||
return options(state, config, optionsArg);
|
||||
},
|
||||
|
||||
resolveId(importee, importer) {
|
||||
return resolveId(state, config, importee, importer);
|
||||
},
|
||||
|
||||
load(id) {
|
||||
return load(state, config, this.addWatchFile, id);
|
||||
},
|
||||
|
||||
transform(code, id) {
|
||||
return transform(state, config, code, id);
|
||||
},
|
||||
|
||||
outputOptions(options) {
|
||||
return outputOptions(state, config, options);
|
||||
},
|
||||
|
||||
generateBundle(options, bundle, isWrite) {
|
||||
generateBundle(state, config, options, bundle, isWrite);
|
||||
},
|
||||
};
|
||||
};
|
||||
14
node_modules/rollup-plugin-web-worker-loader/src/plugin/generateBundle.js
generated
vendored
Normal file
14
node_modules/rollup-plugin-web-worker-loader/src/plugin/generateBundle.js
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
function generateBundle(state, config, options, bundle, isWrite) {
|
||||
if (!config.inline && isWrite) {
|
||||
if (state.configuredFileName && Object.keys(bundle).length === 1) {
|
||||
bundle[Object.keys(bundle)[0]].fileName = state.configuredFileName;
|
||||
}
|
||||
for (const worker of state.idMap) {
|
||||
if (worker[1].chunk && !bundle[worker[1].workerID]) {
|
||||
bundle[worker[1].workerID] = worker[1].chunk;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = generateBundle;
|
||||
95
node_modules/rollup-plugin-web-worker-loader/src/plugin/load.js
generated
vendored
Normal file
95
node_modules/rollup-plugin-web-worker-loader/src/plugin/load.js
generated
vendored
Normal file
@@ -0,0 +1,95 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const rollup = require('rollup');
|
||||
const fixMapSources = require('../utils/fixMapSources');
|
||||
const extractSource = require('../utils/extractSource');
|
||||
const buildWorkerCode = require('../utils/buildWorkerCode');
|
||||
|
||||
const helperPattern = /^\0(?:[0-9]+::)?rollup-plugin-web-worker-loader::helper(?:::)?/;
|
||||
|
||||
function loadHelperFile(id, match, resolve, reject) {
|
||||
const helperParts = id.substr(match[0].length).split('::');
|
||||
const helperPath = path.resolve(__dirname, '../helper', ...helperParts) + '.js';
|
||||
fs.readFile(helperPath, 'utf8', (err, data) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
}
|
||||
resolve(data);
|
||||
});
|
||||
}
|
||||
|
||||
function findChunk(rollupOutput) {
|
||||
for (const chunk of rollupOutput) {
|
||||
if (!chunk.isAsset) { // here to support older rollup versions will be removed soon
|
||||
return chunk;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function updateWatchModules(modules, addWatchFile) {
|
||||
/* add dependencies to watch list */
|
||||
const deps = Object.keys(modules);
|
||||
for (const dep of deps) {
|
||||
addWatchFile(dep);
|
||||
}
|
||||
}
|
||||
|
||||
function handleBundleGenerated(state, config, addWatchFile, id, workerID, result) {
|
||||
const chunk = findChunk(result.output);
|
||||
if (chunk !== null) {
|
||||
updateWatchModules(chunk.modules, addWatchFile);
|
||||
|
||||
let map = null;
|
||||
let source;
|
||||
if (config.inline) {
|
||||
source = extractSource(chunk.code, config.preserveSource);
|
||||
map = null;
|
||||
if (config.sourcemap) {
|
||||
map = fixMapSources(chunk, state.basePath);
|
||||
}
|
||||
} else {
|
||||
const workerPath = path.posix.join(config.outputFolder, workerID);
|
||||
source = path.posix.join(config.loadPath, workerPath);
|
||||
chunk.fileName = workerPath;
|
||||
state.idMap.get(id).chunk = chunk;
|
||||
}
|
||||
return {
|
||||
code: buildWorkerCode(source, map, {
|
||||
inline: config.inline,
|
||||
preserveSource: config.preserveSource,
|
||||
enableUnicode: config.enableUnicode,
|
||||
targetPlatform: config.targetPlatform,
|
||||
}),
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function load(state, config, addWatchFile, id) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const helperMatch = helperPattern.exec(id);
|
||||
if (helperMatch) {
|
||||
loadHelperFile(id, helperMatch, resolve, reject);
|
||||
} else if (state.idMap.has(id) && !state.exclude.has(id)) {
|
||||
const {inputOptions, workerID, target} = state.idMap.get(id);
|
||||
state.exclude.add(id);
|
||||
state.exclude.add(target);
|
||||
rollup.rollup(inputOptions).then(bundle => {
|
||||
state.exclude.delete(id);
|
||||
state.exclude.delete(target);
|
||||
bundle.generate({format: 'iife', name: 'worker_code', sourcemap: true}).then(result => {
|
||||
resolve(handleBundleGenerated(state, config, addWatchFile, id, workerID, result));
|
||||
}).catch(reject);
|
||||
}).catch(reason => {
|
||||
state.exclude.delete(id);
|
||||
state.exclude.delete(target);
|
||||
reject(reason);
|
||||
});
|
||||
} else {
|
||||
resolve(null);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = load;
|
||||
65
node_modules/rollup-plugin-web-worker-loader/src/plugin/options.js
generated
vendored
Normal file
65
node_modules/rollup-plugin-web-worker-loader/src/plugin/options.js
generated
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
const path = require('path');
|
||||
|
||||
function optionsImp(state, config, options) {
|
||||
if (!state.options) {
|
||||
state.options = Object.assign({}, options);
|
||||
if (options.plugins && options.plugins.length) {
|
||||
const plugins = [];
|
||||
options.plugins.forEach(plugin => {
|
||||
if (config.skipPlugins.has(plugin.name)) {
|
||||
return;
|
||||
}
|
||||
plugins.push(plugin);
|
||||
});
|
||||
state.options.plugins = plugins;
|
||||
|
||||
const cwd = process.cwd();
|
||||
if (typeof options.input === 'string') {
|
||||
try {
|
||||
const entry = require.resolve(options.input, { paths: [cwd] });
|
||||
state.basePath = path.dirname(entry);
|
||||
} catch (e) { /* EMPTY */ }
|
||||
} else if (Array.isArray(options.input)) {
|
||||
let componentCount = Number.MAX_SAFE_INTEGER;
|
||||
let shortestPath = null;
|
||||
for (let i = 0, n = options.input.length; i < n; ++i) {
|
||||
try {
|
||||
const entry = require.resolve(options.input[i], { paths: [cwd] });
|
||||
const entryPath = path.dirname(entry);
|
||||
const components = entryPath.split(path.sep);
|
||||
if (components.length < componentCount) {
|
||||
componentCount = components.length;
|
||||
shortestPath = entryPath;
|
||||
}
|
||||
} catch (e) { /* EMPTY */ }
|
||||
}
|
||||
state.basePath = shortestPath;
|
||||
} else {
|
||||
const keys = Object.keys(options.input);
|
||||
let componentCount = Number.MAX_SAFE_INTEGER;
|
||||
let shortestPath = null;
|
||||
for (let i = 0, n = keys.length; i < n; ++i) {
|
||||
const input = options.input[keys[i]];
|
||||
try {
|
||||
const entry = require.resolve(input, { paths: [cwd] });
|
||||
const entryPath = path.dirname(entry);
|
||||
const components = entryPath.split(path.sep);
|
||||
if (components.length < componentCount) {
|
||||
componentCount = components.length;
|
||||
shortestPath = entryPath;
|
||||
}
|
||||
} catch (e) { /* EMPTY */ }
|
||||
}
|
||||
state.basePath = shortestPath;
|
||||
}
|
||||
|
||||
if (!state.basePath) {
|
||||
state.basePath = '.';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
module.exports = optionsImp;
|
||||
14
node_modules/rollup-plugin-web-worker-loader/src/plugin/outputOptions.js
generated
vendored
Normal file
14
node_modules/rollup-plugin-web-worker-loader/src/plugin/outputOptions.js
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
const path = require('path');
|
||||
|
||||
function outputOptions(state, config, options) {
|
||||
if (!config.inline && options.file && !options.dir) {
|
||||
state.configuredFileName = path.basename(options.file);
|
||||
return Object.assign({}, options, {
|
||||
file: null,
|
||||
dir: path.dirname(options.file),
|
||||
});
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
module.exports = outputOptions;
|
||||
65
node_modules/rollup-plugin-web-worker-loader/src/plugin/resolveId.js
generated
vendored
Normal file
65
node_modules/rollup-plugin-web-worker-loader/src/plugin/resolveId.js
generated
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
const path = require('path');
|
||||
|
||||
function resolveModule(name, paths, extensions) {
|
||||
const testNames = [
|
||||
name,
|
||||
...extensions.map(extension => (extension.startsWith('.') ? `${name}${extension}` : `${name}.${extension}`)),
|
||||
];
|
||||
|
||||
for (let i = 0, n = testNames.length; i < n; ++i) {
|
||||
try {
|
||||
return require.resolve(testNames[i], {paths});
|
||||
} catch (e) {
|
||||
// empty
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function resolveId(state, config, importee, importer) {
|
||||
const match = importee.match(config.pattern);
|
||||
if (importee.startsWith('\0rollup-plugin-web-worker-loader::helper')) {
|
||||
if (config.forceInline) {
|
||||
return `\0${state.forceInlineCounter++}::${importee.substr(1)}`;
|
||||
}
|
||||
return importee;
|
||||
} else if (match && match.length) {
|
||||
const name = match[match.length - 1];
|
||||
if (!state.idMap.has(name)) {
|
||||
let target = null;
|
||||
if (importer) {
|
||||
const folder = path.dirname(importer);
|
||||
const paths = require.resolve.paths(importer);
|
||||
paths.push(folder);
|
||||
target = resolveModule(name, paths, config.extensions);
|
||||
} else if (path.isAbsolute(name)) {
|
||||
target = name;
|
||||
}
|
||||
|
||||
if (target) {
|
||||
const prefixed = `\0rollup-plugin-worker-loader::module:${config.forceInline ? `:${state.forceInlineCounter++}:` : ''}${target}`;
|
||||
if (!state.idMap.has(prefixed)) {
|
||||
const inputOptions = Object.assign({}, state.options, {
|
||||
input: target,
|
||||
});
|
||||
|
||||
state.idMap.set(prefixed, {
|
||||
workerID: `web-worker-${state.idMap.size}.js`,
|
||||
chunk: null,
|
||||
inputOptions,
|
||||
target,
|
||||
});
|
||||
}
|
||||
|
||||
if (!state.exclude.has(prefixed)) {
|
||||
return prefixed;
|
||||
}
|
||||
return target;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
module.exports = resolveId;
|
||||
11
node_modules/rollup-plugin-web-worker-loader/src/plugin/transform.js
generated
vendored
Normal file
11
node_modules/rollup-plugin-web-worker-loader/src/plugin/transform.js
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
const path = require('path');
|
||||
|
||||
function transform(state, config, code, id) {
|
||||
if (state.idMap.has(id) && !state.exclude.has(id)) {
|
||||
const {inputOptions} = state.idMap.get(id);
|
||||
return { code, map: `{"version":3,"file":"${path.basename(inputOptions.input)}","sources":[],"sourcesContent":[],"names":[],"mappings":""}` };
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
module.exports = transform;
|
||||
42
node_modules/rollup-plugin-web-worker-loader/src/utils/buildWorkerCode.js
generated
vendored
Normal file
42
node_modules/rollup-plugin-web-worker-loader/src/utils/buildWorkerCode.js
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
const kDefaultsOptions = {
|
||||
inline: true,
|
||||
preserveSource: false,
|
||||
enableUnicode: false,
|
||||
targetPlatform: 'browser',
|
||||
};
|
||||
|
||||
function getFactoryFuncName(options) {
|
||||
if (options.inline) {
|
||||
if (options.preserveSource) {
|
||||
return 'createInlineWorkerFactory';
|
||||
}
|
||||
return 'createBase64WorkerFactory';
|
||||
}
|
||||
return 'createURLWorkerFactory';
|
||||
}
|
||||
|
||||
function getArgsString(source, sourcemap, options) {
|
||||
if (options.inline) {
|
||||
const sourcemapArg = sourcemap ? `'${sourcemap.toUrl()}'` : 'null';
|
||||
if (options.preserveSource) {
|
||||
return `${source.substring(0, source.length - 1)}, ${sourcemapArg}`;
|
||||
}
|
||||
const sourceArg = Buffer.from(source, options.enableUnicode ? 'utf16le' : 'utf8').toString('base64');
|
||||
return `'${sourceArg}', ${sourcemapArg}, ${options.enableUnicode.toString()}`;
|
||||
}
|
||||
return `'${source}'`;
|
||||
}
|
||||
|
||||
function buildWorkerCode(source, sourcemap = null, optionsArg = kDefaultsOptions) {
|
||||
const options = Object.assign({}, kDefaultsOptions, optionsArg);
|
||||
const factoryFuncName = getFactoryFuncName(options);
|
||||
const argsString = getArgsString(source, sourcemap, options);
|
||||
return `
|
||||
/* eslint-disable */
|
||||
import {${factoryFuncName}} from '\0rollup-plugin-web-worker-loader::helper::${options.targetPlatform}::${factoryFuncName}';
|
||||
var WorkerFactory = ${factoryFuncName}(${argsString});
|
||||
export default WorkerFactory;
|
||||
/* eslint-enable */\n`;
|
||||
}
|
||||
|
||||
module.exports = buildWorkerCode;
|
||||
10
node_modules/rollup-plugin-web-worker-loader/src/utils/extractSource.js
generated
vendored
Normal file
10
node_modules/rollup-plugin-web-worker-loader/src/utils/extractSource.js
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
function extractSource(code, asFunction = true) {
|
||||
if (asFunction) {
|
||||
return `/* rollup-plugin-web-worker-loader */function () {\n${
|
||||
code.replace(/(['"])use strict(['"])/g, '$1__worker_loader_strict__$2')
|
||||
}}\n`;
|
||||
}
|
||||
return `/* rollup-plugin-web-worker-loader */\n${code}\n`;
|
||||
}
|
||||
|
||||
module.exports = extractSource;
|
||||
57
node_modules/rollup-plugin-web-worker-loader/src/utils/fixMapSources.js
generated
vendored
Normal file
57
node_modules/rollup-plugin-web-worker-loader/src/utils/fixMapSources.js
generated
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
const path = require('path');
|
||||
|
||||
function findFullPath(file, length, modules) {
|
||||
const keys = Object.keys(modules);
|
||||
for (let i = 0; i < keys.length; ++i) {
|
||||
if (keys[i].endsWith(file) && modules[keys[i]].originalLength === length) {
|
||||
return keys[i];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function fixMapSources(chunk, basePath) {
|
||||
const map = chunk.map;
|
||||
const newSourcesComponents = [];
|
||||
let maxUpFolder = 0;
|
||||
for (let i = 0; i < map.sources.length; ++i) {
|
||||
const full = findFullPath(map.sources[i], map.sourcesContent[i].length, chunk.modules);
|
||||
if (full) {
|
||||
const relative = path.relative(basePath, full);
|
||||
const base = path.dirname(relative);
|
||||
const components = base.split(path.sep);
|
||||
const newComponents = [];
|
||||
let upFolder = 0;
|
||||
for (let component of components) {
|
||||
if (component === '..') {
|
||||
++upFolder;
|
||||
} else {
|
||||
newComponents.push(component);
|
||||
}
|
||||
}
|
||||
newComponents.push(path.basename(full));
|
||||
maxUpFolder = Math.max(maxUpFolder, upFolder);
|
||||
|
||||
newSourcesComponents[i] = newComponents;
|
||||
} else {
|
||||
newSourcesComponents[i] = null;
|
||||
}
|
||||
}
|
||||
|
||||
const basePathComponents = basePath.split(path.sep);
|
||||
const newBaseComponents = [];
|
||||
for (let i = 0; i < maxUpFolder; ++i) {
|
||||
newBaseComponents.unshift(basePathComponents.pop());
|
||||
}
|
||||
const newBase = path.resolve('/web-worker', ...newBaseComponents);
|
||||
|
||||
for (let i = 0; i < map.sources.length; ++i) {
|
||||
if (newSourcesComponents[i]) {
|
||||
map.sources[i] = 'worker:/' + path.resolve(newBase, ...newSourcesComponents[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
module.exports = fixMapSources;
|
||||
Reference in New Issue
Block a user