I'm developing a web extension in typescript. To organize the code, I would like to bundle the extension with webpack.
Ideally, webpack should compile typescript and copy the resulting javascript, together with html, css, images to a dist/
directory.
I found a repository which does just what I need. It has the manifest.json
as entry point and creates a dist/
directory.
But the template doesn't use typescript. And this is my problem: In the manifest.json
I need to define javascript files that will be executed (content, background, etc). But these scripts don't exist yet. They are produced by the typescript compiler. So if I point webpack to the manifest, it complains about not finding sources. A workaround (which I would like to avoid) might be to design a two-step workflow:
- use the typescript compiler to compile my sourcecode to javascript.
- use webpack to bundle the resulting code to dist/.
I would like to condense this into a single webpack-based step and tried to do this based on the example repository. They do the following:
- The entry point is the manifest
- HTML, CSS and Assets are processed with the usual loaders
- For Javascript the config looks for index.js files and processes them with spawn-loader
- Other Js files are loaded with babel.
I didn't know it was possible to use a manifest as the entry point. They do this with extricate-loader
. The docs have a nice sample.
I have created a mix of the two setups. The sample from the docs and the repository. Here is the code to reproduce the problem: https://github.com/lhk/webextension_typescript_webpack/tree/complex
I have also set up a minimal working example: https://github.com/lhk/webextension_typescript_webpack. But this working example doesn't copy any html, css, etc. It just compiles the typescript to dist/
.