michaelolof / vuex-class-component

A Type Safe Vuex Module or Store Using ES6 Classes and ES7 Decorators written in TypeScript.
217 stars 21 forks source link

Namespaced modules' path broken when code is minified #43

Closed aymasse closed 5 years ago

aymasse commented 5 years ago

Hello,

While using version 2.0.4, module declaration is kind of broken in minified code due to the path being pulled from the class' name. Problem is, the class name is being mangled while using vue-cli in its default configuration.

The result (for me) is that my store only has a single module (named t in my output), even if I declare several modules. This single module contains every state property of my modules but only the mutations and actions of the last declared one.

SaphuA commented 5 years ago

For now define your stores the old way:

@Module({ namespacedPath: "foo" })
export default class extends VuexModule { }

You can still define your Vuex-store the new way:

import FooStore from "@/foo/store";
const modules = { ...extractVuexModule(FooStore) };
export const store = new Vuex.Store({ modules });
danielroe commented 5 years ago

I've closed #42 as it's another expression of this issue - thanks to @SaphuA for the workaround.

If it's useful, see see my repro - and run yarn build && yarn start.

vizv commented 5 years ago

From https://github.com/michaelolof/vuex-class-component/blob/24ed31b84f5a62bbecd0bf06202eed9a9ccc526a/src/module.ts#L89

I think you setting namespaced to a string should work.

const VuexModule = createModule({
  namespaced: 'foo',
  strict: false,
  target: "nuxt",
})
michaelolof commented 5 years ago

Hello @aymasse

I've made an update based on the issue raised. Thanks to @vizv 's suggestion

interface VuexModuleOptions {
  namespaced ?:string;
  ...
}

I've modified the namespaced option to take only a string.

SaphuA commented 5 years ago

works perfectly now