Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ES6 module code executed every time it is imported

Is the code in ES6 modules executed every time we import a module? I'm using webpack and it seems that it does exactly that.

// FormStore.js
import sessionActions from "../../session/actions/session";

// session.spec.js
import sessionActions from "../../../src/session/actions/session";

This causes the code in the session module to be executed twice
like image 246
ppoliani Avatar asked Sep 10 '15 12:09

ppoliani


1 Answers

I don't know exactly the answer, but I suspect it has to do with karma. I think it's due to having two different bundles.

In karma.config

preprocessors: {
    "client/specs/index.ts": ["webpack"],
    "client/specs/**/*spec.ts": ["webpack"]
},

webpack: {
    entry: {
        index: "./client/src/index.tsx",
        vendor: []
    }
},

Basically, I don't really need to add the index entry point, as this will probably create an additional bundle.

like image 135
ppoliani Avatar answered Oct 16 '22 19:10

ppoliani