webpack.config.js 4.7 KB
Newer Older
1 2
'use strict';

P
Phil Hughes 已提交
3
var fs = require('fs');
4 5 6
var path = require('path');
var webpack = require('webpack');
var StatsPlugin = require('stats-webpack-plugin');
M
Mike Greiling 已提交
7
var CompressionPlugin = require('compression-webpack-plugin');
8
var BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
9

10
var ROOT_PATH = path.resolve(__dirname, '..');
11
var IS_PRODUCTION = process.env.NODE_ENV === 'production';
12
var IS_DEV_SERVER = process.argv[1].indexOf('webpack-dev-server') !== -1;
13
var DEV_SERVER_PORT = parseInt(process.env.DEV_SERVER_PORT, 10) || 3808;
14
var DEV_SERVER_LIVERELOAD = process.env.DEV_SERVER_LIVERELOAD !== 'false';
15
var WEBPACK_REPORT = process.env.WEBPACK_REPORT;
16 17

var config = {
18
  context: path.join(ROOT_PATH, 'app/assets/javascripts'),
19
  entry: {
20 21 22
    application:          './application.js',
    blob_edit:            './blob_edit/blob_edit_bundle.js',
    boards:               './boards/boards_bundle.js',
P
Phil Hughes 已提交
23
    simulate_drag:        './test_utils/simulate_drag.js',
24
    cycle_analytics:      './cycle_analytics/cycle_analytics_bundle.js',
F
Filipa Lacerda 已提交
25
    commit_pipelines:     './commit/pipelines/pipelines_bundle.js',
26 27
    diff_notes:           './diff_notes/diff_notes_bundle.js',
    environments:         './environments/environments_bundle.js',
F
Filipa Lacerda 已提交
28
    environments_folder:  './environments/folder/environments_folder_bundle.js',
29
    filtered_search:      './filtered_search/filtered_search_bundle.js',
30
    graphs:               './graphs/graphs_bundle.js',
F
Filipa Lacerda 已提交
31
    groups_list:          './groups_list.js',
32
    issuable:             './issuable/issuable_bundle.js',
33 34 35 36 37 38 39 40 41
    merge_conflicts:      './merge_conflicts/merge_conflicts_bundle.js',
    merge_request_widget: './merge_request_widget/ci_bundle.js',
    network:              './network/network_bundle.js',
    profile:              './profile/profile_bundle.js',
    protected_branches:   './protected_branches/protected_branches_bundle.js',
    snippet:              './snippet/snippet_bundle.js',
    terminal:             './terminal/terminal_bundle.js',
    users:                './users/users_bundle.js',
    lib_chart:            './lib/chart.js',
42
    lib_d3:               './lib/d3.js',
43
    lib_vue:              './lib/vue_resource.js',
M
Mike Greiling 已提交
44
    vue_pipelines:        './vue_pipelines_index/index.js',
45 46 47 48 49 50 51 52
  },

  output: {
    path: path.join(ROOT_PATH, 'public/assets/webpack'),
    publicPath: '/assets/webpack/',
    filename: IS_PRODUCTION ? '[name]-[chunkhash].js' : '[name].js'
  },

M
Mike Greiling 已提交
53
  devtool: 'inline-source-map',
54

M
Mike Greiling 已提交
55
  module: {
M
Mike Greiling 已提交
56
    rules: [
M
Mike Greiling 已提交
57
      {
58 59
        test: /\.(js|es6)$/,
        exclude: /(node_modules|vendor\/assets)/,
60
        loader: 'babel-loader',
M
Mike Greiling 已提交
61 62 63 64 65
        options: {
          presets: [
            ["es2015", {"modules": false}],
            'stage-2'
          ]
66
        }
F
Filipa Lacerda 已提交
67 68 69 70
      },
      {
        test: /\.svg$/,
        use: 'raw-loader'
M
Mike Greiling 已提交
71 72 73 74
      }
    ]
  },

75 76 77 78 79 80 81 82 83
  plugins: [
    // manifest filename must match config.webpack.manifest_filename
    // webpack-rails only needs assetsByChunkName to function properly
    new StatsPlugin('manifest.json', {
      chunkModules: false,
      source: false,
      chunks: false,
      modules: false,
      assets: true
P
Phil Hughes 已提交
84
    }),
P
Phil Hughes 已提交
85
    new webpack.IgnorePlugin(/moment/, /pikaday/),
M
Mike Greiling 已提交
86 87 88
  ],

  resolve: {
M
Mike Greiling 已提交
89
    extensions: ['.js', '.es6', '.js.es6'],
90
    alias: {
91
      '~':              path.join(ROOT_PATH, 'app/assets/javascripts'),
92 93
      'bootstrap/js':   'bootstrap-sass/assets/javascripts/bootstrap',
      'emoji-aliases$': path.join(ROOT_PATH, 'fixtures/emojis/aliases.json'),
94
      'icons':          path.join(ROOT_PATH, 'app/views/shared/icons'),
95
      'vendor':         path.join(ROOT_PATH, 'vendor/assets/javascripts'),
M
Mike Greiling 已提交
96
      'vue$':           'vue/dist/vue.common.js',
97
    }
M
Mike Greiling 已提交
98
  }
99 100
}

101
if (IS_PRODUCTION) {
M
Mike Greiling 已提交
102
  config.devtool = 'source-map';
103
  config.plugins.push(
104
    new webpack.NoEmitOnErrorsPlugin(),
M
Mike Greiling 已提交
105 106 107 108
    new webpack.LoaderOptionsPlugin({
      minimize: true,
      debug: false
    }),
109
    new webpack.optimize.UglifyJsPlugin({
M
Mike Greiling 已提交
110
      sourceMap: true
111 112 113
    }),
    new webpack.DefinePlugin({
      'process.env': { NODE_ENV: JSON.stringify('production') }
114 115 116
    }),
    new CompressionPlugin({
      asset: '[path].gz[query]',
M
Mike Greiling 已提交
117
    })
118
  );
119 120 121
}

if (IS_DEV_SERVER) {
122 123
  config.devServer = {
    port: DEV_SERVER_PORT,
124 125
    headers: { 'Access-Control-Allow-Origin': '*' },
    stats: 'errors-only',
126
    inline: DEV_SERVER_LIVERELOAD
127 128 129 130
  };
  config.output.publicPath = '//localhost:' + DEV_SERVER_PORT + config.output.publicPath;
}

131 132 133 134 135 136 137 138 139 140 141 142
if (WEBPACK_REPORT) {
  config.plugins.push(
    new BundleAnalyzerPlugin({
      analyzerMode: 'static',
      generateStatsFile: true,
      openAnalyzer: false,
      reportFilename: path.join(ROOT_PATH, 'webpack-report/index.html'),
      statsFilename: path.join(ROOT_PATH, 'webpack-report/stats.json'),
    })
  );
}

143
module.exports = config;