Skip to content

Instantly share code, notes, and snippets.

@markodayan
Last active April 22, 2020 21:30
Show Gist options
  • Save markodayan/331c4b73d915811a21e8b319a4aa7043 to your computer and use it in GitHub Desktop.
Save markodayan/331c4b73d915811a21e8b319a4aa7043 to your computer and use it in GitHub Desktop.
Webpack configs
{
"name": "chapter-19",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "node_modules/.bin/webpack --mode production",
"serve": "webpack-dev-server --mode development"
},
"author": "",
"license": "ISC",
"devDependencies": {
"@babel/cli": "^7.8.4",
"@babel/core": "^7.9.0",
"@babel/preset-env": "^7.9.5",
"webpack": "^4.43.0",
"webpack-cli": "^3.3.11"
},
"dependencies": {
"webpack-dev-server": "^3.10.3"
}
}
const path = require('path');
module.exports = {
entry: './src/index.js',
output: {
path: path.resolve(__dirname, 'dist/assets'),
filename: 'bundle.js',
},
devServer: {
contentBase: path.resolve(__dirname, 'dist'),
publicPath: '/assets/',
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'],
},
},
},
],
},
};
# create 'webpack.config.js' in root dir
#install webpack and cli as dev dependencies
npm i webpack webpack-cli -D
# run webpack
node_modules/.bin/webpack
#or below after creating a script in package.json
npm run webpack
# install webpack dev server
npm i webpack-dev-server
# install babel-loader to use babel to convert js to compatible code for older browsers
npm install babel-loader -D
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment