require

Resolving circular dependencies with Node.js require and classes in CoffeeScript

孤街浪徒 提交于 2019-12-03 12:52:11
I want to know if there is a way to idiomatically avoid issues with circular dependencies with Node.js's require while using CoffeeScript classes and super . Given the following simplified CoffeeScript files: a.coffee: C = require './c' B = require './b' class A extends C b: B someMethod: -> super module.exports = A b.coffee: C = require './c' A = require './a' class B extends C a: A someMethod: -> super module.exports = B The first obvious issue here is that there is a circular dependency between A and B. Whichever one evaluates first will have {} as a reference to the other. To resolve this

[译] 优化 WEBPACK 以更快地构建 REACT

家住魔仙堡 提交于 2019-12-03 12:03:07
原文地址: OPTIMIZING WEBPACK FOR FASTER REACT BUILDS 原文作者: Jonathan Rowny 译文出自: 掘金翻译计划 本文永久链接: https://github.com/xitu/gold-miner/blob/master/TODO1/optimizing-webpack-for-faster-react-builds.md 译者: Starrier 校对者: lcx-seima 、 sishenhei7 如果您的 Webpack 构建缓慢且有大量的库 —— 别担心,有一种方法可以提高增量构建的速度!Webpack 的 DLLPlugin 允许您将所有的依赖项构建到一个文件中。这是一个取代分块的很好选择。该文件稍后将由您的主 Webpack 配置,甚至可以在共享同一组依赖项的其他项目上使用。典型的 React 应用程序可能包含几十个供应商库,这取决于您的 Flux、插件、路由和其他工具(如 lodash )。我们将通过允许 Webpack 跳过 DLL 中包含的任何引用来节省宝贵的构建时间。 本文假设您已经熟悉典型的 Webpack 和 React 设置。如果没有,请查看 SurviveJS 在 Webpack 和 React 方面的优秀内容,当您的构建时间逐步增加时,请回到本文。 第 1 步,列出您的供应商 构建和维护 DLL

require 'rubygems'

无人久伴 提交于 2019-12-03 11:33:07
问题 I have seen many samples of Ruby code with this line (for example, http://www.sinatrarb.com/). What is purpose of this require? # require 'rubygems' require 'sinatra' get '/hi' do "Hello world!" end In all cases the code works without this line. 回答1: It is often superfluous. It will allow you to require specific versions of particular gems though, with the gem command. https://guides.rubygems.org/patterns/#requiring-rubygems 回答2: require 'rubygems' will adjust the Ruby loadpath allowing you

Ruby require 'file' doesn't work but require './file' does. Why?

筅森魡賤 提交于 2019-12-03 11:29:13
I have a folder full of ruby files, and when I try and require one file in another that is in the same directory using require 'file' I get a LoadError but when I use require './file' everything works fine. Can somebody explain to me why this happens and if there is any way I can require a file without adding a ./ onto the file? (Picture of directory): If you want to require a file not from the system $LOAD_PATH but rather relative to the directory of the file you are require ing from , you should use require_relative . (Which, as you can see, isn't exactly extensively documented.) You don't

I am struggling with the requirejs optimizer and non AMD modules

♀尐吖头ヾ 提交于 2019-12-03 10:54:57
I am struggling with the requirejs optimizer. This code will work if I just load it in the browser without optimization. If I run the optimizer I get : ENOENT, no such file or directory 'C:\Users\dev\checkout\src\main\webapp\resources\scripts\ json2.js' In module tree: main This is the code requirejs.config({ paths : { jquery : "lib/jquery", bootstrap : "lib/bootstrap", modals : "lib/modals", tablesort : "lib/tablesort", json2 : "lib/json2" }, shim : { "bootstrap" : [ "jquery" ], "modals" : [ "jquery" ], "tablesort" : [ "jquery" ], "json2" : [ "jquery" ] } }); require([ "jquery", "json2",

In Perl, what is the difference between use and require for loading a module?

回眸只為那壹抹淺笑 提交于 2019-12-03 10:44:52
问题 What is the difference between doing use My::Module and require My::Module ? 回答1: The use function: use ModuleName; is equivalent to the following code using the require function: BEGIN { require ModuleName; ModuleName->import; } The BEGIN block causes this code to run as soon as the parser sees it. The require loads the module or dies trying. And then the import function of the module is called. The import function may do all sorts of things, but it is common for it to load functions into

ReactDOM.renderToString sessionStorage is not defined, window is not defined

匿名 (未验证) 提交于 2019-12-03 10:24:21
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have an application with webpack configured as a module bundler and babel as my js compiler. all on a node engine. I stetted up that when I run npm run dev the following flow will happen: The webpack-dev-server.js will run. the file is the following: const Express = require('express'); const webpack = require('webpack'); const webpackConfig = require('./dev.config'); const compiler = webpack(webpackConfig); const host = 'localhost'; const port = 8080; const serverOptions = { contentBase: `http://${host}:${port}`, quiet: true, noInfo: true,

Vue: require a package :cannot assign to read only property 'exports' of object '#<Object>'

匿名 (未验证) 提交于 2019-12-03 10:24:21
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I installed package resource-bundle in my project and now to use it in my main.js: /*main.js*/ var co=require('co'); var loader = require('resource-bundle'); co(function*(){ ... ... }).catch(onerror); And this is in the index.js of resource-bundle package: /*index.js*/ module.exports = function*(locale, dir, baseName) { ... ... ... } It gets this error: Cannot assign to read only property 'exports' of object '#<Object>' What's the problem? 回答1: Why your module.exports is a function? It should be Object Literal like this: module.exports = {

RequireJS different jQuery

匿名 (未验证) 提交于 2019-12-03 10:24:21
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I would like to use RequireJS to load jQuery (module I develop supposed to work in uncontrolled environment where jQuery might be already initialized), but there are some problems when require different versions of jQuery. Results are unexpectable. Inside require function block jQuery version is kind of random. What is wrong? Here is code to illustrate problem: <!DOCTYPE html> <html> <head> <script data-main="scripts/main" src="http://ajax.cdnjs.com/ajax/libs/require.js/0.24.0/require.min.js"></script> <script src="http://ajax.googleapis.com

Getting this error while using React router TypeError: type.toUpperCase is not a function

匿名 (未验证) 提交于 2019-12-03 10:24:21
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am developing an isomorphic app using react and express.js. I am using React Router for client side routing. While running the app i am getting following errors and warnings in console Warning : Failed propType: Invalid prop handler of type object supplied to Route , expected function . Warning : Invalid undefined handler of type object supplied to UnknownComponent , expected function . TypeError: type.toUpperCase is not a function Here is code for components/main.jsx var React = require('react'); var Counter = require('./flashCard.js');