mkdir project-folder
cd project-folder
npm init
npm i -D webpack webpack-cli
npm i -D babel-core babel-loader babel-preset-react
{
"presets" : [
" react"
]
}
"scripts" : {
"dev" : " webpack --mode development" ,
"build" : " webpack --mode production"
}
"scripts" : {
"dev" : " webpack --mode development --watch" ,
"build" : " webpack --mode production --watch"
}
npm i -D css-loader style-loader node-sass sass-loader
npm i -D postcss-loader autoprefixer
npm i -D webpack-dev-server
npm i -D html-webpack-plugin
mini-css-extract plugin
npm i -D mini-css-extract-plugin
const path = require ( 'path' ) ;
const autoprefixer = require ( 'autoprefixer' ) ;
const HtmlWebPackPlugin = require ( "html-webpack-plugin" ) ;
const MiniCssExtractPlugin = require ( "mini-css-extract-plugin" ) ;
const htmlPlugin = new HtmlWebPackPlugin ( {
template : "./src/index.html" ,
filename : "./index.html"
} ) ;
const miniCssPlugin = new MiniCssExtractPlugin ( {
// chunk version for cache refresh
// filename: 'style.[contentHash].css',
filename : 'style.css' ,
} ) ;
module . exports = {
entry : { main : './src/index.js' } ,
output : {
path : path . resolve ( __dirname , 'dist' ) ,
// hashing for cache refresh
// filename: 'main.[chunkHash].js',
filename : 'main.js' ,
publicPath : '/'
} ,
devServer : {
historyApiFallback : true
} ,
module : {
rules : [
{
test : / \. j s $ / ,
exclude : / n o d e _ m o d u l e s / ,
use : {
loader : "babel-loader"
}
} ,
{
test : / \. s c s s $ / ,
use : [
'style-loader' ,
MiniCssExtractPlugin . loader ,
'css-loader' ,
'sass-loader'
]
}
]
} ,
plugins : [
htmlPlugin ,
miniCssPlugin
]
} ;
Webpack dev server scripts
webpack-dev-server --mode development --open