decred.org/dcrdex@v1.0.3/client/webserver/site/webpack/common.js (about)

     1  const path = require('path')
     2  const webpack = require('webpack')
     3  const { CleanWebpackPlugin } = require('clean-webpack-plugin')
     4  const MiniCssExtractPlugin = require('mini-css-extract-plugin')
     5  const StyleLintPlugin = require('stylelint-webpack-plugin')
     6  const ESLintPlugin = require('eslint-webpack-plugin')
     7  
     8  const child_process = require('child_process')
     9  function git(command) {
    10    return child_process.execSync(`git ${command}`, { encoding: 'utf8' }).trim();
    11  }
    12  
    13  module.exports = {
    14    target: "web",
    15    module: {
    16      rules: [
    17        {
    18          test: /\.s?[ac]ss$/,
    19          use: [
    20            MiniCssExtractPlugin.loader,
    21            {
    22              loader: 'css-loader',
    23              options: {
    24                modules: false,
    25                url: false,
    26                sourceMap: true
    27              }
    28            },
    29            {
    30              loader: 'sass-loader',
    31              options: {
    32                implementation: require("sass"), // dart-sass
    33                sourceMap: true
    34              }
    35            }
    36          ]
    37        }
    38      ]
    39    },
    40    plugins: [
    41      new webpack.EnvironmentPlugin({
    42        COMMITHASH: git('rev-parse HEAD'),
    43      }),
    44      new CleanWebpackPlugin(),
    45      new MiniCssExtractPlugin({
    46        filename: '../dist/style.css'
    47      }),
    48      new StyleLintPlugin({
    49        threads: true,
    50      }),
    51      new ESLintPlugin({
    52        extensions: ['ts'],
    53        formatter: 'stylish'
    54      })
    55    ],
    56    output: {
    57      filename: 'entry.js',
    58      path: path.resolve(__dirname, '../dist'),
    59      publicPath: '/dist/'
    60    },
    61    resolve: {
    62      extensions: ['.ts', ".js"],
    63    },
    64    // Fixes weird issue with watch script. See
    65    // https://github.com/webpack/webpack/issues/2297#issuecomment-289291324
    66    watchOptions: {
    67      poll: true
    68    }
    69  }