webpack.config.js 4.1 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

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

var config = {
16
  context: path.join(ROOT_PATH, 'app/assets/javascripts'),
17
  entry: {
18 19 20
    application:          './application.js',
    blob_edit:            './blob_edit/blob_edit_bundle.js',
    boards:               './boards/boards_bundle.js',
P
Phil Hughes 已提交
21
    simulate_drag:        './test_utils/simulate_drag.js',
22
    cycle_analytics:      './cycle_analytics/cycle_analytics_bundle.js',
F
Filipa Lacerda 已提交
23
    commit_pipelines:     './commit/pipelines/pipelines_bundle.js',
24 25
    diff_notes:           './diff_notes/diff_notes_bundle.js',
    environments:         './environments/environments_bundle.js',
F
Filipa Lacerda 已提交
26
    environments_folder:  './environments/folder/environments_folder_bundle.js',
27
    filtered_search:      './filtered_search/filtered_search_bundle.js',
28
    graphs:               './graphs/graphs_bundle.js',
29
    issuable:             './issuable/issuable_bundle.js',
30 31 32 33 34 35 36 37 38
    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',
39
    lib_d3:               './lib/d3.js',
40
    lib_vue:              './lib/vue_resource.js',
M
Mike Greiling 已提交
41
    vue_pipelines:        './vue_pipelines_index/index.js',
42 43 44 45 46 47 48 49
  },

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

M
Mike Greiling 已提交
50
  devtool: 'inline-source-map',
51

M
Mike Greiling 已提交
52
  module: {
M
Mike Greiling 已提交
53
    rules: [
M
Mike Greiling 已提交
54
      {
55 56
        test: /\.(js|es6)$/,
        exclude: /(node_modules|vendor\/assets)/,
57
        loader: 'babel-loader',
M
Mike Greiling 已提交
58 59 60 61 62
        options: {
          presets: [
            ["es2015", {"modules": false}],
            'stage-2'
          ]
63
        }
M
Mike Greiling 已提交
64 65 66 67
      }
    ]
  },

68 69 70 71 72 73 74 75 76
  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 已提交
77
    }),
P
Phil Hughes 已提交
78
    new webpack.IgnorePlugin(/moment/, /pikaday/),
M
Mike Greiling 已提交
79 80 81
  ],

  resolve: {
M
Mike Greiling 已提交
82
    extensions: ['.js', '.es6', '.js.es6'],
83
    alias: {
84
      '~':              path.join(ROOT_PATH, 'app/assets/javascripts'),
85 86 87
      'bootstrap/js':   'bootstrap-sass/assets/javascripts/bootstrap',
      'emoji-aliases$': path.join(ROOT_PATH, 'fixtures/emojis/aliases.json'),
      'vendor':         path.join(ROOT_PATH, 'vendor/assets/javascripts'),
88
      'vue$':           IS_PRODUCTION ? 'vue/dist/vue.min.js' : 'vue/dist/vue.js',
89
    }
M
Mike Greiling 已提交
90
  }
91 92
}

93
if (IS_PRODUCTION) {
M
Mike Greiling 已提交
94
  config.devtool = 'source-map';
95
  config.plugins.push(
96
    new webpack.NoEmitOnErrorsPlugin(),
M
Mike Greiling 已提交
97 98 99 100
    new webpack.LoaderOptionsPlugin({
      minimize: true,
      debug: false
    }),
101
    new webpack.optimize.UglifyJsPlugin({
M
Mike Greiling 已提交
102
      sourceMap: true
103 104 105
    }),
    new webpack.DefinePlugin({
      'process.env': { NODE_ENV: JSON.stringify('production') }
106 107 108
    }),
    new CompressionPlugin({
      asset: '[path].gz[query]',
M
Mike Greiling 已提交
109
    })
110
  );
111 112 113
}

if (IS_DEV_SERVER) {
114 115
  config.devServer = {
    port: DEV_SERVER_PORT,
116 117
    headers: { 'Access-Control-Allow-Origin': '*' },
    stats: 'errors-only',
118
    inline: DEV_SERVER_LIVERELOAD
119 120 121 122 123
  };
  config.output.publicPath = '//localhost:' + DEV_SERVER_PORT + config.output.publicPath;
}

module.exports = config;