2022-09-07 11:37:27 +00:00
|
|
|
require("dotenv").config();
|
|
|
|
const path = require("path");
|
|
|
|
const webpack = require("webpack"); //e.g. for iusing DefinePlugin
|
2020-11-12 12:44:48 +00:00
|
|
|
// const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
|
2022-09-07 11:37:27 +00:00
|
|
|
const TerserPlugin = require("terser-webpack-plugin");
|
2020-11-12 12:44:48 +00:00
|
|
|
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
|
2022-09-07 11:37:27 +00:00
|
|
|
const { WebpackManifestPlugin } = require('webpack-manifest-plugin');
|
2021-03-17 08:22:12 +00:00
|
|
|
// const { VueLoaderPlugin } = require('vue-loader');
|
2020-11-12 12:44:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* flag Used to check if the environment is production or not
|
|
|
|
*/
|
2022-09-07 11:37:27 +00:00
|
|
|
// const isProduction = (process.env.NODE_ENV === 'production');
|
|
|
|
// const devMode = (process.env.NODE_ENV !== 'production');
|
2020-11-12 12:44:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Include hash to filenames for cache busting - only at production
|
|
|
|
*/
|
2022-09-07 11:37:27 +00:00
|
|
|
// const fileNamePrefix = isProduction ? "[chunkhash]." : "";
|
2020-11-12 12:44:48 +00:00
|
|
|
|
2022-09-07 11:37:27 +00:00
|
|
|
let isProduction, devMode;
|
|
|
|
|
|
|
|
module.exports = (env, argv) => {
|
|
|
|
isProduction = argv.mode === "production";
|
|
|
|
devMode = argv.mode !== "production";
|
|
|
|
// const fileNamePrefix = isProduction ? "[chunkhash]." : "";
|
|
|
|
|
|
|
|
console.log(`This is the Webpack 5 'mode': ${argv.mode}`);
|
|
|
|
return {
|
|
|
|
// mode: process.env.NODE_ENV,
|
2020-11-12 12:44:48 +00:00
|
|
|
context: __dirname,
|
2022-09-07 11:37:27 +00:00
|
|
|
entry: "./src/js/main.js",
|
2020-11-12 12:44:48 +00:00
|
|
|
output: {
|
2022-09-07 11:37:27 +00:00
|
|
|
path: path.resolve(__dirname, "dist"),
|
|
|
|
filename: "[name].js",
|
|
|
|
// filename: fileNamePrefix + '[name].js',
|
|
|
|
publicPath: "/dist/",
|
2020-11-12 12:44:48 +00:00
|
|
|
},
|
2021-03-17 08:22:12 +00:00
|
|
|
// resolve: {
|
|
|
|
// alias: {
|
|
|
|
// 'vue$': 'vue/dist/vue.esm.js'
|
|
|
|
// },
|
|
|
|
// extensions: ['*', '.js', '.vue', '.json']
|
|
|
|
// },
|
2020-11-12 12:44:48 +00:00
|
|
|
module: {
|
2022-09-07 11:37:27 +00:00
|
|
|
rules: [
|
|
|
|
// {
|
|
|
|
// test: /\.(svg|eot|ttf|woff|woff2)$/,
|
|
|
|
// loader: 'url-loader',
|
|
|
|
// // include: path.resolve(__dirname, '~@fontsource/open-sans/files/'),
|
|
|
|
// options: {
|
|
|
|
// limit: 10000,
|
|
|
|
// name: '[name].[ext]',
|
|
|
|
// outputPath: 'assets/fonts/',
|
|
|
|
// }
|
|
|
|
// },
|
2021-08-24 13:12:47 +00:00
|
|
|
|
2022-09-07 11:37:27 +00:00
|
|
|
// {
|
|
|
|
// test: /\.(png|jpg|gif)$/,
|
|
|
|
// loaders: [
|
|
|
|
// {
|
|
|
|
// loader: 'url-loader',
|
|
|
|
// options: {
|
|
|
|
// limit: 10000,
|
|
|
|
// name: 'images/[name].[ext]'
|
|
|
|
// }
|
|
|
|
// },
|
|
|
|
// 'img-loader'
|
|
|
|
// ],
|
|
|
|
// },
|
|
|
|
// {
|
|
|
|
// test: /\.vue$/,
|
|
|
|
// loader: 'vue-loader'
|
|
|
|
// },
|
|
|
|
// {
|
|
|
|
// test: /\.tsx?$/,
|
|
|
|
// use: 'ts-loader',
|
|
|
|
// exclude: /(node_modules|bower_components)/,
|
|
|
|
// },
|
|
|
|
{
|
|
|
|
// test: /\.js$/,
|
|
|
|
test: /\.(js|jsx|tsx|ts)$/,
|
|
|
|
exclude: /(node_modules|bower_components)/,
|
|
|
|
use: {
|
|
|
|
loader: "babel-loader",
|
|
|
|
// options: {
|
|
|
|
// presets: ['@babel/preset-env']
|
|
|
|
// }
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
test: /\.(scss|css)$/,
|
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader:
|
|
|
|
isProduction === true
|
|
|
|
? MiniCssExtractPlugin.loader
|
|
|
|
: "style-loader",
|
|
|
|
// loader: 'style-loader',
|
|
|
|
// loader: MiniCssExtractPlugin.loader,
|
|
|
|
// options: {
|
|
|
|
// hmr: process.env.NODE_ENV === 'development',
|
|
|
|
// },
|
|
|
|
},
|
2020-11-17 11:52:09 +00:00
|
|
|
// {
|
2022-09-07 11:37:27 +00:00
|
|
|
// loader: "vue-style-loader",
|
|
|
|
// options: {
|
|
|
|
// sourceMap: true
|
|
|
|
// }
|
2021-04-15 16:06:58 +00:00
|
|
|
// },
|
2022-09-07 11:37:27 +00:00
|
|
|
// Translates CSS into CommonJS
|
2020-11-12 12:44:48 +00:00
|
|
|
{
|
2022-09-07 11:37:27 +00:00
|
|
|
loader: "css-loader",
|
|
|
|
options: {
|
|
|
|
sourceMap: true,
|
|
|
|
},
|
2020-11-12 12:44:48 +00:00
|
|
|
},
|
2022-09-07 11:37:27 +00:00
|
|
|
// {
|
|
|
|
// loader: 'resolve-url-loader',
|
|
|
|
// },
|
|
|
|
// Compiles Sass to CSS
|
2020-11-12 12:44:48 +00:00
|
|
|
{
|
2022-09-07 11:37:27 +00:00
|
|
|
loader: "sass-loader",
|
|
|
|
options: {
|
|
|
|
sourceMap: true,
|
|
|
|
},
|
2020-11-12 12:44:48 +00:00
|
|
|
},
|
2022-09-07 11:37:27 +00:00
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
2020-11-12 12:44:48 +00:00
|
|
|
},
|
2021-04-15 16:06:58 +00:00
|
|
|
resolve: {
|
2022-09-07 11:37:27 +00:00
|
|
|
extensions: ["*", ".js", ".jsx", ".tsx", ".ts"],
|
2021-09-01 11:04:48 +00:00
|
|
|
},
|
2020-11-12 12:44:48 +00:00
|
|
|
stats: {
|
2022-09-07 11:37:27 +00:00
|
|
|
colors: true,
|
2020-11-12 12:44:48 +00:00
|
|
|
},
|
2022-09-07 11:37:27 +00:00
|
|
|
// devtool: (isProduction === true) ? 'hidden-source-map' : 'inline-source-map',
|
2022-09-07 13:15:39 +00:00
|
|
|
devtool: (isProduction === true) ? 'hidden-source-map' : 'inline-source-map',
|
2020-11-12 12:44:48 +00:00
|
|
|
|
|
|
|
optimization: {
|
2022-09-07 11:37:27 +00:00
|
|
|
minimize: isProduction,
|
|
|
|
runtimeChunk: "single",
|
|
|
|
splitChunks: {
|
|
|
|
cacheGroups: {
|
|
|
|
defaultVendors: {
|
|
|
|
test: /[\\\/]node_modules[\\\/]/,
|
|
|
|
name: "chunk-vendors",
|
|
|
|
// chunks: 'all',
|
|
|
|
priority: -10,
|
|
|
|
chunks: "initial",
|
|
|
|
},
|
|
|
|
common: {
|
|
|
|
name: "chunk-common",
|
|
|
|
minChunks: 2,
|
|
|
|
priority: -20,
|
|
|
|
chunks: "initial",
|
|
|
|
reuseExistingChunk: true,
|
|
|
|
},
|
|
|
|
// styles: {
|
|
|
|
// name: 'styles',
|
|
|
|
// test: /\.css$/,
|
|
|
|
// chunks: 'all',
|
|
|
|
// enforce: true
|
|
|
|
// }
|
2021-09-01 11:04:48 +00:00
|
|
|
},
|
2022-09-07 11:37:27 +00:00
|
|
|
},
|
|
|
|
minimizer: [
|
|
|
|
new TerserPlugin({
|
|
|
|
// cache: true,
|
|
|
|
parallel: true,
|
|
|
|
// sourceMap: true, // Must be set to true if using source-maps in production
|
|
|
|
extractComments: true,
|
|
|
|
terserOptions: {
|
|
|
|
// compress: {
|
|
|
|
// directives: false,
|
|
|
|
// // drop_console: true,
|
|
|
|
// // drop_debugger: true,
|
|
|
|
// // keep_classnames: false,
|
|
|
|
// // keep_fnames: false,
|
|
|
|
// },
|
|
|
|
compress: {
|
|
|
|
directives: false,
|
|
|
|
arrows: true,
|
|
|
|
collapse_vars: true,
|
|
|
|
comparisons: true,
|
|
|
|
computed_props: true,
|
|
|
|
hoist_funs: true,
|
|
|
|
hoist_props: true,
|
|
|
|
hoist_vars: true,
|
|
|
|
inline: true,
|
|
|
|
loops: true,
|
|
|
|
negate_iife: true,
|
|
|
|
properties: true,
|
|
|
|
reduce_funcs: true,
|
|
|
|
reduce_vars: true,
|
|
|
|
switches: true,
|
|
|
|
toplevel: true,
|
|
|
|
typeofs: true,
|
|
|
|
booleans: true,
|
|
|
|
if_return: true,
|
|
|
|
sequences: true,
|
|
|
|
unused: true,
|
|
|
|
conditionals: true,
|
|
|
|
dead_code: false,
|
|
|
|
evaluate: true,
|
|
|
|
},
|
|
|
|
mangle: true, // Note `mangle.properties` is `false` by default.
|
|
|
|
keep_classnames: false,
|
|
|
|
keep_fnames: false,
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
],
|
2020-11-12 12:44:48 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
plugins: [
|
2022-09-07 11:37:27 +00:00
|
|
|
// new VueLoaderPlugin(),
|
2021-02-10 11:20:43 +00:00
|
|
|
|
2022-09-07 11:37:27 +00:00
|
|
|
new webpack.DefinePlugin({
|
|
|
|
// Remove this plugin if you don't plan to define any global constants
|
|
|
|
ENVIRONMENT: JSON.stringify(process.env.NODE_ENV),
|
|
|
|
CONSTANT_VALUE: JSON.stringify(process.env.CONSTANT_VALUE),
|
|
|
|
MATOMO_SITE_ID: JSON.stringify(process.env.MATOMO_SITE_ID),
|
|
|
|
MATOMO_TRACKER_URL: JSON.stringify(process.env.MATOMO_TRACKER_URL),
|
|
|
|
SERVICE_URL: JSON.stringify(process.env.SERVICE_URL),
|
|
|
|
POINT_URL: JSON.stringify(process.env.POINT_URL),
|
|
|
|
EDGE_URL: JSON.stringify(process.env.EDGE_URL),
|
2021-07-06 09:08:59 +00:00
|
|
|
|
2022-09-07 11:37:27 +00:00
|
|
|
CUSTOM_VAR: JSON.stringify("value5 goes here"), // no quotes needed, string value
|
|
|
|
}),
|
|
|
|
// extractLess,
|
2020-11-17 11:52:09 +00:00
|
|
|
|
2022-09-07 11:37:27 +00:00
|
|
|
new MiniCssExtractPlugin({
|
|
|
|
// Make sure MiniCssExtractPlugin instance is included in array before the PurifyCSSPlugin
|
|
|
|
// Options similar to the same options in webpackOptions.output
|
|
|
|
// both options are optional
|
|
|
|
// filename: '[name].css',
|
|
|
|
// chunkFilename: '[id].css',
|
|
|
|
filename: "[name].css",
|
|
|
|
chunkFilename: "[id].css",
|
|
|
|
}),
|
2021-02-10 11:20:43 +00:00
|
|
|
|
2022-09-07 11:37:27 +00:00
|
|
|
// new PurifyCSSPlugin({
|
|
|
|
// paths: glob.sync(__dirname + '/*.html'),
|
|
|
|
// minimize: true,
|
|
|
|
// }),
|
2020-11-12 12:44:48 +00:00
|
|
|
|
2022-09-07 11:37:27 +00:00
|
|
|
(isProduction) && new WebpackManifestPlugin({
|
|
|
|
fileName: 'manifest.json'
|
|
|
|
}),
|
2020-11-12 12:44:48 +00:00
|
|
|
|
2022-09-07 11:37:27 +00:00
|
|
|
//auto updating on webpack dev server
|
|
|
|
(devMode) && new webpack.HotModuleReplacementPlugin() // HMR plugin will cause problems with [chunkhash]
|
2020-11-17 11:52:09 +00:00
|
|
|
|
2022-09-07 11:37:27 +00:00
|
|
|
].filter(Boolean),
|
|
|
|
};
|
|
|
|
};
|