rollup-plugin-web-worker-loader
Advanced tools
Comparing version 1.5.0 to 1.6.0
{ | ||
"name": "rollup-plugin-web-worker-loader", | ||
"version": "1.5.0", | ||
"version": "1.6.0", | ||
"description": "Rollup plugin to handle Web Workers", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -45,4 +45,7 @@ # rollup-plugin-web-worker-loader | ||
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. | ||
targetPlatform?: string, // The platform workers should be built for, can be 'auto', 'browser', 'node' or 'base64'. | ||
// specifying a target platform other than 'auto' reduces the amount of loader code. | ||
// The `base64` options forces inline and the import results on a base64 string that | ||
// encodes the worker's source code. NOTE: The string does not include a mime type. | ||
// 'auto' detectes the target platform and selects between 'browser` and 'node'. | ||
// Default: 'auto' | ||
@@ -70,2 +73,6 @@ | ||
// built file, otherwise it's embedded as a base64 string. Default: false | ||
preserveFileNames?: boolean, // When code splitting is used (`inline === false`) the input worker file names are | ||
// preserved, if duplicates are found `-n` is appended to the file names. | ||
// Default: false | ||
@@ -97,3 +104,5 @@ enableUnicodeSupport?: boolean, // When inlined in Base64 format, this option enables unicode support (UTF16). This | ||
Setting `targetPlatform` to `'base64'` will ignore the `inline` option and will always inline the resulting code. | ||
### Roadmap | ||
@@ -100,0 +109,0 @@ - [x] Bundle file as web worker blob |
@@ -13,2 +13,3 @@ const options = require('./plugin/options'); | ||
preserveSource: false, | ||
preserveFileNames: false, | ||
enableUnicode: false, | ||
@@ -35,2 +36,3 @@ pattern: /web-worker:(.+)/, | ||
exclude: new Set(), | ||
outFiles: new Map(), | ||
options: null, | ||
@@ -37,0 +39,0 @@ basePath: null, |
@@ -45,3 +45,3 @@ const fs = require('fs'); | ||
let source; | ||
if (config.inline) { | ||
if (config.inline || config.targetPlatform === 'base64') { | ||
source = extractSource(chunk.code, config.preserveSource); | ||
@@ -48,0 +48,0 @@ map = null; |
@@ -47,4 +47,19 @@ const path = require('path'); | ||
let workerName; | ||
if (config.preserveFileNames) { | ||
const extension = path.extname(target); | ||
workerName = path.basename(target, extension); | ||
if (!state.outFiles.has(workerName)) { | ||
state.outFiles.set(workerName, 0); | ||
} else { | ||
const duplicateCount = state.outFiles.get(workerName); | ||
state.outFiles.set(workerName, duplicateCount + 1); | ||
workerName += duplicateCount + 1; | ||
} | ||
} else { | ||
workerName = `web-worker-${state.idMap.size}`; | ||
} | ||
state.idMap.set(prefixed, { | ||
workerID: `web-worker-${state.idMap.size}.js`, | ||
workerID: `${workerName}.js`, | ||
chunk: null, | ||
@@ -51,0 +66,0 @@ inputOptions, |
@@ -19,2 +19,6 @@ const kDefaultsOptions = { | ||
function getArgsString(source, sourcemap, options) { | ||
if (options.targetPlatform === 'base64') { | ||
return Buffer.from(source, options.enableUnicode ? 'utf16le' : 'utf8').toString('base64'); | ||
} | ||
if (options.inline) { | ||
@@ -31,6 +35,11 @@ const sourcemapArg = sourcemap ? `'${sourcemap.toUrl()}'` : 'null'; | ||
function buildWorkerCode(source, sourcemap = null, optionsArg = kDefaultsOptions) { | ||
const options = Object.assign({}, kDefaultsOptions, optionsArg); | ||
const factoryFuncName = getFactoryFuncName(options); | ||
const argsString = getArgsString(source, sourcemap, options); | ||
function buildWorkerSource(options, factoryFuncName, argsString) { | ||
if (options.targetPlatform === 'base64') { | ||
return ` | ||
/* eslint-disable */ | ||
var base64 = '${argsString}'; | ||
export default base64; | ||
/* eslint-enable */\n`; | ||
} | ||
return ` | ||
@@ -44,2 +53,9 @@ /* eslint-disable */ | ||
function buildWorkerCode(source, sourcemap = null, optionsArg = kDefaultsOptions) { | ||
const options = Object.assign({}, kDefaultsOptions, optionsArg); | ||
const factoryFuncName = getFactoryFuncName(options); | ||
const argsString = getArgsString(source, sourcemap, options); | ||
return buildWorkerSource(options, factoryFuncName, argsString); | ||
} | ||
module.exports = buildWorkerCode; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
49535
560
114