├── CODEOWNERS ├── renovate.json ├── .gitignore ├── tests ├── fixtures │ ├── top-level-function-name │ │ ├── config.json │ │ ├── build │ │ │ └── runner.html │ │ ├── entry.js │ │ └── a.js │ ├── public-path │ │ ├── config.json │ │ ├── build │ │ │ └── runner.html │ │ ├── entry.js │ │ └── a.js │ ├── single-default │ │ ├── a.js │ │ ├── build │ │ │ └── runner.html │ │ └── entry.js │ ├── dynamic-import │ │ ├── build │ │ │ └── runner.html │ │ ├── entry.js │ │ └── a.js │ ├── import-meta │ │ ├── build │ │ │ └── runner.html │ │ ├── entry.js │ │ └── a.js │ ├── simple-bundle │ │ ├── build │ │ │ └── runner.html │ │ ├── entry.js │ │ └── a.js │ └── worker │ │ ├── entry.js │ │ ├── a.js │ │ └── build │ │ └── runner.html ├── worker.test.js ├── public-path.test.js ├── simple-bundle.test.js ├── dynamic-import.test.js ├── single-default.test.js ├── import-meta.test.js └── top-level-function-name.test.js ├── .travis.yml ├── CONTRIBUTORS ├── Dockerfile ├── package.json ├── karma.conf.js ├── CONTRIBUTING ├── run_tests.js ├── README.md ├── loader.ejs ├── index.js └── LICENSE /CODEOWNERS: -------------------------------------------------------------------------------- 1 | @surma 2 | -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["config:base"] 3 | } 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | tests/fixtures/*/build/*.js 2 | node_modules 3 | package-lock.json 4 | -------------------------------------------------------------------------------- /tests/fixtures/top-level-function-name/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "topLevelFunctionName": "foo" 3 | } 4 | -------------------------------------------------------------------------------- /tests/fixtures/public-path/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "publicPath": "/base/tests/fixtures/public-path/build" 3 | } 4 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: required 2 | 3 | services: 4 | - docker 5 | 6 | script: 7 | - docker build -t loadz0r . 8 | - docker run --rm -v `pwd`:/usr/src loadz0r 9 | -------------------------------------------------------------------------------- /CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | # People who have agreed to one of the CLAs and can contribute patches. 2 | # The AUTHORS file lists the copyright holders; this file 3 | # lists people. For example, Google employees are listed here 4 | # but not in AUTHORS, because Google holds the copyright. 5 | # 6 | # https://developers.google.com/open-source/cla/individual 7 | # https://developers.google.com/open-source/cla/corporate 8 | # 9 | # Names should be added to this file as: 10 | # Name 11 | Surma 12 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM selenium/node-chrome:latest@sha256:c7230a03f91ccc771636d688cf9288de70ba8db49d065040871ded2e149f06e1 2 | 3 | USER root 4 | 5 | RUN apt-get update -qqy \ 6 | && rm -rf /var/lib/apt/lists/* /var/cache/apt/* \ 7 | && rm /bin/sh && ln -s /bin/bash /bin/sh \ 8 | && chown seluser /usr/local 9 | 10 | ENV NVM_DIR /usr/local/nvm 11 | RUN wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash \ 12 | && source $NVM_DIR/nvm.sh \ 13 | && nvm install v8 14 | 15 | ENV CHROME_BIN /opt/google/chrome/chrome 16 | ENV INSIDE_DOCKER=1 17 | 18 | WORKDIR /usr/src 19 | ENTRYPOINT source $NVM_DIR/nvm.sh && npm i && npm test -------------------------------------------------------------------------------- /tests/fixtures/single-default/a.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 Google Inc. All Rights Reserved. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | 14 | export default 4; 15 | -------------------------------------------------------------------------------- /tests/fixtures/dynamic-import/build/runner.html: -------------------------------------------------------------------------------- 1 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /tests/fixtures/import-meta/build/runner.html: -------------------------------------------------------------------------------- 1 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /tests/fixtures/public-path/build/runner.html: -------------------------------------------------------------------------------- 1 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /tests/fixtures/simple-bundle/build/runner.html: -------------------------------------------------------------------------------- 1 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /tests/fixtures/single-default/build/runner.html: -------------------------------------------------------------------------------- 1 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /tests/fixtures/worker/entry.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 Google Inc. All Rights Reserved. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | 14 | import("./a.js").then(m => m.default()); 15 | -------------------------------------------------------------------------------- /tests/fixtures/import-meta/entry.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 Google Inc. All Rights Reserved. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | 14 | import("./a.js").then(m => m.default()); 15 | -------------------------------------------------------------------------------- /tests/fixtures/public-path/entry.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 Google Inc. All Rights Reserved. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | 14 | import("./a.js").then(m => m.default()); 15 | -------------------------------------------------------------------------------- /tests/fixtures/simple-bundle/entry.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 Google Inc. All Rights Reserved. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | 14 | import A from "./a.js"; 15 | 16 | A(); 17 | -------------------------------------------------------------------------------- /tests/fixtures/dynamic-import/entry.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 Google Inc. All Rights Reserved. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | 14 | import("./a.js").then(m => m.default()); 15 | -------------------------------------------------------------------------------- /tests/fixtures/top-level-function-name/build/runner.html: -------------------------------------------------------------------------------- 1 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /tests/fixtures/top-level-function-name/entry.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 Google Inc. All Rights Reserved. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | 14 | import("./a.js").then(m => m.default()); 15 | -------------------------------------------------------------------------------- /tests/fixtures/worker/a.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 Google Inc. All Rights Reserved. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | 14 | export default function() { 15 | self.postMessage("a"); 16 | } 17 | -------------------------------------------------------------------------------- /tests/fixtures/single-default/entry.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 Google Inc. All Rights Reserved. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | 14 | import A from "./a.js"; 15 | 16 | window.parent.postMessage(A, "*"); 17 | -------------------------------------------------------------------------------- /tests/fixtures/dynamic-import/a.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 Google Inc. All Rights Reserved. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | 14 | export default function() { 15 | window.parent.postMessage("a", "*"); 16 | } 17 | -------------------------------------------------------------------------------- /tests/fixtures/public-path/a.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 Google Inc. All Rights Reserved. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | 14 | export default function() { 15 | window.parent.postMessage("a", "*"); 16 | } 17 | -------------------------------------------------------------------------------- /tests/fixtures/simple-bundle/a.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 Google Inc. All Rights Reserved. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | 14 | export default function() { 15 | window.parent.postMessage("a", "*"); 16 | } 17 | -------------------------------------------------------------------------------- /tests/fixtures/import-meta/a.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 Google Inc. All Rights Reserved. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | 14 | export default function() { 15 | window.parent.postMessage(import.meta.url, "*"); 16 | } 17 | -------------------------------------------------------------------------------- /tests/fixtures/top-level-function-name/a.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 Google Inc. All Rights Reserved. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | 14 | export default function() { 15 | window.parent.postMessage("a", "*"); 16 | } 17 | -------------------------------------------------------------------------------- /tests/fixtures/worker/build/runner.html: -------------------------------------------------------------------------------- 1 | 13 | 14 | 15 | 19 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "rollup-plugin-loadz0r", 3 | "version": "0.7.2", 4 | "description": "Rollup plugin to make code splitting “just work”", 5 | "main": "index.js", 6 | "scripts": { 7 | "fmt": "prettier --write 'tests/**/*.js' *.js *.md *.json", 8 | "test": "node ./run_tests.js" 9 | }, 10 | "author": "Surma ", 11 | "license": "Apache-2.0", 12 | "devDependencies": { 13 | "chai": "4.2.0", 14 | "karma": "4.2.0", 15 | "karma-chai": "0.1.0", 16 | "karma-chrome-launcher": "3.0.0", 17 | "karma-firefox-launcher": "1.1.0", 18 | "karma-mocha": "1.3.0", 19 | "karma-safari-launcher": "1.0.0", 20 | "karma-safaritechpreview-launcher": "2.0.2", 21 | "mocha": "6.1.4", 22 | "prettier": "1.18.2", 23 | "rollup": "1.16.2" 24 | }, 25 | "repository": { 26 | "type": "git", 27 | "url": "https://github.com/surma/rollup-plugin-loadz0r" 28 | }, 29 | "dependencies": { 30 | "ejs": "^2.6.1", 31 | "magic-string": "^0.25.0" 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /tests/worker.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 Google Inc. All Rights Reserved. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | 14 | describe("Worker", function() { 15 | beforeEach(function() { 16 | this.ifr = document.createElement("iframe"); 17 | document.body.append(this.ifr); 18 | }); 19 | 20 | afterEach(function() { 21 | this.ifr.remove(); 22 | }); 23 | 24 | it("loads transpiled modules", function(done) { 25 | window.addEventListener("message", function l(ev) { 26 | if (ev.data === "a") { 27 | window.removeEventListener("message", l); 28 | done(); 29 | } 30 | }); 31 | this.ifr.src = "/base/tests/fixtures/worker/build/runner.html"; 32 | }); 33 | }); 34 | -------------------------------------------------------------------------------- /tests/public-path.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 Google Inc. All Rights Reserved. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | 14 | describe("Public Path", function() { 15 | beforeEach(function() { 16 | this.ifr = document.createElement("iframe"); 17 | document.body.append(this.ifr); 18 | }); 19 | 20 | afterEach(function() { 21 | this.ifr.remove(); 22 | }); 23 | 24 | it("loads transpiled modules", function(done) { 25 | window.addEventListener("message", function l(ev) { 26 | if (ev.data === "a") { 27 | window.removeEventListener("message", l); 28 | done(); 29 | } 30 | }); 31 | this.ifr.src = "/base/tests/fixtures/public-path/build/runner.html"; 32 | }); 33 | }); 34 | -------------------------------------------------------------------------------- /tests/simple-bundle.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 Google Inc. All Rights Reserved. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | 14 | describe("Simple bundle", function() { 15 | beforeEach(function() { 16 | this.ifr = document.createElement("iframe"); 17 | document.body.append(this.ifr); 18 | }); 19 | 20 | afterEach(function() { 21 | this.ifr.remove(); 22 | }); 23 | 24 | it("loads transpiled modules", function(done) { 25 | window.addEventListener("message", function l(ev) { 26 | if (ev.data === "a") { 27 | window.removeEventListener("message", l); 28 | done(); 29 | } 30 | }); 31 | this.ifr.src = "/base/tests/fixtures/simple-bundle/build/runner.html"; 32 | }); 33 | }); 34 | -------------------------------------------------------------------------------- /tests/dynamic-import.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 Google Inc. All Rights Reserved. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | 14 | describe("Dynamic import", function() { 15 | beforeEach(function() { 16 | this.ifr = document.createElement("iframe"); 17 | document.body.append(this.ifr); 18 | }); 19 | 20 | afterEach(function() { 21 | this.ifr.remove(); 22 | }); 23 | 24 | it("loads transpiled modules", function(done) { 25 | window.addEventListener("message", function l(ev) { 26 | if (ev.data === "a") { 27 | window.removeEventListener("message", l); 28 | done(); 29 | } 30 | }); 31 | this.ifr.src = "/base/tests/fixtures/dynamic-import/build/runner.html"; 32 | }); 33 | }); 34 | -------------------------------------------------------------------------------- /tests/single-default.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 Google Inc. All Rights Reserved. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | 14 | describe("Single default const export", function() { 15 | beforeEach(function() { 16 | this.ifr = document.createElement("iframe"); 17 | document.body.append(this.ifr); 18 | }); 19 | 20 | afterEach(function() { 21 | this.ifr.remove(); 22 | }); 23 | 24 | it("loads transpiled modules", function(done) { 25 | window.addEventListener("message", function l(ev) { 26 | if (ev.data === 4) { 27 | window.removeEventListener("message", l); 28 | done(); 29 | } 30 | }); 31 | this.ifr.src = "/base/tests/fixtures/single-default/build/runner.html"; 32 | }); 33 | }); 34 | -------------------------------------------------------------------------------- /tests/import-meta.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 Google Inc. All Rights Reserved. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | 14 | describe("import.meta", function() { 15 | beforeEach(function() { 16 | this.ifr = document.createElement("iframe"); 17 | document.body.append(this.ifr); 18 | }); 19 | 20 | afterEach(function() { 21 | this.ifr.remove(); 22 | }); 23 | 24 | it("loads transpiled modules", function(done) { 25 | window.addEventListener("message", function l(ev) { 26 | if (/^https?:\/\/[^/]+\/a-[0-9a-f]+\.js$/.test(ev.data)) { 27 | window.removeEventListener("message", l); 28 | done(); 29 | } 30 | }); 31 | this.ifr.src = "/base/tests/fixtures/import-meta/build/runner.html"; 32 | }); 33 | }); 34 | -------------------------------------------------------------------------------- /tests/top-level-function-name.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 Google Inc. All Rights Reserved. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | 14 | describe("Top Level Function Name", function() { 15 | beforeEach(function() { 16 | this.ifr = document.createElement("iframe"); 17 | document.body.append(this.ifr); 18 | }); 19 | 20 | afterEach(function() { 21 | this.ifr.remove(); 22 | }); 23 | 24 | it("loads with a different top level function name", function(done) { 25 | window.addEventListener("message", function l(ev) { 26 | if (ev.data === "a") { 27 | window.removeEventListener("message", l); 28 | done(); 29 | } 30 | }); 31 | this.ifr.src = "/base/tests/fixtures/top-level-function-name/build/runner.html"; 32 | }); 33 | }); 34 | -------------------------------------------------------------------------------- /karma.conf.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 Google Inc. All Rights Reserved. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | 14 | module.exports = function(config) { 15 | const configuration = { 16 | basePath: "", 17 | frameworks: ["mocha", "chai"], 18 | files: [ 19 | { 20 | pattern: "tests/fixtures/**", 21 | included: false 22 | }, 23 | { 24 | pattern: "tests/*.test.js" 25 | } 26 | ], 27 | reporters: ["progress"], 28 | port: 9876, 29 | colors: true, 30 | logLevel: config.LOG_INFO, 31 | autoWatch: true, 32 | singleRun: true, 33 | concurrency: 1, 34 | browsers: ["Chrome", "Firefox", "Safari"], 35 | customLaunchers: { 36 | DockerChrome: { 37 | base: "ChromeHeadless", 38 | flags: ["--no-sandbox"] 39 | } 40 | } 41 | }; 42 | 43 | if (process.env.INSIDE_DOCKER) configuration.browsers = ["DockerChrome"]; 44 | 45 | config.set(configuration); 46 | }; 47 | -------------------------------------------------------------------------------- /CONTRIBUTING: -------------------------------------------------------------------------------- 1 | Want to contribute? Great! First, read this page (including the small print at the end). 2 | 3 | ### Before you contribute 4 | Before we can use your code, you must sign the 5 | [Google Individual Contributor License Agreement] 6 | (https://cla.developers.google.com/about/google-individual) 7 | (CLA), which you can do online. The CLA is necessary mainly because you own the 8 | copyright to your changes, even after your contribution becomes part of our 9 | codebase, so we need your permission to use and distribute your code. We also 10 | need to be sure of various other things—for instance that you'll tell us if you 11 | know that your code infringes on other people's patents. You don't have to sign 12 | the CLA until after you've submitted your code for review and a member has 13 | approved it, but you must do it before we can put your code into our codebase. 14 | Before you start working on a larger contribution, you should get in touch with 15 | us first through the issue tracker with your idea so that we can help out and 16 | possibly guide you. Coordinating up front makes it much easier to avoid 17 | frustration later on. 18 | 19 | ### Code reviews 20 | All submissions, including submissions by project members, require review. We 21 | use Github pull requests for this purpose. 22 | 23 | ### The small print 24 | Contributions made by corporations are covered by a different agreement than 25 | the one above, the 26 | [Software Grant and Corporate Contributor License Agreement] 27 | (https://cla.developers.google.com/about/google-corporate). 28 | -------------------------------------------------------------------------------- /run_tests.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 Google Inc. All Rights Reserved. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | 14 | const rollup = require("rollup"); 15 | const path = require("path"); 16 | const loadz0r = require("."); 17 | const fs = require("fs"); 18 | 19 | const karma = require("karma"); 20 | const myKarmaConfig = require("./karma.conf.js"); 21 | 22 | async function init() { 23 | [ 24 | "./tests/fixtures/simple-bundle/entry.js", 25 | "./tests/fixtures/import-meta/entry.js", 26 | "./tests/fixtures/dynamic-import/entry.js", 27 | "./tests/fixtures/public-path/entry.js", 28 | "./tests/fixtures/worker/entry.js", 29 | "./tests/fixtures/single-default/entry.js", 30 | "./tests/fixtures/top-level-function-name/entry.js" 31 | ].forEach(async input => { 32 | const pathName = path.dirname(input); 33 | let config = {}; 34 | try { 35 | const configPath = path.join(pathName, "config.json"); 36 | config = JSON.parse(fs.readFileSync(configPath).toString()); 37 | } catch (e) {} 38 | const bundle = await rollup.rollup({ 39 | input, 40 | 41 | plugins: [loadz0r(config)] 42 | }); 43 | const outputOptions = { 44 | dir: path.join(pathName, "build"), 45 | format: "amd" 46 | }; 47 | await bundle.generate(outputOptions); 48 | await bundle.write(outputOptions); 49 | }); 50 | 51 | const karmaConfig = { port: 9876 }; 52 | myKarmaConfig({ 53 | set(config) { 54 | Object.assign(karmaConfig, config); 55 | } 56 | }); 57 | const server = new karma.Server(karmaConfig, code => { 58 | console.log(`Karma exited with code ${code}`); 59 | process.exit(code); 60 | }); 61 | server.start(); 62 | } 63 | init(); 64 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Deprecated. Please use [rollup-plugin-off-main-thread](https://github.com/surma/rollup-plugin-off-main-thread) 2 | 3 | # rollup-plugin-loadz0r 4 | 5 | 6 | An ill-named rollup plugin so you can use `import()` in every browser, even in workers. 7 | 8 | ``` 9 | $ npm install --save rollup-plugin-loadz0r 10 | ``` 11 | 12 | Code splitting is important to make loading more efficient by only loading what you need. This becomes literally doubly important when you are using workers (including service workers), as [they might share dependencies with your UI thread and you don’t want to load the same code twice][splitting]. That’s the point where you usually run into the issue that workers don’t have support for modules anywhere just yet. To work around this you can either pick a full-blown module loader like [RequireJS] or [SystemJS] **or you can use loadz0r!!!!1!11**. 13 | 14 | The plugin packs a tiny (~380B gzip’d) almost-AMD loader that is specifically tailored to the output that rollup produces. It is so small in fact, that it is totally acceptable to just prepend the loader to all entry point modules. This way you don’t have to load a module loader and then pay another round-trip to load your bootstrap code. 15 | 16 | **This plugin is only necessary for as long as there is no mainstream support for modules in workers.** Once modules in workers land, just use rollup’s ES Module output format. 17 | 18 | > Note: The reason the loader is so small is because _it is not a general purpose loader_. It most likely won’t work with anything but rollup generated bundles. 19 | 20 | ## Usage 21 | 22 | ```js 23 | // rollup.config.js 24 | import loadz0r from "rollup-plugin-loadz0r"; 25 | 26 | export default { 27 | input: ["src/main.js", "src/worker.js", "src/serviceworker.js"], 28 | output: { 29 | dir: "dist", 30 | // You _must_ use “amd” as your format 31 | format: "amd" 32 | }, 33 | plugins: [loadz0r()] 34 | }; 35 | ``` 36 | 37 | ## Options 38 | 39 | ```js 40 | { 41 | // ... 42 | plugins: [loadz0r(options)]; 43 | } 44 | ``` 45 | 46 | - `loader`: A string containing the source of the loader. If `undefined,` loadz0r will use the aforementioned minimal AMD loader (see `loader.js`). 47 | - `useEval`: Use `fetch()` + `eval()` to load dependencies instead of `