Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@mizchi 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

This comment has been minimized.

Copy link

@keeth 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