Skip to content

Instantly share code, notes, and snippets.

@mizchi
Last active December 6, 2019 21:20
Show Gist options
  • Save mizchi/0a669a289ac743b1f2ee20d9fedc5d77 to your computer and use it in GitHub Desktop.
Save mizchi/0a669a289ac743b1f2ee20d9fedc5d77 to your computer and use it in GitHub Desktop.
minimum webpack with babel
/*
yarn init -y
yarn add webpack webpack-cli webpack-serve html-webpack-plugin -D
yarn add babel-loader@^8.0.0-beta @babel/core @babel/preset-env -D
echo '{ "presets": ["@babel/preset-env"] }' > .babelrc
*/
const HtmlPlugin = require("html-webpack-plugin");
module.exports = {
mode: process.env.NODE_ENV || "development",
entry: ["./src/index.js"],
output: {
filename: "bundle.js",
path: __dirname + "/public",
publicPath: "/"
},
module: {
rules: [
{
test: /\.js$/,
use: "babel-loader",
exclude: /node_modules/
}
]
},
plugins: [new HtmlPlugin()]
};
@mizchi
Copy link
Author

mizchi commented Jul 19, 2018

Expected dir

src/
  index.js
public/
  bundle.js
  index.html
.babelrc
webpack.config.js
package.json

  • yarn webpack: build
  • NODE_ENV=production yarn webpack: production build
  • yarn webpack-serve --port 3333: start watch server

@keeth
Copy link

keeth commented Dec 6, 2019

I went to http://localhost:3333/public and I get a 404 on /bundle.js

This fixed it:

publicPath: "/public"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment