Skip to content

Latest commit

 

History

History
56 lines (36 loc) · 2.09 KB

build.md

File metadata and controls

56 lines (36 loc) · 2.09 KB

Build

Important points about webpack configuration

production

CI

The ForkTsCheckerWebpackPlugin async is false so that build process returns non-zero code if the typescript type check fails; useful for continuous integration.

new ForkTsCheckerWebpackPlugin({
      async: false,
      watch: localPath('src'),
      tslint: true,
    })

browser extension

Development: We cannot use optimization.splitChunks

Although webpack 4 provides excellent optimization.splitChunks option, it cannot be enabled for extension development. Chunks generated by the splitChunks communicate through the shared window variable.

However, each browser content script lives in a sandbox (see here); it can access window variable but most probably each such window instance is just a clone of the DOM window. The only real way content scripts can interact is through the actual DOM (or a kind fo WEB API messages).

The manual division into two entry points is decent but surely there is room for improvement.

Development: Static file loading

If a content script CSS tries to load a static file, the the URL is interpreted relative to the tab URL, not the browser extension URL (so we end up with e.g. stackoverflow.com/assets/extension_icon.png instead of chrome-extension://XYZ/assets/extension_icon.png. Some solutions have been proposed here. However, they make the code inflexible -- they cannot be used in a simple client app anymore, as existence of chrome browser extension is assumed.

our solution

We manually set the browser extension key (more here), so we know the app key at runtime and can explicitly define the address where static files should be searched for:

publicPath: chrome-extension://${KEY}/

(where we ourselves have devised the KEY)

production

The production key is provided by Chrome on app registration.