More extensive mangling terser-webpack-plugin? - vue.js

Is there a way to thoroughly mangle vue components that have been bundled with webpack?
When applying mangling via terser-webpack-plugin with mangle.properties set to true, then not all of the property names are mangled, for example:
location: {
lng: -.134281,
lat:51.513508,
zoom:13,
pitch:1,
bearing:60
}
becomes
location:{
k:-.134281,
M:51.513508,
zoom:13,
pitch:1,
V:60
}
Edit
As requested: the relevant portion of the Webpack configuration file, in this case the default vie-cli config with the mangle.properties item manually added:
minimizer: [
{
options: {
test: /\.m?js(\?.*)?$/i,
chunkFilter: () => true,
warningsFilter: () => true,
extractComments: false,
sourceMap: false,
cache: true,
cacheKeys: defaultCacheKeys => defaultCacheKeys,
parallel: true,
include: undefined,
exclude: undefined,
minify: undefined,
terserOptions: {
output: {
comments: /^\**!|#preserve|#license|#cc_on/i
},
compress: {
arrows: false,
collapse_vars: false,
comparisons: false,
computed_props: false,
hoist_funs: false,
hoist_props: false,
hoist_vars: false,
inline: false,
loops: false,
negate_iife: false,
properties: false,
reduce_funcs: false,
reduce_vars: false,
switches: false,
toplevel: false,
typeofs: false,
booleans: true,
if_return: true,
sequences: true,
unused: true,
conditionals: true,
dead_code: true,
evaluate: true
},
mangle: {
safari10: true,
properties: true
}
}
}
}
],

These two properties (zoom, pitch) so happened to be included in the reserved name list, have a look at this default domprops.json file which UglifyJS uses internally during mangling.
A default exclusion file is provided in tools/domprops.json which should cover most standard JS and DOM properties defined in various browsers. Pass --mangle-props domprops to disable this feature
If you like to keep this default list, you could do any of the following in the custom minify option of the plugin:
Create your custom reserved name list,
Load up the default list (domprops.json) and pass in a function/filter for removing those unwanted names,
Simply merge these two files if you are sure there is no name conflict.
webpack.config.js
{
optimization: {
minimizer: [
new TerserPlugin({
minify(file, sourceMap) {
const uglifyJsOptions = {
mangle: {
properties: {
reserved: require('your_custom_list')
}
// Or filter them
properties: {
reserved: require('uglify-js/tools/domprops.json')
.filter(name => ![
'zoom',
'pitch'
]
.includes(name))
}
}
};
return require('uglify-js').minify(file, uglifyJsOptions);
},
}),
],
},
}
Also, please mind the similarities between mangle.reserved and mangle.properties.reserved while doing this, as the latter one might be what you need here. Check out the minify option structure.

Related

Error evaluating function `ceil`: argument must be a number

On OSX, after I installed all of dependencies by yarn install, The webpack bundle's output keeps showing the error Error evaluating function ceil: argument must be a number.
I have no idea why this happen but it works on my linux machine with the same package.json
Some info:
webpack: "5.56.0"
less: "^4.1.2"
less-loader: "^10.0.1"
Here is my less-loader config:
{loader: "less-loader"}
It looks like the there is a change of the default options of less based on what I've found in here
https://lesscss.org/usage/#less-options-math
The solution is adding the option for less-loader in webpack config as following:
{
loader: "less-loader",
options: {
lessOptions: {
math: 'always' // <=== add this
}
}
}
Also you should change => strictMath: false
Example (my file config-overrides.js):
const addLessLoader = require("customize-cra-less-loader");
module.exports = override(
addLessLoader({
cssLoaderOptions: {
sourceMap: true,
modules: {
localIdentName: "[hash:base64:8]",
},
},
lessLoaderOptions: {
lessOptions: {
math: "always",
modifyVars: { "#primary-color": "#2a4365" },
javascriptEnabled: true,
strictMath: false,
},
},
})
);

TypeOrm + Sqlite works only in development [React Native + Expo]

