Skip to content
This repository was archived by the owner on Feb 18, 2024. It is now read-only.

Web Extension Preset #831

Closed
wants to merge 10 commits into from
Closed

Web Extension Preset #831

wants to merge 10 commits into from

Conversation

Morikko
Copy link

@Morikko Morikko commented Apr 29, 2018

Creating web extension easily over webpack and web-ext

  • Use web-ext tool for development (open a specific browser environment)
  • Build the final project with web-ext (final source, ZIP and XPI)
  • Lint the project with web-ext on top of any classical code lint
  • Read the manifest to detect automatically some paths (panel, popup...)

See the README.md in webextension/ for more information.

Note

Repository for testing: webextension-neutrino-test

helfi92 and others added 9 commits March 27, 2018 12:41
* Renamed the preset to webextension
* Deleted unwanted configs from the web preset
* Store hot-update.{js, json} files in build/hot/
* Stop using hashes because it's not useful for
web extensions. Also, the main html and js files
need to be referenced in manifest.json and so it becomes
hard to reference them if they have hashes.
- Also rebase on neutrino ^8.0.0
- `start` uses now dev/ (files to copy are also watched)
- `build` uses build/
-
Built extension is now in `build/extension`
ZIP/XPI files are in `build`
 + Read manifest to find the entries automatically
 + Avoid creating useless HTML for content scripts & background.js
 + Keep entry structure `popup/popup.js -> popup/popup.html`
@Morikko
Copy link
Author

Morikko commented Apr 29, 2018

Problems

  • Copied files are not removed in ./dev if removed from ./src
  • New files in ./src don't trigger a rebuild (but are copied after a rebuild due to a modification on another file)
  • Lots of warnings due to the use of eval
  • When building, all js target (without HTML: content scripts and background.js) are not working because runtime.js is not imported...
  • Lots of error reported in Firefox console from the bundled files. Example below.
   ReferenceError: reference to undefined property "disabled"[Learn More]  CustomizableUI.jsm:2480:5
   TypeError: cannot use 'in' operator to search for 'canGoBack' in 'browser'[Learn More]  tabbrowser.xml:2473:1
   ReferenceError: reference to undefined property "additionalBackgrounds"[Learn More]  LightweightThemeConsumer.jsm:161:5
   ReferenceError: reference to undefined property "backgroundsAlignment"[Learn More]  LightweightThemeConsumer.jsm:205:5
   ReferenceError: reference to undefined property "initialPageLoadedFromURLBar"[Learn More]  tabbrowser.xml:697:1
   ...

@eliperelman
Copy link
Member

To update here, we made significant changes in #852 that eliminates the Neutrino CLI. To continue forward with this, we would need to change this to instead output the config required for webext to consume the middleware. Are you still willing to pick up on this?

@Morikko
Copy link
Author

Morikko commented Jun 3, 2018

If I understood well, in webext-config.js, it would be like this:

const neutrino = require('neutrino');

module.exports = neutrino().webext(config => {
  // Overwrites the config here
});

Where neutrino().webext() is the default config from the middleware (like in packages/webextension/index.js) ?

@edmorley
Copy link
Member

edmorley commented Jun 5, 2018

Hi!

Yes that sounds right.

After #852, we no longer have a Neutrino CLI that calls various tools by their node API, and instead rely on the tool's own CLIs / native config files.

I'm not very familiar with web extensions, but reading through the web-ext package docs it seems that it will auto-detect a file named .web-ext-config.js or web-ext-config.js. As such, if the web-ext CLI is to be used, that file should contain the module.exports = neutrino().webext(), and the .webext() command registered using something like:
https://github.com/mozilla-neutrino/neutrino-dev/blob/b6eb31ffee0b1e1f50504355d74da4472b4a03b8/packages/jest/src/index.js#L21

That said, I can't tell from skimming through this PR whether it used to invoke the webpack build at all? (I guess the neutrino.on('build', ...) was cumulative, and so it did invoke webpack as well as the webext API?)

If it did, then perhaps this preset needs to change to using the webpack plugin instead? (Since otherwise two separate CLIs would have to be run sequentially)
https://github.com/rpl/webpack-webext-plugin

A couple of other things I spotted in the PR:

  • config.resolve.modules and config.resolveLoader.modules can be removed (see Use default webpack module resolution #926)
  • some of the deepmerge usages can be replaced with the spread operator (now that we require node 8.3+)

Hope that helps :-)

@edmorley
Copy link
Member

Closing this out for now since there's no activity. If you or someone else has a chance to work through the suggested changes above, happy to answer any questions you might have :-)

@edmorley edmorley closed this Aug 29, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

Successfully merging this pull request may close these issues.

4 participants