2017-10-01 13:02:25 -05:00
|
|
|
'use strict';
|
|
|
|
|
2022-04-22 08:33:13 -05:00
|
|
|
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
|
2020-01-30 03:54:11 -06:00
|
|
|
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
|
|
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
2022-04-22 08:33:13 -05:00
|
|
|
const path = require('path');
|
|
|
|
const TerserPlugin = require('terser-webpack-plugin');
|
|
|
|
const { merge } = require('webpack-merge');
|
|
|
|
|
2022-05-26 04:49:18 -05:00
|
|
|
const HTMLWebpackCSSChunks = require('./plugins/HTMLWebpackCSSChunks');
|
2022-04-22 08:33:13 -05:00
|
|
|
const common = require('./webpack.common.js');
|
2017-10-01 13:02:25 -05:00
|
|
|
|
2021-11-11 07:32:34 -06:00
|
|
|
module.exports = (env = {}) =>
|
|
|
|
merge(common, {
|
|
|
|
mode: 'production',
|
|
|
|
devtool: 'source-map',
|
2017-10-01 13:02:25 -05:00
|
|
|
|
2021-11-11 07:32:34 -06:00
|
|
|
entry: {
|
|
|
|
dark: './public/sass/grafana.dark.scss',
|
|
|
|
light: './public/sass/grafana.light.scss',
|
|
|
|
},
|
2017-10-01 13:02:25 -05:00
|
|
|
|
2021-11-11 07:32:34 -06:00
|
|
|
module: {
|
|
|
|
// Note: order is bottom-to-top and/or right-to-left
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.tsx?$/,
|
|
|
|
exclude: /node_modules/,
|
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: 'babel-loader',
|
2021-11-18 10:38:58 -06:00
|
|
|
options: {
|
|
|
|
cacheDirectory: true,
|
|
|
|
cacheCompression: false,
|
|
|
|
},
|
2021-11-11 07:32:34 -06:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
require('./sass.rule.js')({
|
|
|
|
sourceMap: false,
|
|
|
|
preserveUrl: false,
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
},
|
|
|
|
optimization: {
|
|
|
|
nodeEnv: 'production',
|
|
|
|
minimize: parseInt(env.noMinify, 10) !== 1,
|
|
|
|
minimizer: [
|
|
|
|
new TerserPlugin({
|
|
|
|
parallel: false,
|
|
|
|
}),
|
|
|
|
new CssMinimizerPlugin(),
|
|
|
|
],
|
|
|
|
},
|
|
|
|
|
|
|
|
// enable persistent cache for faster builds
|
|
|
|
cache: {
|
|
|
|
type: 'filesystem',
|
|
|
|
name: 'grafana-default-production',
|
|
|
|
buildDependencies: {
|
|
|
|
config: [__filename],
|
2018-04-18 08:01:36 -05:00
|
|
|
},
|
2021-11-11 07:32:34 -06:00
|
|
|
},
|
|
|
|
|
|
|
|
plugins: [
|
|
|
|
new MiniCssExtractPlugin({
|
2022-05-26 04:49:18 -05:00
|
|
|
filename: 'grafana.[name].[contenthash].css',
|
2020-01-30 03:54:11 -06:00
|
|
|
}),
|
2021-11-11 07:32:34 -06:00
|
|
|
new HtmlWebpackPlugin({
|
|
|
|
filename: path.resolve(__dirname, '../../public/views/error.html'),
|
|
|
|
template: path.resolve(__dirname, '../../public/views/error-template.html'),
|
|
|
|
inject: false,
|
|
|
|
excludeChunks: ['dark', 'light'],
|
|
|
|
chunksSortMode: 'none',
|
|
|
|
}),
|
|
|
|
new HtmlWebpackPlugin({
|
|
|
|
filename: path.resolve(__dirname, '../../public/views/index.html'),
|
|
|
|
template: path.resolve(__dirname, '../../public/views/index-template.html'),
|
|
|
|
inject: false,
|
|
|
|
excludeChunks: ['manifest', 'dark', 'light'],
|
|
|
|
chunksSortMode: 'none',
|
2018-06-26 03:28:37 -05:00
|
|
|
}),
|
2022-05-26 04:49:18 -05:00
|
|
|
new HTMLWebpackCSSChunks(),
|
2021-11-11 07:32:34 -06:00
|
|
|
function () {
|
|
|
|
this.hooks.done.tap('Done', function (stats) {
|
|
|
|
if (stats.compilation.errors && stats.compilation.errors.length) {
|
|
|
|
console.log(stats.compilation.errors);
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2020-01-30 03:54:11 -06:00
|
|
|
],
|
2021-11-11 07:32:34 -06:00
|
|
|
});
|