X-Git-Url: https://git.immae.eu/?p=github%2Fshaarli%2FShaarli.git;a=blobdiff_plain;f=webpack.config.js;h=ed548c735ad08444ba7adf204e93a2c14012e4ab;hp=602147e51d3d200b8dcf45bbb6df7f951e08c6c3;hb=HEAD;hpb=cf92b4dd1521241eefc58eaf6dcd202cd83969d8 diff --git a/webpack.config.js b/webpack.config.js index 602147e5..2c316d32 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -2,29 +2,26 @@ const path = require('path'); const glob = require('glob'); // Minify JS -const MinifyPlugin = require('babel-minify-webpack-plugin'); +const TerserPlugin = require('terser-webpack-plugin'); // This plugin extracts the CSS into its own file instead of tying it with the JS. // It prevents: // - not having styles due to a JS error // - the flash page without styles during JS loading -const ExtractTextPlugin = require("extract-text-webpack-plugin"); +const MiniCssExtractPlugin = require("mini-css-extract-plugin"); -const extractCssDefault = new ExtractTextPlugin({ +const extractCss = new MiniCssExtractPlugin({ filename: "../css/[name].min.css", - publicPath: 'tpl/default/css/', -}); - -const extractCssVintage = new ExtractTextPlugin({ - filename: "../css/[name].min.css", - publicPath: 'tpl/vintage/css/', }); module.exports = [ { + mode: 'production', entry: { + shaare_batch: './assets/common/js/shaare-batch.js', thumbnails: './assets/common/js/thumbnails.js', thumbnails_update: './assets/common/js/thumbnails-update.js', + metadata: './assets/common/js/metadata.js', pluginsadmin: './assets/default/js/plugins-admin.js', shaarli: [ './assets/default/js/base.js', @@ -45,23 +42,23 @@ module.exports = [ loader: 'babel-loader', options: { presets: [ - 'babel-preset-env', + '@babel/preset-env', ] } } }, { test: /\.s?css/, - use: extractCssDefault.extract({ - use: [{ - loader: "css-loader", + use: [ + { + loader: MiniCssExtractPlugin.loader, options: { - minimize: true, - } - }, { - loader: "sass-loader" - }], - }) + publicPath: 'tpl/default/css/', + }, + }, + 'css-loader', + 'sass-loader', + ], }, { test: /\.(gif|png|jpe?g|svg|ico)$/i, @@ -81,17 +78,21 @@ module.exports = [ options: { name: '../fonts/[name].[ext]', // do not add a publicPath here because it's already handled by CSS's publicPath - publicPath: '', + publicPath: '../default/', } }, ], }, + optimization: { + minimize: true, + minimizer: [new TerserPlugin()], + }, plugins: [ - new MinifyPlugin(), - extractCssDefault, + extractCss, ], }, { + mode: 'production', entry: { shaarli: [ './assets/vintage/js/base.js', @@ -100,6 +101,7 @@ module.exports = [ ].concat(glob.sync('./assets/vintage/img/*')), markdown: './assets/common/css/markdown.css', thumbnails: './assets/common/js/thumbnails.js', + metadata: './assets/common/js/metadata.js', thumbnails_update: './assets/common/js/thumbnails-update.js', }, output: { @@ -115,21 +117,23 @@ module.exports = [ loader: 'babel-loader', options: { presets: [ - 'babel-preset-env', + '@babel/preset-env', ] } } }, { test: /\.css$/, - use: extractCssVintage.extract({ - use: [{ - loader: "css-loader", + use: [ + { + loader: MiniCssExtractPlugin.loader, options: { - minimize: true, - } - }], - }) + publicPath: 'tpl/vintage/css/', + }, + }, + 'css-loader', + 'sass-loader', + ], }, { test: /\.(gif|png|jpe?g|svg|ico)$/i, @@ -138,16 +142,20 @@ module.exports = [ loader: 'file-loader', options: { name: '../img/[name].[ext]', - publicPath: '', + // do not add a publicPath here because it's already handled by CSS's publicPath + publicPath: '../vintage', } } ], }, ], }, + optimization: { + minimize: true, + minimizer: [new TerserPlugin()], + }, plugins: [ - new MinifyPlugin(), - extractCssVintage, + extractCss, ], }, ];