Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
developit committed Jan 10, 2020
2 parents 35c7333 + 57b5f48 commit 7d4a9c4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ node_modules
*.log
build
dist
coverage
package-lock.json
yarn.lock
coverage/*
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "comlink-loader",
"version": "1.1.0",
"version": "1.1.1",
"description": "Webpack loader: offload modules to Worker threads seamlessly using Comlink",
"main": "dist/comlink-loader.js",
"repository": "GoogleChromeLabs/comlink-loader",
"scripts": {
"build": "microbundle --inline none --format cjs --no-compress src/*.js",
"prepublishOnly": "npm run build",
"dev": "karmatic watch --no-headless",
"test": "npm run build && karmatic",
"test": "npm run build && karmatic --no-coverage",
"release": "npm t && git commit -am $npm_package_version && git tag $npm_package_version && git push && git push --tags && npm publish"
},
"eslintConfig": {
Expand Down Expand Up @@ -61,14 +61,15 @@
"eslint-plugin-promise": "^3.8.0",
"eslint-plugin-standard": "^3.1.0",
"jasmine-sinon": "^0.4.0",
"karmatic": "^1.0.5",
"microbundle": "^0.4.2",
"karmatic": "^1.4.0",
"microbundle": "^0.11.0",
"sinon": "^5.1.0",
"webpack": "^4.32.2"
"webpack": "^4.41.2"
},
"dependencies": {
"comlink": "^4.0.1",
"comlink": "^4.2.0",
"loader-utils": "^1.1.0",
"slash": "^3.0.0",
"worker-loader": "^2.0.0"
}
}
17 changes: 13 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,29 @@

import path from 'path';
import loaderUtils from 'loader-utils';
import slash from 'slash';

const comlinkLoaderSpecificOptions = ['multiple', 'multi', 'singleton'];

export default function loader () { }

loader.pitch = function (request) {
const options = loaderUtils.getOptions(this) || {};
// const multi = options.multiple || options.multi || options.singleton === false;
const multi = options.multiple || options.multi || options.singleton === false;
const workerLoaderOptions = {};
for (let i in options) {
if (comlinkLoaderSpecificOptions.indexOf(i) === -1) {
workerLoaderOptions[i] = options[i];
}
}

return `
import { wrap } from 'comlink';
var inst;
var worker = require('!worker-loader?${JSON.stringify(options)}!${path.resolve(__dirname, 'comlink-worker-loader.js')}!${request}');
var worker = wrap(require('!worker-loader?${JSON.stringify(workerLoaderOptions)}!${slash(path.resolve(__dirname, 'comlink-worker-loader.js'))}!${request}');
export default function f() {
inst = inst || wrap(worker());
return (this instanceof f) ? wrap(worker()) : inst;
if (this instanceof f) return wrap(worker());
return inst = inst || wrap(worker());
}
`.replace(/\n\s*/g, '');
};

0 comments on commit 7d4a9c4

Please sign in to comment.