mirror of
https://github.com/grafana/grafana.git
synced 2024-12-27 09:21:35 -06:00
78bef7a26a
* build(webpack): move CopyUniconsPlugin into own file * chore(webpack): delete unused blobUrl and compile loaders * build(webpack): prefer contenthash over fullhash for longer caching * build(webpack): set optimization.moduleIds named only in dev * build(webpack): introduce HTMLWebpackCSSChunks so templates can access theme css by name * feat: inject css files with contenthash in html templates * revert(error-template): remove ContentDeliveryURL from CSS href * refactor(index-template): update grafanaBootData.themePaths * chore(webpack): add typescript annotations for CopyUniconsPlugin
94 lines
2.6 KiB
JavaScript
94 lines
2.6 KiB
JavaScript
'use strict';
|
|
|
|
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
|
|
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
|
const path = require('path');
|
|
const TerserPlugin = require('terser-webpack-plugin');
|
|
const { merge } = require('webpack-merge');
|
|
|
|
const HTMLWebpackCSSChunks = require('./plugins/HTMLWebpackCSSChunks');
|
|
const common = require('./webpack.common.js');
|
|
|
|
module.exports = (env = {}) =>
|
|
merge(common, {
|
|
mode: 'production',
|
|
devtool: 'source-map',
|
|
|
|
entry: {
|
|
dark: './public/sass/grafana.dark.scss',
|
|
light: './public/sass/grafana.light.scss',
|
|
},
|
|
|
|
module: {
|
|
// Note: order is bottom-to-top and/or right-to-left
|
|
rules: [
|
|
{
|
|
test: /\.tsx?$/,
|
|
exclude: /node_modules/,
|
|
use: [
|
|
{
|
|
loader: 'babel-loader',
|
|
options: {
|
|
cacheDirectory: true,
|
|
cacheCompression: false,
|
|
},
|
|
},
|
|
],
|
|
},
|
|
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],
|
|
},
|
|
},
|
|
|
|
plugins: [
|
|
new MiniCssExtractPlugin({
|
|
filename: 'grafana.[name].[contenthash].css',
|
|
}),
|
|
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',
|
|
}),
|
|
new HTMLWebpackCSSChunks(),
|
|
function () {
|
|
this.hooks.done.tap('Done', function (stats) {
|
|
if (stats.compilation.errors && stats.compilation.errors.length) {
|
|
console.log(stats.compilation.errors);
|
|
process.exit(1);
|
|
}
|
|
});
|
|
},
|
|
],
|
|
});
|