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 14

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

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

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

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

73 74 75 76 77 78 79 80 81
  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 已提交
82
    }),
P
Phil Hughes 已提交
83
    new webpack.IgnorePlugin(/moment/, /pikaday/),
M
Mike Greiling 已提交
84 85 86
  ],

  resolve: {
M
Mike Greiling 已提交
87
    extensions: ['.js', '.es6', '.js.es6'],
88
    alias: {
89
      '~':              path.join(ROOT_PATH, 'app/assets/javascripts'),
90 91 92 93 94
      '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'),
      'vue$':           'vue/dist/vue.js',
      'vue-resource$':  'vue-resource/dist/vue-resource.js'
95
    }
M
Mike Greiling 已提交
96
  }
97 98
}

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

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

module.exports = config;