webpack.config.js 4.0 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',
25
    filtered_search:      './filtered_search/filtered_search_bundle.js',
26
    graphs:               './graphs/graphs_bundle.js',
27
    issuable:             './issuable/issuable_bundle.js',
28 29 30 31 32 33 34 35 36
    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',
37
    lib_d3:               './lib/d3.js',
38
    lib_vue:              './lib/vue_resource.js',
M
Mike Greiling 已提交
39
    vue_pipelines:        './vue_pipelines_index/index.js',
40 41 42 43 44 45 46 47
  },

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

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

M
Mike Greiling 已提交
50 51 52
  module: {
    loaders: [
      {
53 54
        test: /\.(js|es6)$/,
        exclude: /(node_modules|vendor\/assets)/,
55 56
        loader: 'babel-loader',
        query: {
M
Mike Greiling 已提交
57
          presets: ['es2015', 'stage-2']
58
        }
59 60 61
      },
      {
        test: /\.(js|es6)$/,
62
        exclude: /node_modules/,
63
        loader: 'imports-loader',
64
        query: 'this=>window'
65 66 67 68
      },
      {
        test: /\.json$/,
        loader: 'json-loader'
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 83 84 85
    }),
    new CompressionPlugin({
      asset: '[path].gz[query]',
    }),
M
Mike Greiling 已提交
86 87 88
  ],

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

101
if (IS_PRODUCTION) {
M
Mike Greiling 已提交
102
  config.devtool = 'source-map';
103 104 105 106 107 108 109 110 111 112 113
  config.plugins.push(
    new webpack.NoErrorsPlugin(),
    new webpack.optimize.UglifyJsPlugin({
      compress: { warnings: false }
    }),
    new webpack.DefinePlugin({
      'process.env': { NODE_ENV: JSON.stringify('production') }
    }),
    new webpack.optimize.DedupePlugin(),
    new webpack.optimize.OccurrenceOrderPlugin()
  );
114 115 116
}

if (IS_DEV_SERVER) {
117 118 119 120 121 122 123 124
  config.devServer = {
    port: DEV_SERVER_PORT,
    headers: { 'Access-Control-Allow-Origin': '*' }
  };
  config.output.publicPath = '//localhost:' + DEV_SERVER_PORT + config.output.publicPath;
}

module.exports = config;