Closed isabellachen closed 6 years ago
plugin code won't get hot-reloaded, AFAIK. But you could use watch if you're sick of manually restarting the dev server.
npm install watch kill-port --save-dev
in your project root.
.
Add this to your npm scripts:
"dev-plugins": "watch 'kill-port --port 8000 && gatsby develop' plugins "
Now you can npm run dev-plugins
It' will watch your plugins directory and will restart the dev server every time you make changes in the plugins directory.
@zabute I'm unable to get it to work :(
"watch": {
"restart": "plugins/gatsby-source-eventbrite/*.js"
},
"scripts": {
"dev-plugins": "watch 'kill-port --port 8000 && gatsby develop' plugins ",
"watch": "npm-watch",
"build": "gatsby build",
"develop": "gatsby develop",
"format": "prettier --write 'src/**/*.js'",
"test": "echo \"Error: no test specified\" && exit 1"
},
@zabute There‘s no need for an extra package as gatsby-dev-cli has everything included: https://next.gatsbyjs.org/docs/how-to-contribute/#contributing-to-the-repo
The process described there makes it easier to develop a plugin.
@zabute nice solution! @isabellachen did you install the new dependencies first? Did you get an error when you ran the npm script? How did it not work?
Since @zabute provided a nice solution, I'll close this. @zabute it could make sense to add this to the plugin authoring docs somewhere as well https://next.gatsbyjs.org/docs/plugins/
My bad, I did not install kill-port. Solution works nicely :) Thanks :)
Although I'm unable to exit the process with ^C. Seems like I need to kill -9 the process in another terminal window. Not an issue, only wondering if it was the expected behaviour...?
@KyleAMathews Actually, the issues was that I was transpiling the code in plugins/src and chucking them out in the root of the gatsby-source-eventbrite, so @zabute 's solution was watching for changes in /src but the changes were not being reflected. I suppose the only solution is to develop in the gatsby-plugin-eventbrite folder and then at the end put the code in /src ...
@LekoArts can you elaborate on how to use the gatsby dev cli to restart dev server on plugin changes? Is that what you're implying above?
edit: This is what I had to set up with npm-watch to get it to work. Granted I'm working on a local site plugin, not one to be published.
"scripts": {
"build": "gatsby build",
"dev": "gatsby develop",
"format": "prettier --write \"**/*.{js,jsx,json,md}\"",
"start": "npm run dev",
"restart": "kill-port --port 8000 && gatsby develop",
"watch": "npm-watch restart",
"serve": "gatsby serve",
"test": "echo \"Write tests! -> https://gatsby.dev/unit-testing \""
},
"watch": {
"restart": "plugins/**/*.js"
},
If gatsby-node files can't be hot reloaded, it might be nice to add a flag like gatsby develop --watch-configs
(lame label there but you get it) to restart gatsby develop when gatsby-*.js files change in root.
Summary
While developing a source plugin, I realise I have to
^c
to escape the current build andgatsby develop
again to see the console.logs in the terminal. Is there a way to get gatsby to run the gatsby-node.js file in the plugins/gatsby-source-eventbrite folder when I save changes instead of having to manually escape and rungatsby develop
again?I installed nodemon in the gatsby-source-eventbrite folder but I'm unsure how to configure it ... but I don't think it works this way since gatsby develop from the root passes in the config options and creates the nodes and such...
Relevant information
My folder structure source-eventbrite-site //
gatsby develop
from the root -- plugins ------ gatsby-source-eventbrite -------- gatsby-node.js // watch this file for changesEnvironment (if relevant)
System: OS: macOS High Sierra 10.13.6 CPU: x64 Intel(R) Core(TM) i5-7267U CPU @ 3.10GHz Shell: 5.3 - /bin/zsh Binaries: Node: 10.1.0 - ~/.nvm/versions/node/v10.1.0/bin/node Yarn: 1.6.0 - /usr/local/bin/yarn npm: 6.0.1 - ~/.nvm/versions/node/v10.1.0/bin/npm Browsers: Chrome: 68.0.3440.106 Safari: 11.1.2 npmGlobalPackages: gatsby-cli: 1.1.58
File contents (if changed)
gatsby-config.js
: N/Apackage.json
gatsby-node.js
: N/Agatsby-browser.js
: N/Agatsby-ssr.js
: N/A