|
| 1 | +/* |
| 2 | + * Copyright (C) 2017-2017 SonarSource SA |
| 3 | + * All rights reserved |
| 4 | + * mailto:info AT sonarsource DOT com |
| 5 | + */ |
| 6 | +const webpack = require('webpack'); |
| 7 | +const config = require('./webpack.config'); |
| 8 | +const getClientEnvironment = require('../env'); |
| 9 | + |
| 10 | +// Get environment variables to inject into our app. |
| 11 | +const env = getClientEnvironment(); |
| 12 | + |
| 13 | +// Assert this just to be safe. |
| 14 | +// Development builds of React are slow and not intended for production. |
| 15 | +if (env['process.env.NODE_ENV'] !== '"production"') { |
| 16 | + throw new Error('Production builds must have NODE_ENV=production.'); |
| 17 | +} |
| 18 | + |
| 19 | +const noUglify = process.argv.some(arg => arg.indexOf('--no-uglify') > -1); |
| 20 | + |
| 21 | +// Don't attempt to continue if there are any errors. |
| 22 | +config.bail = true; |
| 23 | + |
| 24 | +config.plugins = [ |
| 25 | + // Makes some environment variables available to the JS code, for example: |
| 26 | + // if (process.env.NODE_ENV === 'production') { ... }. See `./env.js`. |
| 27 | + // It is absolutely essential that NODE_ENV was set to production here. |
| 28 | + // Otherwise React will be compiled in the very slow development mode. |
| 29 | + new webpack.DefinePlugin(env), |
| 30 | + |
| 31 | + // This helps ensure the builds are consistent if source hasn't changed: |
| 32 | + new webpack.optimize.OccurrenceOrderPlugin(), |
| 33 | + |
| 34 | + // Try to dedupe duplicated modules, if any: |
| 35 | + new webpack.optimize.DedupePlugin() |
| 36 | +]; |
| 37 | + |
| 38 | +if (!noUglify) { |
| 39 | + config.plugins.push( |
| 40 | + new webpack.optimize.UglifyJsPlugin({ |
| 41 | + compress: { |
| 42 | + screw_ie8: true, // React doesn't support IE8 |
| 43 | + warnings: false |
| 44 | + }, |
| 45 | + mangle: { |
| 46 | + screw_ie8: true |
| 47 | + }, |
| 48 | + output: { |
| 49 | + comments: false, |
| 50 | + screw_ie8: true |
| 51 | + } |
| 52 | + }) |
| 53 | + ); |
| 54 | +} |
| 55 | + |
| 56 | +module.exports = config; |
0 commit comments