darkty2009 / webpack-require-http Goto Github PK
View Code? Open in Web Editor NEWyou can use the "require" method to load http resource in webpack
you can use the "require" method to load http resource in webpack
thank you .
please help me .
webpack.config.js
externals:[
require('webpack-require-http')
]
this is code
const apiKey='xxxxxx';
require('http://codemirror.net/mode/javascript/javascript.js?ak='+apiKey); // has error
require('http://codemirror.net/mode/javascript/javascript.js?ak=xxxxxx'); // is worked
this is error
Module not found: Error: Cannot resolve module 'http://codemirror.net' in /home/mx/learn/src/components/Node
What is the reason?
The level of vegetables, please...
if the http resource is a AMD module,hao to load it?
In the browser console I am getting the error
Cannot read property 'then' of undefined
I am trying to require from inside an angular router loadChildren. In this way I could load into a module from an entirely different project. Localhost here is just used for testing this idea.
const routes: Routes = [
{ path: ``, loadChildren: () => new Promise(function (resolve) {
require('http://localhost:3100/testset-module-bundle.js').then((response: any) => {
resolve(response)
}
)
})
}
];
I'm aware that wrapping it in another promise like that is kind of dumb, but it's just for test purposes so I have more control.
The bundled code output from webpack looks like:
var routes = [
{ path: "", loadChildren: function () { return new Promise(function (resolve) {
__webpack_require__(406).then(function (response) {
resolve(response);
});
}); }
}
];
If anybody looks inside ext
folder nowadays, will just see two javascript extension treatment files, for .js
and .css
required files; but, what happens with the rest of things we can import using webpack, such fonts, images or any other kind of assets?
I'm convinced webpack-require-http
may add a treatment for assets in its code, in order to let it be imported through http and by-passing the import()
function.
Hope this won't become a super-effort at all.
Thanks a lot fot this package.
if(result.protocol == 'http:' || request.protocol == 'https:') {
correct:
if(result.protocol == 'http:' || result.protocol == 'https:') {
My code has a few requires of local files, but when i use this webpack-require-http , the external (http) file is still getting a call from the browser, even though it's in the bundle as well.
as my main objective is to reduce traffic. i need to remove the 'extra' call.
any idea why this is happening ?
Thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.