Closed Anima-t3d closed 7 years ago
I have to think about this more. I'm not sure I agree on either point for a few reasons.
Have valid HTML start point
html-webpack-plugin
(preferred)
require('../index.html')
in src/index.js
+ add html
to test
in the file-loader config of webpack.config.js
html-webpack-plugin
route out of the box.Put JS and CSS in proper folders
html-webpack-plugin
it doesn't really matter because any changes to asset structure will occur automatically. If by proper you mean in an assets/
directory within dist/
- that's really easy to configure.All that said, I think after weighing the pros and cons here... including html-webpack-plugin
out-of-the-box makes the most sense in terms of package-completeness.
I've updated the package with these considerations and bumped the version to reflect potential breaking changes. I also updated the create-app script to include a search for .ejs
files when replacing {{PKG_NAME}}
.
I also noticed that when trying to add packages I got cross-env error. I added it, then I had a babel error, so I installed babel-cli. After that I could add the package I wanted to originally add. However each install it will run the npm build command. Or am I doing something wrong?
What do you mean when you say 'try to add packages'? babel-cli
is included in the package dependencies, as is cross-env
.
Installing your app runs npm build
because npm build
is included in the prepublish
script. To disable that, just remove that script from package.json
. There are very good reasons to automatically build before publishing as a default behavior.
Thanks for staying engaged by the way. Valuable feedback.
It's just that right now you cannot run build and have a ready to deploy (be it in minimal form) folder.
This is more a nice to have than really needed. For the minimal form, I see no issue with having no folders for assets. Later on you could still split it into folders and update the .html
file to point to the right paths.
What do you mean when you say 'try to add packages'?
babel-cli
is included in the package dependencies, as iscross-env
.
For example I wanted to add react-router-dom
to my app which has a dependency on your boilerplate. For some reason I could not add new packages until I resolved cross-env
and babel-cli
. Perhaps something went wrong, but I thought to bring it up.
Installing your app runs npm build because npm build is included in the prepublish script. To disable that, just remove that script from package.json. There are very good reasons to automatically build before publishing as a default behavior.
Ok, thanks.
I agree with you on both points for consistency and usability concerns. The update is live here and on npm. You will have to make some small but annoying changes to your configs on any current applications to use the solution I arrived at:
npm install --save-dev html-webpack-plugin
html-webpack-plugin
https://github.com/jaredlunde/webpack2-react-sass-env-boilerplate/blob/master/index.ejshtml-webpack-plugin
to webpack.config.js
https://github.com/jaredlunde/webpack2-react-sass-env-boilerplate/blob/master/webpack.config.js#L132-L136assets/
to output paths in webpack.config.js
And if you used the create-app
-like executable:
Replace
find . -type f \( -name "*.html" -o -name "*.js" -o -name "*.json" \) -and -not -path "*/node_modules/*" -exec sed -i.bak -e "s/{{PKG_NAME}}/${PKG_NAME}/g" {} \;;
With
find . -type f \( -name "*.html" -o -name "*.js" -o -name "*.ejs" -o -name "*.json" \) -and -not -path "*/node_modules/*" -exec sed -i.bak -e "s/{{PKG_NAME}}/${PKG_NAME}/g" {} \;;
Oh, also I couldn't replicate the issue you're having w/ cross-env and babel-cli unfortunately. I installed react-router and react-router-dom on a fresh app (on macOS) w/o issue :.
Oh, also I couldn't replicate the issue you're having w/ cross-env and babel-cli unfortunately. I installed react-router and react-router-dom on a fresh app (on macOS) w/o issue :.
I think it must have been some edge case. Most likely something along the lines of the server running and at the same time trying to add a package perhaps...
I integrated your changes and it works well. Thanks.
When running the
npm run build
ornpm run build:dist
command I don't see a usableindex.html
file in thedist
folder?For now I copied the
index.html
file from the root:And changed it to:
For it to be production ready the tool needs to be changed so it can do:
However
npm run start
works well for development.I also noticed that when trying to add packages I got
cross-env
error. I added it, then I had ababel
error, so I installedbabel-cli
. After that I could add the package I wanted to originally add. However each install it will run thenpm build
command. Or am I doing something wrong?