Skip to content
This repository has been archived by the owner on Feb 3, 2022. It is now read-only.

How to integrate with modulization introduced by PR #11? #14

Open
menicosia opened this issue Oct 30, 2019 · 4 comments
Open

How to integrate with modulization introduced by PR #11? #14

menicosia opened this issue Oct 30, 2019 · 4 comments

Comments

@menicosia
Copy link
Contributor

menicosia commented Oct 30, 2019

Hello! I am trying to take advantage of the improvements in recent PRs, but I am blocked by the change introduced by PR #11 where the main file was transformed into a module.

Previous behavior:

  • Load googleDocsUtil.js via the extension's manifest.json:

    "content_scripts": [
       {
         "js": ["googleDocsUtil.js", "receiver.js"],
    

Current behavior:

  • When I try to load googleDocsUtil.js in that way, I get this error from Chrome:

    googleDocsUtil.js:1
    Uncaught SyntaxError: Unexpected token 'export'

As a result of this change, I don't know how to access the module from within a Chrome extension. Specifically, I need googleDocsUtil.js to load into the page that I am currently viewing, and the only way I know how to do that is via a content script, which does not accept a Javascript module. There is no way to import or require the file because, without this content script loading, the file is not available to my extension.

Since I am stuck, the only change I can think to suggest is to roll-back the module-ness of PR #11? Are there other options?

/cc @bdvorianov

@menicosia
Copy link
Contributor Author

FYI just changing the first and last lines of the file seemed to resolve this issue:

1c1
< var googleDocsUtil = function () {
---
> export default (function () {
446c446
< }();
---
> })();

@bdvorianov
Copy link

bdvorianov commented Oct 31, 2019

@menicosia my bad, sorry.

I'm using webpack to make bundles for my extension, so export module is what I needed.

Thank you for feedback. 🙏

@volpav
Copy link

volpav commented Jan 8, 2020

Ran into the same issue when playing with the tool. I would recommend not relying on a particular build system here (and therefore, rolling back this change). @bdvorianov - you could probably "modularize" it using webpack's custom loaders.

@Amaimersion
Copy link

Amaimersion commented Dec 24, 2020

Consider using my fork of this project - google-docs-utils.
I rewrite this project, but keep almost all current functionality and add support for both IIFE and CJS.

So, if you on Node.js, then just:

const GoogleDocsUtils = require('google-docs-utils');

If you in browser, then you can inject this script manually and access GoogleDocsUtils global variable:

var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'https://unpkg.com/google-docs-utils@latest/dist/iife/index.js';
document.head.appendChild(script);

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants