A template you can use when creating a new repository to immediately get started with your project! All that you need is to follow the quick setup below.
- npm init -y
- npm install -D webpack webpack-cli html-webpack-plugin style-loader css-loader html-loader webpack-dev-server
- npm init -y
- npm install --save-dev webpack webpack-cli
- npm install --save-dev html-webpack-plugin
- npm install --save-dev style-loader css-loader
- npm install --save-dev html-loader
- npm install --save-dev webpack-dev-server
- touch webpack.config.js
- mkdir src && touch src/index.js src/another.js
- touch src/template.html
- touch src/styles.css
- optional npm install -D babel-loader @babel/core @babel/preset-env webpack
npx webpack serve or npm run dev
"scripts": { "test": "echo "Error: no test specified" && exit 1", "build": "webpack", "dev": "webpack serve", "deploy": "git subtree push --prefix dist origin gh-pages" },
- make a new branch to deploy from (git branch gh-pages)
- commit any remaining work and push
- git checkout gh-pages && git merge main --no-edit
- npx webpack or npm run build
- git add dist -f && git commit -m "deployment commit"
- git subtree push --prefix dist origin gh-pages
- git checkout main
const path = require("path"); const HtmlWebpackPlugin = require("html-webpack-plugin");
module.exports = { mode: "development", entry: "./src/index.js", output: { filename: "main.js", path: path.resolve(__dirname, "dist"), clean: true, }, devtool: "eval-source-map", devServer: { watchFiles: ["./src/template.html"], }, plugins: [ new HtmlWebpackPlugin({ template: "./src/template.html", }), ], module: { rules: [ { test: /.css$/i, use: ["style-loader", "css-loader"], }, { test: /.html$/i, loader: "html-loader", }, { test: /.(png|svg|jpg|jpeg|gif)$/i, type: "asset/resource", }, { // optional test: /.(?:js|mjs|cjs)$/, exclude: /node_modules/, use: { loader: 'babel-loader', options: { targets: "defaults", presets: [ ['@babel/preset-env'] ] } } } ], }, };