question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"name" in @Component options is obfuscated (?) in build version

See original GitHub issue

Repro: https://github.com/sp00x/vue-typescript-name-bug

2 components, Foo (ts) and Bar (js) registered as global components in main.ts using

import Foo from '@/components/Foo.vue';
import Bar from '@/components/Bar.vue';
Vue.component(Foo.name, Foo) // typescript
Vue.component(Bar.name, Bar) // javascript

With yarn serve it logs in the console:

in App.vue:

Foo.name = Foo
Bar.name = Bar

in main.ts

Foo.name = Foo
Bar.name = Bar

and renders

Foo:
foo
- Bar:
bar

With yarn build output it logs in the console:

in App.vue:

Foo.name = t
Bar.name = Bar

in main.ts

Foo.name = t
Bar.name = Bar

renders:

Foo: - Bar:
bar

Foo is a typescript SFC, where as Bar is a regular javascript SFC with export default { name: 'Bar' }

Seems like the typescript value is being obfuscated or uglified somehow?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
simllllcommented, Apr 13, 2020

This is actually a side effect of terser webpack plugin. If you disable terser’s mangling, things work fine. I added the following in my nuxt config in build.extend() function:

if (isServer) {
  // replace terser on server side with "mangle: false"
  config.optimization.minimizer = config.optimization.minimizer.map(o => {
	if (o.constructor.name === 'TerserPlugin') {
		return new TerserPlugin({
			cache: true,
			parallel: true,
			sourceMap: true, // Must be set to true if using source-maps in production
			terserOptions: {
				mangle: false
			}
		});
	}
	return o;
  });
}
1reaction
Trinovantescommented, Nov 14, 2020

This worked for me in webpack4 without increasing the bundle size too much

module.exports = {
    optimization: {
        minimizer: [
            new TerserPlugin({
                terserOptions: {
                    keep_classnames: true,
                },
            }),
        ],
    },
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to configure functions in Vue 2 project from being ...
Is there a way (possibly in vue.config.js) that I can select certain function names from being obfuscated during build?
Read more >
Obfuscating Dart code
Obfuscation hides function and class names in your compiled Dart code, making it difficult for an attacker to reverse engineer your proprietary app....
Read more >
Shrink, obfuscate, and optimize your app
Learn how to shrink code in your release build to remove unused code and resources.
Read more >
Common ProGaurd rules you must know for Android
app/build.gradleandroid { buildTypes { release { // Enables code shrinking, obfuscation, and optimization for only
Read more >
How to obfuscate Blazor App?
It offers names obfuscation, control flow obfuscation and code ... by the ArmDot demo version 1>[ArmDot] Finished 1>Done building project ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found