blob: 2ef01beea4edbcd6d77ae04af8b25f4c8357af19 [file] [log] [blame]
Jeremy Mordkoffe29efc32016-09-07 18:59:17 -04001/*
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 */
Bob Gallagherefcca982017-03-15 08:24:47 -040018var webpack = require('webpack');
Jeremy Mordkoffe29efc32016-09-07 18:59:17 -040019var path = require('path');
20var nodeModulesPath = path.resolve(__dirname, 'node_modules');
21var buildPath = path.resolve(__dirname, 'public', 'build');
22var mainPath = path.resolve(__dirname, 'src', 'main.js');
23var uiPluginCmakeBuild = process.env.ui_plugin_cmake_build || false;
24var frameworkPath = uiPluginCmakeBuild?'../../../../skyquake/skyquake-build/framework':'../../framework';
25var HtmlWebpackPlugin = require('html-webpack-plugin');
Bob Gallagherefcca982017-03-15 08:24:47 -040026var CompressionPlugin = require("compression-webpack-plugin");
Jeremy Mordkoffe29efc32016-09-07 18:59:17 -040027// Added to overcome node-sass bug https://github.com/iam4x/isomorphic-flux-boilerplate/issues/62
28process.env.UV_THREADPOOL_SIZE=64;
29var config = {
30 devtool: 'source-map',
31 entry: mainPath,
32 output: {
33 path: buildPath,
34 filename: 'bundle.js',
35 publicPath: "build/"
36 },
37 resolve: {
38 extensions: ['', '.js', '.jsx', '.css', '.scss'],
39 root: path.resolve(frameworkPath),
40 alias: {
41 'widgets': path.resolve(frameworkPath) + '/widgets',
42 'style': path.resolve(frameworkPath) + '/style',
43 'utils': path.resolve(frameworkPath) + '/utils'
44 }
45 },
46 module: {
47 loaders: [{
48 test: /\.(jpe?g|png|gif|svg|ttf|otf|eot|svg|woff(2)?)(\?[a-z0-9]+)?$/i,
49 loader: "file-loader"
50 },
51 {
52 test: /\.(js|jsx)$/,
53 exclude: /node_modules/,
54 loader: 'babel-loader',
55 query: {
56 presets: ["es2015", "stage-0", "react"]
57 }
58 }, {
59 test: /\.css$/,
60 loader: 'style!css'
61 }, {
62 test: /\.scss/,
63 loader: 'style!css!sass'
64 }
65 ]
66 },
67 plugins: [
68 new HtmlWebpackPlugin({
Bob Gallagherefcca982017-03-15 08:24:47 -040069 filename: '../index.html',
70 templateContent: '<div id="app"></div>'
71 })
Jeremy Mordkoffe29efc32016-09-07 18:59:17 -040072 ]
73};
Bob Gallagherefcca982017-03-15 08:24:47 -040074
75if (process.argv.indexOf('--optimize-minimize') !== -1) {
76 // we are going to output a gzip file in the production process
77 config.output.filename = "gzip-" + config.output.filename;
78 config.plugins.push(new webpack.DefinePlugin({ // <-- key to reducing React's size
79 'process.env': {
80 'NODE_ENV': JSON.stringify('production')
81 }
82 }));
83 config.plugins.push(new CompressionPlugin({
84 asset: "[path]", // overwrite js file with gz file
85 algorithm: "gzip",
86 test: /\.(js)$/
87 }));
88}
Jeremy Mordkoffe29efc32016-09-07 18:59:17 -040089module.exports = config;