From 86002fe6cead07809f7ad02de3989a1fa50d9d40 Mon Sep 17 00:00:00 2001 From: Christophe Massolin Date: Wed, 2 May 2018 16:15:11 +0200 Subject: [PATCH 1/2] Update README.md --- README.md | 71 ++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 57 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index fb29446..2f76660 100644 --- a/README.md +++ b/README.md @@ -98,20 +98,63 @@ Chrome tab that will talk remotely to a running Electron app over HTTP. - `require('devtron').install()` cannot be called before the `ready` event of the `app` module has been emitted. -- When using webpack, you may experience issues resolving `__dirname` in accordance with the [docs](https://webpack.js.org/configuration/node/#node-__dirname) since `__dirname` is resolved at runtime on the compiled file. - - To work around this: - 1. Make sure that webpack does not replace `__dirname` by setting: - ``` - // in your webpack config for main process - { - target: 'electron-main', - node: { - __dirname: false, - } - } - ``` - 2. Ensure that the copy target for `devtron/manifest.json` is the same folder as your compiled main process `js` file. - 3. Ensure that the copy target for the `devtron/out/browser-globals.js` is `out/browser-globals.js` relative to your compiled main process `js` file. +#### Webpack + +When using webpack, you may experience issues resolving `__dirname`. In accordance with the [docs](https://webpack.js.org/configuration/node/#node-__dirname), `__dirname` is resolved at runtime on the compiled file. + +You have to two solutions: + - Remove `devtron` from Webpack bundle with `config.externals` **[Recommanded]** + - Copy `devtron` files to the same folder as your compiled main process file + +#### Remove from webpack bundle [Recommended] + +```js +config.externals = [ + function(context, request, callback) { + if (request.match(/devtron/)) { + return callback(null, 'commonjs ' + request) + } + + callback() + } +] +``` + +#### Copy devtron files + 1. Make sure that webpack does not replace `__dirname` by setting: + ```js + // in your webpack config for main process + { + target: 'electron-main', + node: { + __dirname: false, + } + } + ``` + 2. Ensure that the copy target for `devtron/manifest.json` is the same folder as your compiled main process `js` file. + 3. Ensure that the copy target for the `devtron/out/browser-globals.js` is `out/browser-globals.js` relative to your compiled main process `js` file. + +You can copy files with `copy-webpack-plugin`. + +```js +const path = require('path'); +const CopyWebpackPlugin = require('copy-webpack-plugin'); + +const copyFiles = [ + { + from: path.resolve(__dirname, 'node_modules/devtron/manifest.json') + }, + { + from: path.resolve(__dirname, 'node_modules/devtron/out/browser-globals.js'), + to: path.resolve(__dirname, 'out'), + } +]; + +config.target = 'electron-main', +config.plugins = [ + new CopyWebpackPlugin(copyFiles), +] +``` ## Contributing From 1996551a8ec0055be756b053e40bbc746aac664a Mon Sep 17 00:00:00 2001 From: Christophe Massolin Date: Wed, 2 May 2018 16:18:12 +0200 Subject: [PATCH 2/2] Update README.md Precise how to make it run `devtron` with a webpack bundle. --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 2f76660..2af2843 100644 --- a/README.md +++ b/README.md @@ -103,10 +103,10 @@ Chrome tab that will talk remotely to a running Electron app over HTTP. When using webpack, you may experience issues resolving `__dirname`. In accordance with the [docs](https://webpack.js.org/configuration/node/#node-__dirname), `__dirname` is resolved at runtime on the compiled file. You have to two solutions: - - Remove `devtron` from Webpack bundle with `config.externals` **[Recommanded]** - - Copy `devtron` files to the same folder as your compiled main process file + 1. Remove `devtron` from Webpack bundle with `config.externals` + 2. Copy `devtron` files to the same folder as your compiled main process file -#### Remove from webpack bundle [Recommended] +#### [Solution 1] Remove from webpack bundle ```js config.externals = [ @@ -120,7 +120,7 @@ config.externals = [ ] ``` -#### Copy devtron files +#### [Solution 2] Copy devtron files 1. Make sure that webpack does not replace `__dirname` by setting: ```js // in your webpack config for main process