summaryrefslogtreecommitdiff
path: root/config/webpack.config.review_toolbar.js
blob: baaba7ed387ed4c08ad2520f4a7c3d240b29d3b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
const path = require('path');
const CompressionPlugin = require('compression-webpack-plugin');

const ROOT_PATH = path.resolve(__dirname, '..');
const CACHE_PATH = process.env.WEBPACK_CACHE_PATH || path.join(ROOT_PATH, 'tmp/cache');
const NO_SOURCEMAPS = process.env.NO_SOURCEMAPS;
const IS_PRODUCTION = process.env.NODE_ENV === 'production';

const devtool = IS_PRODUCTION ? 'source-map' : 'cheap-module-eval-source-map';

const alias = {
  vendor: path.join(ROOT_PATH, 'vendor/assets/javascripts'),
  spec: path.join(ROOT_PATH, 'spec/javascripts'),
};

module.exports = {
  mode: IS_PRODUCTION ? 'production' : 'development',

  context: path.join(ROOT_PATH, 'app/assets/javascripts'),

  name: 'visual_review_toolbar',

  entry: './visual_review_toolbar',

  output: {
    path: path.join(ROOT_PATH, 'public/assets/webpack'),
    filename: 'visual_review_toolbar.js',
    library: 'VisualReviewToolbar',
    libraryTarget: 'var',
  },

  resolve: {
    alias,
  },

  module: {
    rules: [
      {
        test: /\.js$/,
        loader: 'babel-loader',
        options: {
          cacheDirectory: path.join(CACHE_PATH, 'babel-loader'),
        },
      },
      {
        test: /\.css$/,
        use: ['style-loader', 'css-loader'],
      },
    ],
  },

  plugins: [
    // compression can require a lot of compute time and is disabled in CI
    new CompressionPlugin(),
  ].filter(Boolean),

  devtool: NO_SOURCEMAPS ? false : devtool,
};