On development the app database works very well but when I generated APK it just not work, I can't use the database.
I found this answare of jbenzshawel:
1º: yarn add metro-minify-terser
2º: Update the metro config to keep class names and file names. Add the following to the metro.config.js transformer:
minifierConfig: {
ecma: 8,
keep_classnames: true,
keep_fnames: true,
module: true,
mangle: {
module: true,
keep_classnames: true,
keep_fnames: true,
},
},
So if you need to create metro.config.js add the following:
const { getDefaultConfig } = require('expo/metro-config');
const config = getDefaultConfig(__dirname);
config.transformer.minifierPath = 'metro-minify-terser';
config.transformer.minifierConfig = {
ecma: 8,
keep_classnames: true,
keep_fnames: true,
module: true,
mangle: {
module: true,
keep_classnames: true,
keep_fnames: true,
},
};
module.exports = config;

Nuxt i18n does not load cookie language in root directory

Whenever I select a language in my application, it saves this parameter in the "lang" cookie, but accessing the root (http://localhost) without the language path (http://localhost/en) it loads the default language "pt", even the cookie set in another language "en" or "es". This is normal? Or is there any configuration for this type of situation?
[
'nuxt-i18n',
{
locales: [
{
code: 'en',
file: 'en.js'
},
{
code: 'es',
file: 'es.js'
},
{
code: 'pt',
file: 'pt.js'
}
],
lazy: true,
langDir: 'lang/',
parsePages: false,
strategy: 'prefix',
defaultLocale: 'pt',
rootRedirect: 'pt',
detectBrowserLanguage: {
useCookie: true,
cookieDomain: null,
cookieKey: 'lang',
alwaysRedirect: false,
fallbackLocale: 'pt'
},
}
]
Method change lang:
changeLanguage(lang) {
this.locale = lang
this.$i18n.setLocale(lang)
this.$moment.locale(lang);
},
I found that I needed to set the alwaysRedirect parameter to true, it forces the redirect by the cookie.
detectBrowserLanguage: {
alwaysRedirect: true
},

grunt-contrib-less: compilation on watch task removes sourcemap link

Here's my less task config:
less: {
development: {
options: {
compress: false,
sourceMap: true,
yuicompress: true,
sourceMapFilename: 'export/style/app.css.map',
sourceMapURL: '/style/app.css.map'
},
files: {
"export/style/app.css": "less/app.less"
}
}
},
If I just type grunt less, in my compiled file i get the /*# sourceMappingURL=/style/app.css.map */ comment correctly.
Instead, when i run grunt and my watch task kicks in, the /*# sourceMappingURL=/style/app.css.map */ comment is removed on compilation.
Here's my watch task for less:
watch: {
less: {
files: ['less/*.less'],
tasks: ['less', 'postcss'],
options: {
livereload: true,
nospaces: true
}
}
},
What am I doing wrong?
it was actually the postcss task preventing the comment to appear. fixed with
postcss: {
options: {
map: true,

Weyland output map file and optimize css?

How do I configure weyland to optimize the css files and also include the map file of the js in the output?
My current config is:
exports.config = function(weyland) {
weyland.build('main')
.task.jshint({
include: 'App/**/*.js',
exclude: ['App/main-built.js'],
})
.task.uglifyjs({
include: ['App/**/*.js', 'Scripts/durandal/**/*.js'],
exclude: ['App/main-built.js'],
})
.task.rjs({
include: ['Content/**/*.css', 'App/**/*.{js,html}', 'Scripts/durandal/**/*.js'],
exclude: ['App/main-built.js'],
loaderPluginExtensionMaps: {
'.html': 'text',
},
rjs: {
name: '../Scripts/almond-custom', //to deploy with require.js, use the build's name here instead
insertRequire: ['main'], //not needed for require
baseUrl: 'App',
mainConfigFile: 'App/main.js', //not needed for require
wrap: true, //not needed for require
paths: {
'text': '../Scripts/text',
'durandal': '../Scripts/durandal',
'plugins': '../Scripts/durandal/plugins',
'transitions': '../Scripts/durandal/transitions',
'knockout': 'empty:',
'bootstrap': 'empty:',
'jquery': 'empty:'
},
inlineText: true,
preserveLicenseComments: false,
generateSourceMaps: true,
//optimize : 'none',
optimize: 'uglify2',
optimizeCss: 'standard.keepLines',
pragmas: {
build: true
},
stubModules: ['text'],
keepBuildDir: true,
out: 'App/main-built.js'
}
});
}