influxdb/ui/webpack/prod.config.js

184 lines
4.7 KiB
JavaScript
Raw Normal View History

/* eslint-disable no-var */
2018-02-20 14:28:51 +00:00
const webpack = require('webpack')
const path = require('path')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
2018-02-25 15:30:06 +00:00
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin')
2018-02-26 01:29:39 +00:00
2018-04-17 18:07:00 +00:00
const pkg = require('../package.json')
const dependencies = pkg.dependencies
2018-02-20 14:28:51 +00:00
const babelLoader = {
loader: 'babel-loader',
options: {
cacheDirectory: false,
presets: [['env', {modules: false}], 'react', 'stage-0'],
2018-04-17 18:07:00 +00:00
plugins: ['transform-decorators-legacy'],
2018-02-20 14:28:51 +00:00
},
}
const config = {
2018-02-20 15:23:53 +00:00
node: {
2018-02-25 15:30:06 +00:00
fs: 'empty',
module: 'empty',
},
bail: true,
2018-02-25 19:06:24 +00:00
devtool: false,
entry: {
2018-03-29 17:14:24 +00:00
app: path.resolve(__dirname, '..', 'src', 'index.tsx'),
2016-09-30 20:16:24 +00:00
vendor: Object.keys(dependencies),
},
output: {
publicPath: '/',
path: path.resolve(__dirname, '../build'),
2016-09-30 21:23:15 +00:00
filename: '[name].[chunkhash].js',
},
resolve: {
alias: {
app: path.resolve(__dirname, '..', 'app'),
src: path.resolve(__dirname, '..', 'src'),
shared: path.resolve(__dirname, '..', 'src', 'shared'),
style: path.resolve(__dirname, '..', 'src', 'style'),
utils: path.resolve(__dirname, '..', 'src', 'utils'),
},
2018-02-20 14:28:51 +00:00
extensions: ['.ts', '.tsx', '.js'],
},
module: {
noParse: [
path.resolve(
__dirname,
'..',
'node_modules',
'memoizerific',
'memoizerific.js'
),
],
2018-02-25 15:30:06 +00:00
loaders: [
2018-03-21 22:31:40 +00:00
{
test: /\.ts(x?)$/,
exclude: /node_modules/,
loader: 'tslint-loader',
enforce: 'pre',
options: {
2018-03-22 20:43:47 +00:00
emitErrors: true,
configFile: path.resolve(__dirname, '..', 'tslint.json'),
2018-03-21 22:31:40 +00:00
},
},
2018-02-25 15:30:06 +00:00
{
test: /\.js$/,
exclude: [/node_modules/, /(_s|S)pec\.js$/],
use: 'eslint-loader',
enforce: 'pre',
},
{
test: /\.scss$/,
loader: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
'css-loader',
'sass-loader',
'resolve-url-loader',
'sass-loader?sourceMap',
],
}),
},
{
test: /\.css$/,
loader: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: ['css-loader', 'postcss-loader'],
}),
},
{
2017-10-27 16:11:03 +00:00
test: /\.(ico|png|cur|jpg|ttf|eot|svg|woff(2)?)(\?[a-z0-9]+)?$/,
loader: 'file-loader',
},
{
test: /\.js$/,
exclude: /node_modules/,
use: [{loader: 'thread-loader'}, babelLoader],
},
2018-02-20 14:28:51 +00:00
{
test: /\.ts(x?)$/,
exclude: /node_modules/,
use: [
{
loader: 'thread-loader',
options: {
// there should be 1 cpu for the fork-ts-checker-webpack-plugin
workers: require('os').cpus().length - 1,
},
},
2018-02-20 14:28:51 +00:00
babelLoader,
{
loader: 'ts-loader',
options: {
happyPackMode: true, // required for use with thread-loader
},
2018-02-20 14:28:51 +00:00
},
],
},
],
},
plugins: [
2018-02-25 19:06:24 +00:00
new webpack.DefinePlugin({
VERSION: JSON.stringify(require('../package.json').version),
'process.env.NODE_ENV': JSON.stringify('production'),
}),
new webpack.optimize.ModuleConcatenationPlugin(),
new ForkTsCheckerWebpackPlugin({
checkSyntacticErrors: true,
}),
new webpack.LoaderOptionsPlugin({
postcss: require('./postcss'),
options: {
eslint: {
failOnWarning: false,
failOnError: false,
},
},
}),
2016-09-30 20:16:24 +00:00
new webpack.ProvidePlugin({
2017-10-27 16:11:03 +00:00
$: 'jquery',
jQuery: 'jquery',
2016-09-30 20:16:24 +00:00
}),
2017-10-27 16:11:03 +00:00
new ExtractTextPlugin('chronograf.css'),
2018-02-25 19:16:18 +00:00
new UglifyJsPlugin({
parallel: true,
uglifyOptions: {
ie8: false,
},
}),
2018-02-25 15:30:06 +00:00
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
minChunks(module) {
return module.context && module.context.indexOf('node_modules') >= 0
},
}),
2016-09-30 20:16:24 +00:00
new webpack.optimize.CommonsChunkPlugin({
2018-02-25 15:30:06 +00:00
name: 'manifest',
2016-09-30 20:16:24 +00:00
}),
2018-02-26 01:29:39 +00:00
new HtmlWebpackPlugin({
template: path.resolve(__dirname, '..', 'src', 'index.template.html'),
inject: 'body',
chunksSortMode: 'dependency',
favicon: 'assets/images/favicon.ico',
}),
2018-02-25 15:30:06 +00:00
function() {
2017-10-27 16:11:03 +00:00
/* Webpack does not exit with non-zero status if error. */
2018-02-25 15:30:06 +00:00
this.plugin('done', function(stats) {
2018-03-28 17:43:13 +00:00
const {compilation: {errors}} = stats
if (errors && errors.length) {
2018-04-17 18:07:00 +00:00
errors.forEach(err => console.error(err))
2017-10-27 16:11:03 +00:00
process.exit(1)
}
2017-10-27 16:11:03 +00:00
})
},
],
target: 'web',
2017-10-27 16:11:03 +00:00
}
2018-02-25 15:30:06 +00:00
module.exports = config