require

What are the paths that “require” looks up by default?

喜欢而已 提交于 2019-11-27 00:16:23
问题 In Ruby, I have been told that when doing require "some_file" Ruby will look for the file in certain places. I know that it looks for some_file.rb , but where does it look for it by default? 回答1: It depends on your platform, and how Ruby was compiled, so there is no "the" answer to this. You can find out by running: ruby -e 'puts $:' Generally, though, you have the standard, site, and vendor Ruby library paths, including an arch, version, and general directory under each. 回答2: Ruby looks in

Derived class defined later in the same file “does not exist”?

杀马特。学长 韩版系。学妹 提交于 2019-11-26 23:07:18
问题 Let’s suppose we’ve got two php files, a.php and b.php Here’s content of file a.php: <?php // content of a.php class A { } And here’s the content of file b.php <?php // content of b.php include dirname(__FILE__) . "/a.php"; echo "A: ", class_exists("A") ? "exists" : "doesn’t exist", "\n"; echo "B: ", class_exists("B") ? "exists" : "doesn’t exist", "\n"; echo "BA (before): ", class_exists("BA") ? "exists" : "doesn’t exist", "\n"; echo "BB: ", class_exists("BB") ? "exists" : "doesn’t exist", "

webpack dynamic module loader by require

陌路散爱 提交于 2019-11-26 23:02:19
OK, i have searched high and low but cannot reliably deterrmine if this is or is not possible with webpack. https://github.com/webpack/webpack/tree/master/examples/require.context Appears to indicate that one can pass a string to a function and it load a module... But my attempt is just not working: webpack.config.js 'use strict'; let webpack = require('webpack'), jsonLoader = require("json-loader"), path = require("path"), fs = require('fs'), nodeModules = {}; fs.readdirSync('node_modules') .filter(function(x) { return ['.bin'].indexOf(x) === -1; }) .forEach(function(mod) { nodeModules[mod] =

Getting closure-compiler and Node.js to play nice

倾然丶 夕夏残阳落幕 提交于 2019-11-26 22:54:29
问题 Are there any projects that used node.js and closure-compiler (CC for short) together? The official CC recommendation is to compile all code for an application together, but when I compile some simple node.js code which contains a require("./MyLib.js") , that line is put directly into the output, but it doesn't make any sense in that context. I see a few options: Code the entire application as a single file. This solves the problem by avoiding it, but is bad for maintenance. Assume that all

What is the difference between require('mypackage.js') and require('mypackage')?

做~自己de王妃 提交于 2019-11-26 22:46:26
Both these require statements appear to work the same way: var Mypackage = require('mypackage.js'); var Mypackage require('mypackage'); Is there a difference between them? Amol M Kulkarni Here is the answer: Module.prototype.load = function(filename) { debug('load ' + JSON.stringify(filename) + ' for module ' + JSON.stringify(this.id)); assert(!this.loaded); this.filename = filename; this.paths = Module._nodeModulePaths(path.dirname(filename)); var extension = path.extname(filename) || '.js'; if (!Module._extensions[extension]) extension = '.js'; Module._extensions[extension](this, filename);

Webpack and external libraries

懵懂的女人 提交于 2019-11-26 22:18:51
I’m trying out webpack ( http://webpack.github.io/ ) and it looks really nice, however I’m kind of stuck here. Say that I’m using a CDN for a library, f.ex jQuery. Then in my code, I want the require('jquery') to automatically point to the global jquery instance, instead of trying to include it from my modules. I’ve tried using plugins like the IgnorePlugin : new webpack.IgnorePlugin(new RegExp("^(jquery|react)$")) This works for ignoring the library, but it still says that the required module is "missing" when I run the webpacker. Somehow I need to tell webpack that jquery should be picked up

PHP: Require path does not work for cron job?

一世执手 提交于 2019-11-26 20:55:20
问题 I have a cron job that needs to include this file: require '../includes/common.php'; however, when it is run via the cron job (and not my local testing), the relative path does not work. the cron job runs the following file (on the live server): /home/username123/public_html/cron/mycronjob.php and here's the error: Fatal error: require(): Failed opening required '../includes/common.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/username123/public_html/cron/mycronjob.php on

Swift REPL: how to import, load, evaluate, or require a .swift file?

血红的双手。 提交于 2019-11-26 20:48:58
问题 In the Swift REPL, how to import (a.k.a. load, evaluate, require) a typical text *.swift file? I want to use the code from this file: ~/src/Foo.swift Syntax like this doesn't work: import ~/src/Foo.swift For comparison: An equivalent solution in the Swift REPL for a framework is: import Foundation An equivalent solution in the Ruby REPL for a *.ruby file is: require "~/src/foo" These are similar questions that are /not/ what I'm asking: How to use/make a Swift command-line script, executable,

Browserify with require('fs')

限于喜欢 提交于 2019-11-26 20:46:42
I was trying to use browserify on a file that uses the fs object. When I browserify it, the call to require('fs') doesn't get transformed and require returns {} . Is there any workaround for this? I've seen some suggestions on stackoverlow and elsewhere, but none seem to be fully realized. I actually hoped to create a google web packaged app using browserify for a class I teach. Thanks in advance. Which filesystem should the browser use then? The HTML5 filesystem is not really comparable to a traditional filesystem. It doesn't have symlinks, and it is only accessible asynchronously outside Web

require_once :failed to open stream: no such file or directory

本秂侑毒 提交于 2019-11-26 20:38:13
问题 I have this testing code in "PAGE A" : <?php require_once('../mysite/php/classes/eventManager.php'); $x=new EventManager(); $y=$x->loadNumbers(); ?> "eventManager.php" has inside a require_once: <?php require_once('../includes/dbconn.inc'); class EventManager {...} ?> My folders structure is this: mysite/php/classes folder and includes folder If i test PAGE A in a browser i receive: Warning: require_once(../includes/dbconn.inc) [function.require-once]: failed to open stream: No such file or