Welcome to my webpack starter for microverse projects. This is for general projects. For phaser game development, use this starter
clone repo and run
npm install
All files are in src folder. There is no need for a dist folder. script tags and style tags for files in src in html are also not necessary. They will be auto injected by webpack. You can put CDN links for bootstrap, font-awesome etc in the html file in src folder.
- Write your html in
src/index.html
file. - Write your javascript in
src/
. - Write your styles in
src/index.scss
and import it inindex.js
import 'index.scss';
- The final project assets will be in the
dist
folder after the build command in production section below. This is useful for publishing to github and for the lighthouse linter in github.
You have live updates for javacript and scss in localhost:3000
. Refresh after changes to html.
- Run this in your terminal and keep it running, the project will be available live with hot reloading at
localhost:3000
. Happy programming : )
npm run dev
- Keep the import for scss in
index.js
if you want scss styles.
import 'index.scss';
You can change localhost:port number in webpack/webpack.config.dev.js's port property
devServer: {
contentBase: "./dist",
hot: true,
port: "3000", //change here to your port
}
if you want html in dist folder instead of src folder
remove the plugin HtmlWebpackPlugin
. You can also remove the Dotenv
plugin if you are not using any .env
file.
plugins: [
new Dotenv(),
new HtmlWebpackPlugin({ //remove this line
filename: "index.html", // remove this line
template: "/src/index.html", //remove this line
inject: true, // remove this line
}), // remove this line
],
create an .env
file for your variables
API_KEY=20r8304283yourkeyexample
and import it in js
const API_KEY = process.env.API_KEY
- Your eslint might use destructuring syntax
{ API_KEY }
. As said in the documentation for dotenv-webpack, please use the syntax I have shown above if the environment variable isundefined
if you are not using any environment variables, you can also safely remove the new Dotenv()
plugin from the webpack config files.
All commands have --fix appended internally already.
One command for all linters
npm run linters
- eslint
npm run eslint
- stylelint
npm run lint
- webhint
npm run hint
One command to create production code and publish it live on github. Run this after project completion. Also helpful for lighthouse linter on github pull request.
npm run publish
or seperately run,
- Build final production project build
npm run build
- Run in terminal to push your created
dist
folder to github to get a live website on github
npm run live
Contributions, issues, and feature requests are welcome!
Feel free to check the issues page.
Give a ⭐️ if you like this project!
👤 Samrood Ali
- GitHub: @samroodAli
- LinkedIn: Samrood-Ali