diff --git a/packages/worker/.npmignore b/packages/worker/.npmignore index b4be6775d2..b33ab99fc9 100644 --- a/packages/worker/.npmignore +++ b/packages/worker/.npmignore @@ -1,4 +1,8 @@ * +!/bundle/worker.js +!/string/**/* +!/cjs/**/* +!/esm/**/* !/src/**/* /src/**/*.spec.ts /src/**/*.specHelper.ts diff --git a/packages/worker/scripts/build-worker-string.js b/packages/worker/scripts/build-worker-string.js index c84ce8f679..5ed129c060 100755 --- a/packages/worker/scripts/build-worker-string.js +++ b/packages/worker/scripts/build-worker-string.js @@ -5,7 +5,15 @@ const fs = require('fs') const bundlePath = path.resolve(__dirname, '../bundle') const workerBundlePath = path.join(bundlePath, 'worker.js') -const workerStringPath = path.join(bundlePath, 'workerString.ts') const workerBundleContent = fs.readFileSync(workerBundlePath, { encoding: 'utf-8' }) -fs.writeFileSync(workerStringPath, `export const workerString = ${JSON.stringify(workerBundleContent)}`) +const workerString = `${JSON.stringify(workerBundleContent)}\n` +writeOutput('cjs', `exports.workerString = ${workerString}`) +writeOutput('esm', `export const workerString = ${workerString}`) + +function writeOutput(moduleType, content) { + const outputPath = path.resolve(__dirname, path.join('..', moduleType, 'entries')) + fs.mkdirSync(outputPath, { recursive: true }) + fs.writeFileSync(path.join(outputPath, 'string.js'), content) + fs.writeFileSync(path.join(outputPath, 'string.d.ts'), 'export declare const workerString: string\n') +} diff --git a/packages/worker/string/package.json b/packages/worker/string/package.json index 7827a7c40f..db127a797e 100644 --- a/packages/worker/string/package.json +++ b/packages/worker/string/package.json @@ -1,4 +1,6 @@ { "private": true, - "main": "../bundle/workerString.ts" + "main": "../cjs/entries/string.js", + "module": "../esm/entries/string.js", + "types": "../cjs/entries/string.d.ts" }