Skip to content

Commit 9583f59

Browse files
committed
[CONFIG] Added support for base64 target platform.
1 parent cb66278 commit 9583f59

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

src/plugin/load.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function handleBundleGenerated(state, config, addWatchFile, id, workerID, result
4242

4343
let map = null;
4444
let source;
45-
if (config.inline) {
45+
if (config.inline || config.targetPlatform === 'base64') {
4646
source = extractSource(chunk.code, config.preserveSource);
4747
map = null;
4848
if (config.sourcemap) {

src/utils/buildWorkerCode.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ function getFactoryFuncName(options) {
1616
}
1717

1818
function getArgsString(source, sourcemap, options) {
19+
if (options.targetPlatform === 'base64') {
20+
return Buffer.from(source, options.enableUnicode ? 'utf16le' : 'utf8').toString('base64');
21+
}
22+
1923
if (options.inline) {
2024
const sourcemapArg = sourcemap ? `'${sourcemap.toUrl()}'` : 'null';
2125
if (options.preserveSource) {
@@ -27,10 +31,15 @@ function getArgsString(source, sourcemap, options) {
2731
return `'${source}'`;
2832
}
2933

30-
function buildWorkerCode(source, sourcemap = null, optionsArg = kDefaultsOptions) {
31-
const options = Object.assign({}, kDefaultsOptions, optionsArg);
32-
const factoryFuncName = getFactoryFuncName(options);
33-
const argsString = getArgsString(source, sourcemap, options);
34+
function buildWorkerSource(options, factoryFuncName, argsString) {
35+
if (options.targetPlatform === 'base64') {
36+
return `
37+
/* eslint-disable */
38+
var base64 = '${argsString}';
39+
export default base64;
40+
/* eslint-enable */\n`;
41+
}
42+
3443
return `
3544
/* eslint-disable */
3645
import {${factoryFuncName}} from '\0rollup-plugin-web-worker-loader::helper::${options.targetPlatform}::${factoryFuncName}';
@@ -39,4 +48,11 @@ export default WorkerFactory;
3948
/* eslint-enable */\n`;
4049
}
4150

51+
function buildWorkerCode(source, sourcemap = null, optionsArg = kDefaultsOptions) {
52+
const options = Object.assign({}, kDefaultsOptions, optionsArg);
53+
const factoryFuncName = getFactoryFuncName(options);
54+
const argsString = getArgsString(source, sourcemap, options);
55+
return buildWorkerSource(options, factoryFuncName, argsString);
56+
}
57+
4258
module.exports = buildWorkerCode;

0 commit comments

Comments
 (0)