2017-10-01 13:02:25 -05:00
|
|
|
'use strict';
|
|
|
|
|
2023-01-23 05:15:05 -06:00
|
|
|
const browserslist = require('browserslist');
|
2022-04-22 08:33:13 -05:00
|
|
|
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
|
2023-06-01 03:23:09 -05:00
|
|
|
const { EsbuildPlugin } = require('esbuild-loader');
|
2023-01-23 05:15:05 -06:00
|
|
|
const { resolveToEsbuildTarget } = require('esbuild-plugin-browserslist');
|
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');
|
2022-08-30 04:18:55 -05:00
|
|
|
const { WebpackManifestPlugin } = require('webpack-manifest-plugin');
|
2022-04-22 08:33:13 -05:00
|
|
|
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');
|
2023-01-23 05:15:05 -06:00
|
|
|
const esbuildTargets = resolveToEsbuildTarget(browserslist(), { printUnknownTargets: false });
|
2017-10-01 13:02:25 -05:00
|
|
|
|
2023-06-01 03:23:09 -05:00
|
|
|
// esbuild-loader 3.0.0+ requires format to be set to prevent it
|
|
|
|
// from defaulting to 'iife' which breaks monaco/loader once minified.
|
|
|
|
const esbuildOptions = {
|
|
|
|
target: esbuildTargets,
|
|
|
|
format: undefined,
|
|
|
|
};
|
|
|
|
|
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/,
|
2023-01-23 05:15:05 -06:00
|
|
|
use: {
|
|
|
|
loader: 'esbuild-loader',
|
2023-06-01 03:23:09 -05:00
|
|
|
options: esbuildOptions,
|
2023-01-23 05:15:05 -06:00
|
|
|
},
|
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,
|
2023-06-01 03:23:09 -05:00
|
|
|
minimizer: [new EsbuildPlugin(esbuildOptions), new CssMinimizerPlugin()],
|
2021-11-11 07:32:34 -06:00
|
|
|
},
|
|
|
|
|
|
|
|
// 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(),
|
2022-08-30 04:18:55 -05:00
|
|
|
new WebpackManifestPlugin({
|
|
|
|
fileName: path.join(process.cwd(), 'manifest.json'),
|
|
|
|
filter: (file) => !file.name.endsWith('.map'),
|
|
|
|
}),
|
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
|
|
|
});
|