Advertisement
Guest User

Untitled

a guest
Apr 9th, 2018
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const HtmlWebpackPlugin = require('html-webpack-plugin');
  2. const path = require('path');
  3. const webpack = require('webpack');
  4. const normalize = require('node-normalize-scss').includePaths;
  5. const MiniCssExtractPlugin = require('mini-css-extract-plugin');
  6.  
  7. const sourcePath = path.join(__dirname, 'src');
  8. const buildPath = path.join(__dirname, 'dist');
  9.  
  10. module.exports = env => {
  11.   const NODE_ENV = env ? env.NODE_ENV : 'developmet';
  12.  
  13.   return {
  14.     entry: {
  15.       app: path.resolve(sourcePath, 'entrypoint.js'),
  16.       common: ['react', 'react-dom']
  17.     },
  18.     output: {
  19.       path: buildPath,
  20.       chunkFilename: '[name]-[chunkhash:7].js',
  21.       publicPath: '/admin/'
  22.     },
  23.     module: {
  24.       rules: [
  25.         {
  26.           test: /\.(sass|scss|css)$/,
  27.           use: [
  28.             MiniCssExtractPlugin.loader,
  29.             'css-loader',
  30.             'postcss-loader',
  31.             `sass-loader?includePaths[]=${normalize}`
  32.           ]
  33.         },
  34.         {
  35.           test: /\.html$/,
  36.           exclude: /(node_modules)/,
  37.           use: [{ loader: 'html-loader', options: { minimize: true } }]
  38.         },
  39.         {
  40.           test: /\.(js)$/,
  41.           exclude: /(node_modules|assets)/,
  42.           use: ['babel-loader']
  43.         },
  44.         {
  45.           test: /\.(png|jpe?g|gif|svg)$/i,
  46.           use: ['file-loader?limit=5000&name=assets/images/[name].[ext]']
  47.         },
  48.         {
  49.           test: /\.(woff|woff2|ttf|eot)$/,
  50.           use: ['file-loader?name=fonts/[name].[ext]']
  51.         },
  52.         {
  53.           test: /\.(ico)$/,
  54.           exclude: /(node_modules)/,
  55.           use: [
  56.             {
  57.               loader: 'file-loader',
  58.               options: {
  59.                 name: '[name].[ext]'
  60.               }
  61.             }
  62.           ]
  63.         }
  64.       ]
  65.     },
  66.     plugins: [
  67.       new webpack.ProvidePlugin({
  68.         $: 'jquery/dist/jquery.min',
  69.         jQuery: 'jquery/dist/jquery.min',
  70.         'window.jQuery': 'jquery/dist/jquery.min'
  71.       }),
  72.  
  73.       new HtmlWebpackPlugin({
  74.         template: 'assets/index.html',
  75.         filename: 'index.html',
  76.         favicon: 'assets/favicon.ico'
  77.       }),
  78.       new MiniCssExtractPlugin({
  79.         filename: '[name].css',
  80.         chunkFilename: '[id].css'
  81.       })
  82.     ]
  83.   };
  84. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement