Rift-15726 compress code in production environment
[osm/UI.git] / skyquake / plugins / composer / webpack.production.config.js
1 /*
2 *
3 * Copyright 2016 RIFT.IO Inc
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 */
18 /*
19 * Webpack distribution configuration
20 *
21 * This file is set up for serving the distribution version. It will be compiled to dist/ by default
22 */
23
24 'use strict';
25
26 var webpack = require('webpack');
27 var path = require('path');
28 var uiPluginCmakeBuild = process.env.ui_plugin_cmake_build || false;
29 var frameworkPath = uiPluginCmakeBuild?'../../../../skyquake/skyquake-build/framework':'../../framework';
30 var HtmlWebpackPlugin = require('html-webpack-plugin');
31 var CompressionPlugin = require("compression-webpack-plugin");
32 // Added to overcome node-sass bug https://github.com/iam4x/isomorphic-flux-boilerplate/issues/62
33 process.env.UV_THREADPOOL_SIZE=64;
34 var config = {
35 devtool: 'source-map',
36 output: {
37 publicPath: 'assets/',
38 path: 'public/assets/',
39 filename: 'bundle.js'
40 },
41
42 debug: false,
43 entry: [path.resolve(__dirname) + '/src/index.js'],
44
45 stats: {
46 colors: true,
47 reasons: false
48 },
49 resolve: {
50 extensions: ['', '.js', '.jsx', '.css', '.scss'],
51 root: path.resolve(frameworkPath),
52 alias: {
53 'widgets': path.resolve(frameworkPath) + '/widgets',
54 'style': path.resolve(frameworkPath) + '/style',
55 'utils': path.resolve(frameworkPath) + '/utils',
56 'styles': path.join(process.cwd(), './src/styles/'),
57 'libraries': path.join(process.cwd(), './src/libraries/'),
58 'components': path.join(process.cwd(), './src/components/'),
59 //'stores': '../../../src/stores/',
60 //'actions': '../../../src/actions/',
61 'helpers': path.join(process.cwd(), './test/helpers/')
62 }
63 },
64 module: {
65 noParse: [/autoit.js/],
66 // preLoaders: [
67 // {
68 // test: /\.(js|jsx)$/,
69 // exclude: /node_modules/,
70 // loader: 'eslint-loader'
71 // }
72 // ],
73 loaders: [
74 {
75 test: /\.(js|jsx)$/,
76 exclude: /node_modules/,
77 loader: 'babel-loader',
78 query: {
79 presets: ['es2015', 'stage-0', 'react']
80 }
81 }, {
82 test: /\.css$/,
83 loader: 'style-loader!css-loader'
84 }, {
85 test: /\.scss/,
86 loader: 'style-loader!css-loader!sass-loader?outputStyle=expanded&includePaths[]='+ path.resolve(frameworkPath)
87 },{
88 test: /\.(jpe?g|png|gif|svg|ttf|otf|eot|svg|woff(2)?)(\?[a-z0-9]+)?$/i,
89 loader: "file-loader"
90 },
91 { test: /\.json$/, loader: "json-loader" },
92 ]
93 },
94 plugins: [
95 new HtmlWebpackPlugin({
96 filename: '../index.html',
97 templateContent: '<div id="app"></div>'
98 })
99 ]
100 };
101
102 if (process.argv.indexOf('--optimize-minimize') !== -1) {
103 // we are going to output a gzip file in the production process
104 config.output.filename = "gzip-" + config.output.filename;
105 config.plugins.push(new webpack.DefinePlugin({ // <-- key to reducing React's size
106 'process.env': {
107 'NODE_ENV': JSON.stringify('production')
108 }
109 }));
110 config.plugins.push(new CompressionPlugin({
111 asset: "[path]", // overwrite js file with gz file
112 algorithm: "gzip",
113 test: /\.(js)$/
114 }));
115 }
116
117 module.exports = config;