adambullmer / vue-cli-plugin-browser-extension

Browser extension development plugin for vue-cli 3.0
GNU Lesser General Public License v3.0
427 stars 76 forks source link

typescript support. #12

Closed mayajuni closed 5 years ago

mayajuni commented 6 years ago

I am using typescript. Does it support typescript?

Thank you.

adambullmer commented 6 years ago

I haven't tested on typescript yet, so the scaffolding won't auto convert yet. But I think if you add vue-cli-plugin-typescript and you manually convert files to lang="ts" it should build fine. Definitely needs to be added to the roadmap, as it is fairly simple to convert files to TS after generation.

mayajuni commented 6 years ago

i tested. it is ok. but i have to use background.js and content-script.js.

i have 1 more error. it is 'global is not defined' i am using crypto from nodejs. base vue-cli is fine. but i had an error after i added this module.

thank you.

adambullmer commented 6 years ago

Until I get TS integrated, you could adjust the webpack chain similar to how I have done here in your own vue.config.js. You'd delete my 'background' entry and add your own referencing the background.ts file instead of background.js, and then the same thing for the content script.

Concerning your other error, could you paste in some relevant lines of code or steps to reproduce?

mayajuni commented 6 years ago

When I put in the below code onto popup.js, a 'global is not defined' error occurs.

popup.js

const crypto = require('crypto');

function encrypt(text, cryptoKey) {
  const sha256 = crypto.createHash('sha256');
  sha256.update(cryptoKey.toString());

  // Initialization Vector
  const iv = crypto.randomBytes(16);
  const cipher = crypto.createCipheriv('aes-256-ctr', sha256.digest(), iv);

  const ciphertext = cipher.update(Buffer.from(JSON.stringify(text)));

  return Buffer.concat([iv, ciphertext, cipher.final()]).toString('base64');
}

console.log(encrypt('123', '123'));

When I put in 'global = window;' onto the very top of dist/popup/popup.js, the error goes away. Is there a way to fix this?

Thank you.

mayajuni commented 6 years ago

I was able to find a solution to the above. If you look at the 33rd line of index.js, it shows as below:

webpackConfig.node.global = false

By modifying to the below, I was able to solve the problem.

webpackConfig.node.global = true

Is there a way to add <script src+'test.js'> to popup.html? I'm asking because the code gets deleted once it's built? Thank you in advance.