I am learning Es6 modules at this current time, it took me so long to finally understand and be proficient in closures, IIFE's and scope using one script that I was almost upset to find ES6 modules bring about a different, more manageable way to organise modular code into various different scripts and then for a bundler like Webpack to bundle it all back into one ( or only a few ) scripts.
Wherever I look the solution is to use a local host to get round this which I have done? But at what point does Webpack work it's bundling? Is it when I run it in the command line or when it's loaded into the browser?
Each time I run Webpack from the command line it bundles together the latest code taken from the entry point ( specified during my config). This means I can use the ES6 module syntax on my entry file without having to use a live server as I never intend to load this js entry file into the browser, it's simply to be the controller of all other script exports by importing what I need from them. Then this script will be the target of Webpacks bundling ( the entry point) meaning the only script that is loaded into the browser is the bundled script, which has no other imports. This avoids the need to run a live server when testing ES6 modules.. If not using Webpack I would have to run a server because my main script would be importing other scripts and unless they have the same url ( they don't even have one yet in my file system) then I will get a cross origin error. As soon as I run my local server 127.0.0.1 then it would work. I prefer testing with Webpack.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.