-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Internal dev watching/rebuilding script and commander interface #36
Internal dev watching/rebuilding script and commander interface #36
Conversation
…ix/webpack-errors
…s if alreayd exist
Another problem is we would still require a separate generateBuild function because we have to reuse it so we can't have the same script automatically run it be used for importing that to webpack.config.develop.js |
@hutchgrant |
Fixed the live-reload! Now back to the other 404 and link reload problem which comes from using routes that rely on redux store. In CEA for example, webpack will automatically route 404s to the index.html file.
I would like it if we could do that via webpack, but if not, I believe there is a plugin to insert a script into the index.html, specifically we could use it for reloading the url from redux. Also we could include a 404.html and have that bundled only in development(in addition to script insert). |
Problem with live-reload is compilation var wasn't being reintialized, so we'd have duplicate pages/routes. The 404 redirect issue in development has been fixed, as well as a default template 404.html has been added in production. Another day we can allow more user control of 404.html |
There is a problem with the webpack rewrite plugin within |
Nice, lot of work here for me to check out! 💪 As a note, and not sure if you have HMR working too, but I think we treat livereload as a different features, given that I see HMR as an extended feature on top of livereload, but not as necessary (in the context of this PR). So if live reload is working, awesome. If HMR isn't working, no worries, let's make it an issue we can work on after this task. |
|
||
module.exports = webpackMerge(commonConfig, { | ||
|
||
mode: 'development', | ||
|
||
devServer: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you explain the reasoning for for moving this out of the development config?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when running webpack-dev-server within node, it didn't appear to be doing anything in my initial tests. When you add it as a second parameter in develop.js
, it seemed to work.
e.g. toggle hot var in both develop.js
and then try it in webpack.config.commons.js
using the standard devServer object. You'll notice, turning it on does nothing in the webpack config, but does work in develop.js
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, let me a take a look at this one. being able to keep it in the webpack config file seems to make the most sense of extending it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking pretty, pretty, pretty good!
Just left some final comments and I think most can be put into issues, so let me know your thoughts and if you could leave a final comment with any / open items you think we should track, let me know and then we can merge this!!
}, | ||
entry: [ | ||
'webpack-dev-server/client?http://localhost:1981', | ||
path.join(process.cwd(), '.greenwood', 'app', 'app.js') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we should add a TODO or an issue to make sure we go around and clean up any hardcoded paths / strings and pull them from the compilation
object?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just was reminded that there is a TODO above that line in the same file, for the consolidating of the compilation. Do you want to add the TODO to every instance of a hardcoded string? I think its a bit redundant, as long as we have at least one TODO we know there's hardcoded string in that file related to issue #11
edit: woops the common config has it not the develop, which I will add
const generateGraph = require('./graph'); | ||
const generateScaffolding = require('./scaffold'); | ||
|
||
let config = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
anyway to keep this closer to the "top" like in index.js? Having this single source of truth / configuration I think would be beneficial for keeping all the tasks / configs / in lockstep?
As an improvement issue instead, maybe we could put this into a file, and import
it in index.js to establish all the defaults, and then pass that around to all the tasks, modifying it based on "userland" configurations in index.js first?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer the latter idea. Though functionally it makes sense to have carry through from beginning in index.js
but it looks so out of place within that file.
package.json
Outdated
"dev-build": "export NODE_ENV=development && yarn build", | ||
"dev-watch": "nodemon --watch src --exec 'yarn dev-build'", | ||
"dev-serve": "webpack-dev-server --config ./packages/cli/config/webpack.config.develop.js --open", | ||
"dev": "node ./packages/cli/index.js dev", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, could keep this develop through and through? (task, command, filename?). 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want, I like less characters to type tbh
} | ||
}; | ||
|
||
const publicPath = '/'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i see this in prod config too. (publicPath
). should we be in webpack.config.common.js?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree its a dupe however, where it is used is specific to dev and prod only not both.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That should come from a config/compilation object as well. #11
the base for this branch was #22 are we switching it to master then? |
ah, didn't realize that. assumed it was just an alternate version to consider. I will repoint the branch. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty much there, just want to note a couple things:
[ ] Just opened up #39 to do a quick refactor of the webpack dev server config
[x] We should see if we can improve the double index and 404 file maintenance, made #38
[x] Noted some more TODOs in the description of #11 as identified in this PR
and this is good to merge
…de-webpack-config-mini-refactor small webpack config refactor for development mode
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
Related Issue
Resolves #25 and #14
Summary of Changes
Whew this is a big list but here it goes...
index.js
index.js
, the main entry for the greenwood cli package, is now dedicated as a root control or main() file, with nearly as little individual function calls as possible. It only deals with calling the specific scripts for each mode, based on whatever args are submitted. It also deals with the commander display/control.most the previous
run()
functions from theindex.js
main entry file have been removed. Well where are they? Why would you do that? Well they could be split into 2 categories:So the former category is all we need to call in "dev" mode. We also need to call it not once but twice. Once when we're running the full build (generated components and serializing) and another when we want to run the dev(as well as rebuilding from webpack when a file is changed!).
Therefore, this made sense to have its own file. It is not part of the control of the whole application. It is itself its own specific script. I have added it as
generate.js
.I've merged the latter category(serializing) in
serialize.js
as it was just a single function call, in addition to the main export fromserialize.js
.build.js
webpack.config.develop.js
added filewatcher-webpack-plugin with a custom callback onChange. This uses chokidar under the hood, its the same options as chokidar.
had to set a custom debounce. For some reason, the amount of times the onChangeCallback is called, multiplies with each change. I cannot explain what is happening but it fired at least 2 events, once I added the build script it fired more. So I just set a timeout of 1000 ms and it works fine. I left a debug console.log which you can uncomment to see what I mean.
I know what you're thinking, it must be some option you missed etc. I spent a lot of time trying all the options and reading about them to no avail.
Unit Tests
Package.json
I've simply duplicated and slightly modified our outter package.json to prepare it for the individual cli package. It's not being used at the moment.
Known Problems
lit-redux-router will not work on a fresh load of new link. We need a 404.html file to forward back to our index file, in order to get the redux URL change. e.g. a link to a url will work but if you reload the page with a url it will fail. A similar problem will happen in production too(just with 404s not page reload). I have a script to fix it but will have to implement it another time(or now?)
hot module reload doesn't appear to be working. It only worked in Adding Webpack Dev Server #22 because it was restarting dev server, which refreshed the page and gave the appearance of HMR.
need to add a callback to filewatcher plugin for when a new file is added (not just when files are changed)
filewatcher's regex is only looking for .js files in the workspace. Might be a better idea to look for other files as well such as css.
with commander, I set it to use actions rather than options. Perhaps it might be better to use options because at least they'll be listed automatically in help menu. I don't know how to list actions.
e.g. the
--help
menu:But actually we have: