Skip to content

Commit

Permalink
Excluding compression for local development
Browse files Browse the repository at this point in the history
  • Loading branch information
jolzee committed Feb 20, 2020
1 parent 64018d4 commit e2cb6b5
Showing 1 changed file with 38 additions and 17 deletions.
55 changes: 38 additions & 17 deletions vue.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,34 @@ const BrotliPlugin = require("brotli-webpack-plugin");
const WebpackDeletePlugin = require("webpack-delete-plugin");
const TerserPlugin = require("terser-webpack-plugin");

const environmentVariables = process.env;
const getEnvValue = (name, fallback = "") => {
let result = fallback;
if (name in environmentVariables && environmentVariables[name] !== "") {
result = environmentVariables[name];
if (result === "true") {
result = true;
} else if (result === "false") {
result = false;
}
}
return result;
};

// const prod = process.env.NODE_ENV === "production";
const dev = process.env.NODE_ENV === "development";
// var const = process.env.NODE_ENV === "qa";
const isLocalDev = getEnvValue("LOCAL", false);

let produceSourceMaps = false;
if (process.env.VUE_APP_SOURCE_MAP === "true" || dev) {
if ((process.env.VUE_APP_SOURCE_MAP === "true" || dev) && !isLocalDev) {
produceSourceMaps = true;
} else {
produceSourceMaps = false;
}

let stopCompression = getEnvValue("LOCAL", false);

console.log(`produceSourceMaps: ${produceSourceMaps}`);

const enableJavaScriptCompression = process.env.VUE_APP_BUILD_COMPRESS_JAVASCRIPT_ASSETS
Expand Down Expand Up @@ -87,22 +104,7 @@ let buildConfig = {
},
configureWebpack: {
devtool: "source-map",
plugins:
enableJavaScriptCompression || enableCssCompression
? [
new CompressionPlugin({
test: compressionPluginTest(),
exclude: /leopardConfig(?:\..{1,10}?)??\.js/,
threshold: 7000
}),
new BrotliPlugin({
asset: "[path].br[query]",
test: brotliPluginTest(),
threshold: 7000,
minRatio: 0.8
})
]
: []
plugins: []
},
chainWebpack: config => {
config.externals({
Expand Down Expand Up @@ -136,6 +138,25 @@ let buildConfig = {
]
};

if (!stopCompression && (enableJavaScriptCompression || enableCssCompression)) {
buildConfig.configureWebpack.plugins.push(
new CompressionPlugin({
test: compressionPluginTest(),
exclude: /leopardConfig(?:\..{1,10}?)??\.js/,
threshold: 7000
})
);

buildConfig.configureWebpack.plugins.push(
new BrotliPlugin({
asset: "[path].br[query]",
test: brotliPluginTest(),
threshold: 7000,
minRatio: 0.8
})
);
}

if (!dev) {
console.log(`Using TerserPlugin`);
buildConfig.configureWebpack.plugins.push(
Expand Down

0 comments on commit e2cb6b5

Please sign in to comment.