dynamic-import

import() breaks in Angular 7.2.3 + Webpack 4.28

孤人 提交于 2019-12-13 03:56:54
问题 I have the following code : var path = "./relative/path/to/" + fileName + ".json"; import(path).then(cb); The import works as expected in my Electron demo (which uses Webpack 3.12). It breaks in my Angular demo (which uses Webpack 4.28). My Angular demo has the following Webpack config : module.exports = { node: { fs: 'empty' } }; It produces the following error at runtime : Unhandled Promise rejection: Cannot find module './resources/symbology/labelTemplates/labelTemplates.json' ; Zone:

Handling dynamic import with py2exe

本秂侑毒 提交于 2019-12-12 11:23:21
问题 I have a problem when preparing an .exe for my app using py2exe. The source of this problem is the following function that I created to use classes from a dynamically defined module. def of_import(module, classname, country = None): ''' Returns country specific class found in country module ''' if country is None: country = CONF.get('simulation', 'country') _temp = __import__(country + '.' + module, globals = globals(), locals = locals(), fromlist = [classname], level=-1) return getattr(_temp

Name webpack chunks from react-loadable

两盒软妹~` 提交于 2019-12-05 11:04:55
问题 I've successfully added react-loadable library in my project to enable code splitting, the only problem I've found is that the chunks generated by webpack are not named, they are given integer names. My code for react-loadable use is const AppRootLoadable = Loadable({ loader: () => import(/* webpackChunkName: "app" */ './App'), loading: () => null, render(loaded) { const Component = loaded.default; return <Component />; }, }); I've added the comment to tell webpack 3 that I want this chunk to

Dynamic import with not bundled file

随声附和 提交于 2019-12-04 11:06:57
I have a React project bundled with Webpack. I have a component that I want it to render components Dynamically. In my case, the path of the component comes from props. Also, these components are not bundled in my project .js file; they are external React components/libaries. I've tried the Dynamic ES6 import: componentWillReceiveProps(nextProps){ if(nextProps.pagesData && this.props.pagesData !== nextProps.pagesData && nextProps.pagesData.get('cards').count() > 0){ // Getting the first card from the Immutable object let card = nextProps.pagesData.getIn(['cards', 0]); // Getting the cardType

SSR: dynamic import in react app how to deal with html miss match when component is loading on the client

梦想与她 提交于 2019-12-04 04:21:17
问题 I'm just starting on server side rendering a react 16 app using code splitting and dynamic import thanks to webpack 4 and react-loadable. My question might sound stupid but there's something I don't quite get. On the server side, I'm waiting that webpack has loaded all modules before spitting out the html to the client. On the client side I have a kind of loading component rendered, before rendering the loaded component. So basically the server renders the loaded component: <div>loaded

React Router with React 16.6 Suspense “Invalid prop `component` of type `object` supplied to `Route`, expected `function`.”

十年热恋 提交于 2019-12-03 16:26:53
问题 I'm using the latest version (16.6) of React with react-router (4.3.1) and trying to use code splitting using React.Suspense . Although my routing is working and the code did split into several bundles loaded dynamically, I'm getting a warning about not returning a function, but an object to Route . My code: import React, { lazy, Suspense } from 'react'; import { Switch, Route, withRouter } from 'react-router-dom'; import Loading from 'common/Loading'; const Prime = lazy(() => import('modules

Dynamic imports in ES6 with runtime variables

瘦欲@ 提交于 2019-11-28 00:15:44
Recently stumbled upon the dynamic import proposal and also this Youtube video . Thought would be a great idea to use it for on demand imports of components in React. Running into an issue where I was not able to "resolve" a path when import is passed string literals as runtime variables. for eg: <div> <button onClick={this._fetchComp.bind(this, "../component/Counter")}> Get Asyn Comp </button> </div> Tried with multiple options for _fetchComp, but passing parameters doesnt seem to work . A breakdown of the different options tried. Template Strings Does Not Work : Getting an the below error on

Dynamically import a method in a file, from a string

一个人想着一个人 提交于 2019-11-27 17:26:07
I have a string, say: abc.def.ghi.jkl.myfile.mymethod . How do I dynamically import mymethod ? Here is how I went about it: def get_method_from_file(full_path): if len(full_path) == 1: return map(__import__,[full_path[0]])[0] return getattr(get_method_from_file(full_path[:-1]),full_path[-1]) if __name__=='__main__': print get_method_from_file('abc.def.ghi.jkl.myfile.mymethod'.split('.')) I am wondering if the importing individual modules is required at all. Edit: I am using Python version 2.6.5. From Python 2.7 you can use the importlib.import_module() function. You can import a module and

Python - create an EXE that runs code as written, not as it was when compiled

大兔子大兔子 提交于 2019-11-27 15:01:34
I'm making a pygame program that is designed to be modular. I am building an exe with pygame2exe of the file main.py, which basically just imports the real main game and runs it. What I'm hoping for is a sort of launcher that will execute Python scripts from an EXE, rather than a single program containing all immutable files. What is the best way to go about this? I've tried using imp to dynamically import all modules at runtime instead of implicitly importing them, but that seems to break object inheritance. After some experiments I've found a solution. Create a separate folder source in the

Dynamically importing Python module

笑着哭i 提交于 2019-11-26 18:53:53
I have a trusted remote server that stores many custom Python modules. I can fetch them via HTTP (e.g. using urllib2.urlopen ) as text/plain, but I cannot save the fetched module code to the local hard disk. How can I import the code as a fully operable Python module, including its global variables and imports? I suppose I have to use some combination of exec and imp module's functions, but I've been unable to make it work yet. It looks like this should do the trick: importing a dynamically generated module >>> import imp >>> foo = imp.new_module("foo") >>> foo_code = """ ... class Foo: ...