update from RIFT as of 696b75d2fe9fb046261b08c616f1bcf6c0b54a9b third try
[osm/UI.git] / skyquake / plugins / about / 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 var webpack = require('webpack');
19 var path = require('path');
20 var nodeModulesPath = path.resolve(__dirname, 'node_modules');
21 var buildPath = path.resolve(__dirname, 'public', 'build');
22 var mainPath = path.resolve(__dirname, 'src', 'main.js');
23 var uiPluginCmakeBuild = process.env.ui_plugin_cmake_build || false;
24 var frameworkPath = uiPluginCmakeBuild?'../../../../skyquake/skyquake-build/framework':'../../framework';
25 var HtmlWebpackPlugin = require('html-webpack-plugin');
26 var CompressionPlugin = require("compression-webpack-plugin");
27
28 // Added to overcome node-sass bug https://github.com/iam4x/isomorphic-flux-boilerplate/issues/62
29 process.env.UV_THREADPOOL_SIZE=64;
30 var htmlFilename = (process.argv.indexOf('--production-debug') !== -1) ? 'debug.html' : 'index.html';
31 var config = {
32 devtool: 'source-map',
33 entry: mainPath,
34 output: {
35 path: buildPath,
36 filename: 'bundle.js',
37 publicPath: "build/"
38 },
39 resolve: {
40 extensions: ['', '.js', '.jsx', '.css', '.scss'],
41 root: path.resolve(frameworkPath),
42 alias: {
43 'widgets': path.resolve(frameworkPath) + '/widgets',
44 'style': path.resolve(frameworkPath) + '/style',
45 'utils': path.resolve(frameworkPath) + '/utils'
46 }
47 },
48 module: {
49 loaders: [{
50 test: /\.(jpe?g|png|gif|svg|ttf|otf|eot|svg|woff(2)?)(\?[a-z0-9]+)?$/i,
51 loader: "file-loader"
52 },
53 {
54 test: /\.(js|jsx)$/,
55 exclude: /node_modules/,
56 loader: 'babel-loader',
57 query: {
58 presets: ["es2015", "stage-0", "react"]
59 }
60 }, {
61 test: /\.css$/,
62 loader: 'style!css'
63 }, {
64 test: /\.scss/,
65 loader: 'style!css!sass'
66 }
67 ]
68 },
69 plugins: [
70 new HtmlWebpackPlugin({
71 filename: '../' + htmlFilename,
72 template: frameworkPath + '/plugin-index.html'
73 })
74 ]
75 };
76
77 if (process.argv.indexOf('--optimize-minimize') !== -1) {
78 // we are going to output a gzip file in the production process
79 config.output.filename = "gzip-" + config.output.filename;
80 config.plugins.push(new webpack.DefinePlugin({ // <-- key to reducing React's size
81 'process.env': {
82 'NODE_ENV': JSON.stringify('production')
83 }
84 }));
85 config.plugins.push(new CompressionPlugin({
86 asset: "[path]", // overwrite js file with gz file
87 algorithm: "gzip",
88 test: /\.(js)$/
89 }));
90 }
91 module.exports = config;