Browse Source

add require path flag for registering babel and such

pull/93/head
mattdesl 5 years ago
parent
commit
f934e0609d
  1. 4
      README.md
  2. 4
      lib/main-window.js
  3. 4
      lib/parse-args.js
  4. 16
      lib/preload.js
  5. 5
      package.json
  6. 1
      test/fixtures/log-random.js

4
README.md

@ -46,6 +46,7 @@ Options:
--config a path to .devtoolrc config file
--verbose verbose Chromium logging
--version, -v log versions of underlying tools
--require, -r require path(s) before running entry
--browser-field, --bf resolve using "browser" field
--no-source-maps,
--no-sm disable source map generation
@ -72,6 +73,9 @@ devtool writer.js < README.md
# pass clean arg list to app.js
devtool app.js --watch -- entry
# register with babel before requiring our app
devtool -r babel-register app.js
```
You can specify `--watch` multiple times to watch different files/globs. If a custom `--index` is passed, it will also be watched for changes.

4
lib/main-window.js

@ -78,7 +78,9 @@ function createMainWindow (entry, url, argv, onReady) {
// and process.nextTick didn't work
setImmediate(function () {
webContents.once('devtools-closed', function () {
mainWindow.close();
// Weird timeout is necessary for election@1.3.3 to
// avoid errors on OSX from Cmd+W
setTimeout(() => mainWindow.close(), 50);
});
});
}

4
lib/parse-args.js

@ -31,6 +31,7 @@ module.exports = function parseArgs (args) {
debugBreak: argv.debugBreak,
browserGlobals: argv.browserGlobals,
nodeTimers: argv.nodeTimers,
requirePaths: [].concat(argv.require).filter(Boolean),
entry: null, // resolved in server.js
quit: true, // true until app launches
_processTTY: {
@ -52,7 +53,7 @@ function fromArray (args) {
'browserField', 'version', 'break', 'browserGlobals',
'nodeTimers', 'verbose', 'sourceMaps'
],
string: [ 'index' ],
string: [ 'index', 'require' ],
default: {
browserGlobals: true,
sourceMaps: true,
@ -69,6 +70,7 @@ function fromArray (args) {
browserField: [ 'bf', 'browser-field' ],
watch: 'w',
quit: 'q',
require: 'r',
version: 'v',
console: 'c',
index: 'i',

16
lib/preload.js

@ -11,6 +11,8 @@
var consoleHook = require('./console-hook');
var timerHook = require('./timer-hook');
var mockProcess = require('mock-stdin');
var browserResolve = require('browser-resolve');
var nodeResolve = require('resolve');
var remote = electron.remote;
var ipc = electron.ipcRenderer;
@ -80,6 +82,9 @@
var firstRun = true;
// boot up entry application when DOM is ready
ipc.on('run-entry', function () {
if (Array.isArray(globals.requirePaths)) {
globals.requirePaths.forEach(doRequire);
}
if (entry) require(entry);
if (firstRun) {
// Tell the main thread to send along stdin
@ -88,6 +93,17 @@
}
});
function doRequire (file) {
var result;
var resolveOpt = { basedir: cwd };
if (globals.browserField) {
result = browserResolve.sync(file, resolveOpt);
} else {
result = nodeResolve.sync(file, resolveOpt);
}
require(result);
}
function fatalError (err) {
ipc.send('error', JSON.stringify(serialize(err)));
}

5
package.json

@ -16,13 +16,14 @@
"concat-stream": "^1.5.1",
"convert-source-map": "^1.2.0",
"deep-extend": "^0.4.1",
"electron-prebuilt": "1.3.1",
"electron-prebuilt": "1.3.3",
"events": "^1.1.0",
"mime": "^1.3.4",
"minimist": "^1.2.0",
"mock-stdin": "^0.3.0",
"object-assign": "^4.0.1",
"rc": "^1.1.6",
"resolve": "^1.1.7",
"serializerr": "^1.0.2",
"sliced": "^1.0.1",
"strip-bom": "^2.0.0",
@ -32,7 +33,7 @@
"devDependencies": {
"awesome-streetview": "^1.4.2",
"babel-plugin-transform-es2015-template-literals": "^6.3.13",
"babel-register": "^6.4.3",
"babel-register": "^6.11.6",
"bluebird": "^3.1.5",
"browserify": "^13.0.0",
"concat-stream": "^1.5.1",

1
test/fixtures/log-random.js

@ -0,0 +1 @@
console.log(Math.random());
Loading…
Cancel
Save