Add options to minify Webpack output and rearrange webpack.config.js
This commit is contained in:
@ -3,6 +3,11 @@
|
|||||||
const { webpackConfig, merge } = require('shakapacker')
|
const { webpackConfig, merge } = require('shakapacker')
|
||||||
const webpack = require('webpack');
|
const webpack = require('webpack');
|
||||||
|
|
||||||
|
const CompressionPlugin = require("compression-webpack-plugin");
|
||||||
|
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
|
||||||
|
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
|
||||||
|
const TerserPlugin = require("terser-webpack-plugin");
|
||||||
|
|
||||||
// Custom ERB loader to disable Spring and prevent crashes
|
// Custom ERB loader to disable Spring and prevent crashes
|
||||||
const erb = require("./loaders/erb");
|
const erb = require("./loaders/erb");
|
||||||
|
|
||||||
@ -12,21 +17,24 @@ const relative_url_root = process.env.RAILS_RELATIVE_URL_ROOT || '';
|
|||||||
const public_output_path = webpackConfig.output.publicPath;
|
const public_output_path = webpackConfig.output.publicPath;
|
||||||
|
|
||||||
const envConfig = module.exports = {
|
const envConfig = module.exports = {
|
||||||
output: {
|
|
||||||
publicPath: relative_url_root + public_output_path
|
|
||||||
},
|
|
||||||
module: {
|
module: {
|
||||||
rules: [
|
rules: [
|
||||||
erb
|
erb
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
resolve: {
|
optimization: {
|
||||||
extensions: ['.css', '.ts', '.tsx'],
|
minimize: true,
|
||||||
alias: {
|
minimizer: [
|
||||||
$: 'jquery/src/jquery',
|
new TerserPlugin(),
|
||||||
jquery: 'jquery/src/jquery',
|
new CssMinimizerPlugin()
|
||||||
vis$: 'vis-timeline/standalone',
|
],
|
||||||
}
|
},
|
||||||
|
output: {
|
||||||
|
publicPath: relative_url_root + public_output_path
|
||||||
|
},
|
||||||
|
performance: {
|
||||||
|
// Turn off size warnings for large assets
|
||||||
|
hints: false
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
new webpack.ProvidePlugin({
|
new webpack.ProvidePlugin({
|
||||||
@ -41,13 +49,19 @@ const envConfig = module.exports = {
|
|||||||
d3: 'd3',
|
d3: 'd3',
|
||||||
Sentry: '@sentry/browser',
|
Sentry: '@sentry/browser',
|
||||||
Sortable: 'sortablejs',
|
Sortable: 'sortablejs',
|
||||||
})
|
}),
|
||||||
|
new CompressionPlugin(),
|
||||||
|
new MiniCssExtractPlugin(),
|
||||||
],
|
],
|
||||||
performance: {
|
resolve: {
|
||||||
// Turn off size warnings for large assets
|
extensions: ['.css', '.ts', '.tsx'],
|
||||||
hints: false
|
alias: {
|
||||||
|
$: 'jquery/src/jquery',
|
||||||
|
jquery: 'jquery/src/jquery',
|
||||||
|
vis$: 'vis-timeline/standalone',
|
||||||
|
}
|
||||||
},
|
},
|
||||||
stats: 'minimal'
|
stats: 'minimal',
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = merge(webpackConfig, envConfig)
|
module.exports = merge(webpackConfig, envConfig)
|
||||||
|
Reference in New Issue
Block a user