Last active
January 30, 2023 06:02
-
-
Save Rootdiv/efb822fc1c0e539e99f410823dea1c95 to your computer and use it in GitHub Desktop.
browser-sync-webpack-plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* webpack.config.js для марафона Интернет-магазин гаджетов (27.06.2022 - 10.07.2022) | |
с возможностью запуска 2-х браузеров через browser-sync-webpack-plugin */ | |
const path = require('path'); | |
const HtmlWebpackPlugin = require('html-webpack-plugin'); | |
const MiniCssExtractPlugin = require('mini-css-extract-plugin'); | |
const Critical = require('critical-css-webpack-plugin'); | |
const BrowserSyncWebpackPlugin = require('browser-sync-webpack-plugin'); | |
const PAGES = ['index', 'cart', 'card']; | |
const mode = process.env.NODE_ENV || 'development'; | |
const devMode = mode === 'development'; | |
const target = devMode ? 'web' : 'browserslist'; | |
const devtool = devMode ? 'source-map' : undefined; | |
module.exports = { | |
mode, | |
target, | |
devtool, | |
devServer: { | |
port: 3000, | |
open: { | |
app: { | |
name: 'google-chrome', | |
arguments: ['--new-window'], | |
}, | |
}, | |
hot: true, | |
}, | |
entry: ['@babel/polyfill', path.resolve(__dirname, 'src', 'index.js')], | |
output: { | |
path: path.resolve(__dirname, 'dist'), | |
clean: true, | |
filename: '[name].[contenthash].js', | |
assetModuleFilename: 'assets/[name][ext]', | |
}, | |
plugins: [ | |
...PAGES.map( | |
page => | |
new HtmlWebpackPlugin({ | |
template: path.resolve(__dirname, 'src', `${page}.html`), | |
filename: `${page}.html`, | |
}), | |
), | |
new MiniCssExtractPlugin({ | |
filename: '[name].[contenthash].css', | |
}), | |
new BrowserSyncWebpackPlugin( | |
{ | |
ui: false, | |
notify: false, | |
proxy: 'http://localhost:3000/', | |
browser: 'firefox', | |
}, | |
{ | |
reload: false, | |
}, | |
), | |
...(devMode ? [] : [new Critical()]), | |
], | |
module: { | |
rules: [ | |
{ | |
test: /\.html$/i, | |
loader: 'html-loader', | |
}, | |
{ | |
test: /\.(c|sa|sc)ss$/i, | |
use: [ | |
devMode ? 'style-loader' : MiniCssExtractPlugin.loader, | |
'css-loader', | |
{ | |
loader: 'postcss-loader', | |
options: { | |
postcssOptions: { | |
plugins: [require('postcss-preset-env')], | |
}, | |
}, | |
}, | |
'group-css-media-queries-loader', | |
'sass-loader', | |
], | |
}, | |
{ | |
test: /\.woff2?$/i, | |
type: 'asset/resource', | |
generator: { | |
filename: 'fonts/[name][ext]', | |
}, | |
}, | |
{ | |
test: /\.(jpe?g|png|webp|gif|svg)$/i, | |
use: [ | |
{ | |
loader: 'image-webpack-loader', | |
options: { | |
mozjpeg: { | |
progressive: true, | |
}, | |
optipng: { | |
enabled: false, | |
}, | |
pngquant: { | |
quality: [0.65, 0.9], | |
speed: 4, | |
}, | |
gifsicle: { | |
interlaced: false, | |
}, | |
webp: { | |
quality: 75, | |
}, | |
}, | |
}, | |
], | |
type: 'asset/resource', | |
}, | |
{ | |
test: /\.js$/i, | |
exclude: /node_modules/, | |
use: { | |
loader: 'babel-loader', | |
options: { | |
presets: ['@babel/preset-env'], | |
}, | |
}, | |
}, | |
], | |
}, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment