Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //// webpack.conf
  2.  
  3. const HtmlWebpackPlugin = require('html-webpack-plugin');
  4. const path = require('path');
  5.  
  6. module.exports = (env, argv) =>  ({
  7.     entry: path.resolve(__dirname, 'src/scripts/index.js'),
  8.     devServer: {
  9.         contentBase: path.join(__dirname, '.'),
  10.         compress: true,
  11.         port: 8080
  12.     },
  13.     devtool:  argv.mode === 'production' ? false : 'source-map',
  14.     mode: argv.mode || 'development',
  15.     output: {
  16.         filename: 'bundle.js',
  17.         path: path.resolve(__dirname, 'dist')
  18.     },
  19.     plugins: [new HtmlWebpackPlugin()],
  20.     module: {
  21.         rules: [
  22.             {
  23.                 test: /\.js$/,
  24.                 exclude: /node_modules/,
  25.                 use: {
  26.                     loader: 'babel-loader',
  27.                     options: {
  28.                         presets: ['@babel/preset-env'],
  29.                         cacheDirectory: true
  30.                     },
  31.                 }
  32.             },
  33.             {
  34.                 test: /\.s?css$/,
  35.                 use: [
  36.                     'style-loader',
  37.                     {
  38.                         loader: 'css-loader',
  39.                         options: {
  40.                             sourceMap: argv.mode !== 'production'
  41.                         }
  42.                     },
  43.                     {
  44.                         loader: 'postcss-loader',
  45.                         options: {
  46.                             ident: 'postcss',
  47.                             plugins: [
  48.                                 require('autoprefixer'),
  49.                             ]
  50.                         }
  51.                     },
  52.                     'sass-loader'
  53.                 ]
  54.             },
  55.             {
  56.                 test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2)$/i,
  57.                 use: [
  58.                     'url-loader?limit=10000',
  59.                     {
  60.                         loader: 'img-loader',
  61.                         options: {
  62.                             plugins: [
  63.                                 require('imagemin-gifsicle')({
  64.                                     interlaced: false
  65.                                 }),
  66.                                 require('imagemin-mozjpeg')({
  67.                                     progressive: true,
  68.                                     arithmetic: false
  69.                                 }),
  70.                                 require('imagemin-pngquant')({
  71.                                     floyd: 0.5,
  72.                                     speed: 2
  73.                                 }),
  74.                                 require('imagemin-svgo')({
  75.                                     plugins: [
  76.                                         { removeTitle: true },
  77.                                         { convertPathData: false }
  78.                                     ]
  79.                                 })
  80.                             ]
  81.                         }
  82.                     }
  83.                 ]
  84.             },
  85.         ]
  86.     }
  87. })
  88.  
  89.  
  90.  
  91.  
  92. /// package.json
  93.  
  94.   "scripts": {
  95.     "start:dev": "webpack-dev-server",
  96.     "build": "webpack --mode production"
  97.   },
  98.  
  99.   "browserslist": [
  100.     "defaults",
  101.     "not ie < 11",
  102.     "last 2 versions",
  103.     "> 1%",
  104.     "iOS 7",
  105.     "last 3 iOS versions"
  106.   ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement