rollup-plugin-web-worker-loader
Advanced tools
Comparing version 0.3.1 to 0.4.0
{ | ||
"name": "rollup-plugin-web-worker-loader", | ||
"version": "0.3.1", | ||
"version": "0.4.0", | ||
"description": "Rollup plugin to handle Web Workers", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -7,3 +7,4 @@ # rollup-plugin-web-worker-loader | ||
Handles Worker dependencies and can emit source maps. | ||
Worker dependencies are added to Rollup's watch list. | ||
Worker dependencies are added to Rollup's watch list. | ||
Supports bundling workers for Node.js environments | ||
@@ -10,0 +11,0 @@ ### Getting started |
@@ -0,1 +1,4 @@ | ||
const kIsNodeJS = Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]'; | ||
const kRequire = kIsNodeJS ? module.require : null; // eslint-disable-line | ||
export function createInlineWorkerFactory(fn, sourcemap = null) { | ||
@@ -6,7 +9,8 @@ const source = fn.toString(); | ||
const body = source.substring(start, end) + (sourcemap ? `//# sourceMappingURL=${sourcemap}` : ''); | ||
const lines = body.split('\n').map(line => line.substring(4) + '\n'); | ||
const blankPrefixLength = body.search(/\S/); | ||
const lines = body.split('\n').map(line => line.substring(blankPrefixLength) + '\n'); | ||
if (Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]') { | ||
if (kIsNodeJS) { | ||
/* node.js */ | ||
const Worker = require('worker_threads').Worker; // eslint-disable-line | ||
const Worker = kRequire('worker_threads').Worker; // eslint-disable-line | ||
const concat = lines.join('\n'); | ||
@@ -27,5 +31,5 @@ return function WorkerFactory(options) { | ||
export function createURLWorkerFactory(url) { | ||
if (Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]') { | ||
if (kIsNodeJS) { | ||
/* node.js */ | ||
const Worker = require('worker_threads').Worker; // eslint-disable-line | ||
const Worker = kRequire('worker_threads').Worker; // eslint-disable-line | ||
return function WorkerFactory(options) { | ||
@@ -32,0 +36,0 @@ return new Worker(url, options); |
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
35254
290
66