webpack-contrib / imports-loader

Imports Loader
MIT License
520 stars 63 forks source link

Support dot notation in variable names #30

Closed fredriks closed 7 years ago

fredriks commented 8 years ago

import?abc.def.ghi=>1 => var abc = {}; abc.def = {}; abc.def.ghi = 1;

import?window.jQuery=jquery => var window = {}; window.jQuery = require("jquery");

Fixes #28, fixes #22, fixes #32

korya commented 7 years ago

Does this PR handle case of injecting multiple globals? For example: import?window.jQuery=jquery,window._=lodash

jsf-clabot commented 7 years ago

CLA assistant check
All committers have signed the CLA.

fredriks commented 7 years ago

@korya It does handle multiple globals on window. I've added tests that illustrate various cases.

korya commented 7 years ago

Great! Thanks!

korya commented 7 years ago

@sokra What do you think? can it be merged?

artyomtrityak commented 7 years ago

It looks like this code change may override some variables which are already exist. For example i have global / local variable noty.

import?noty.theme

will be compiled to

var noty = {};
var noty.theme = __webpack_require__(XXX);

which will override my global / local variable noty that can be used in code

SpaceK33z commented 7 years ago

@fredriks, looks like @artyomtrityak is right (disclaimer: I'm looking purely at the code). At the moment you have a specific check for var window (window || {}), perhaps that could be changed so it works on all variables?

fredriks commented 7 years ago

Aye, good point! I'll update the PR with a more general approach.

artyomtrityak commented 7 years ago

looks good for me

SpaceK33z commented 7 years ago

Thanks a lot @fredriks!

SpaceK33z commented 7 years ago

Released imports-loader@0.7.0 with this. Thanks again @fredriks, this has solved a lot of issues.