require

require node modules at the file beginning

▼魔方 西西 提交于 2019-12-23 23:14:54
问题 I had a habit of requiring all my node modules in the beginning of the app.js file. var express=require('express'), bodyParser = require( 'body-parser' ), cookieParser = require( 'cookie-parser' ), compression = require( 'compression' ), . . But some modules are used for single jobs in a single function, so I can remove those from the beginning and place them inline. var express=require('express'), bodyParser = require( 'body-parser' ), cookieParser = require( 'cookie-parser' ), compression =

nodejs Import require conversion

可紊 提交于 2019-12-23 20:52:30
问题 Learning NodeJs here. Problem is when I tried to search for answers, I am not finding what I am looking for. Probably because this is too basic or non-issue. I am working on nodejs with angular2. So naturally, I have things like: import { stuff } from 'some_module' But I am trying to work with a package that has usage example of: var stuff = require('some_module') Obviously, my code didn't work when I use import etc. else I wouldn't be posting here. Is it because I am doing something wrong?

Nodejs进阶:如何玩转子进程(child_process)

守給你的承諾、 提交于 2019-12-23 17:39:26
本文摘录自个人总结《Nodejs学习笔记》,更多章节及更新,请访问 github主页地址 。欢迎加群交流,群号 197339705 。 模块概览 在node中,child_process这个模块非常重要。掌握了它,等于在node的世界开启了一扇新的大门。熟悉shell脚本的同学,可以用它来完成很多有意思的事情,比如文件压缩、增量部署等,感兴趣的同学,看文本文后可以尝试下。 举个简单的例子: const spawn = require('child_process').spawn; const ls = spawn('ls', ['-lh', '/usr']); ls.stdout.on('data', (data) => { console.log(`stdout: ${data}`); }); ls.stderr.on('data', (data) => { console.log(`stderr: ${data}`); }); ls.on('close', (code) => { console.log(`child process exited with code ${code}`); }); 几种创建子进程的方式 注意事项: 下面列出来的都是异步创建子进程的方式,每一种方式都有对应的同步版本。 .exec() 、 .execFile() 、 .fork() 底层都是通过

RequireJs optimizer ignore plugin

对着背影说爱祢 提交于 2019-12-23 13:01:10
问题 I would like to ignore the use of a require js plugin when I use the optimizer define(["css!styles.css"]) This always gives me this error Cannot read property 'normalize' of undefined . I've set this options to the require optimizer { paths : { 'css' : 'empty:' } } But it keeps giving me the error. 回答1: I don't know if that is what you want, but you could stub out the css plugin. //Specify modules to stub out in the optimized file. The optimizer will //use the source version of these modules

Using a query-string in require_once in PHP

拟墨画扇 提交于 2019-12-23 07:47:27
问题 On one of my pages I have a require_once('../path/to/url/page.php'); which works with no problems. The moment I add a query string require_once('../path/to/url/page.php?var=test'); it won't include the file anymore. It's just blank. Anyone have any ideas of why? Can you not use a query-string in a require? Thanks, Ryan 回答1: By using require_once('../path/to/url/page.php?var=test'); , php will not make a new request to page.php, it will actually search for the file named page.php?var=test and

[Node.js]模块

[亡魂溺海] 提交于 2019-12-23 01:26:11
模块可以让Node.js的文件之间相互调用,模块是Node.js应用程序的基本组成部分,文件和模块是一一对应的,换言之,一个Node.js文件就是一个模块,这个文件可能是js代码,json或者编译过的c/C++扩展。 创建模块 在node.js中,创建一个模块是非常简单的。 一个例子 创建一个名为main.js的文件,代码如下: var hello=require("./hello"); hello.world(); 代码require("./hello")引入当前目录下的hello.js文件(./为当前目录,node.js默认后缀为js)。Node.js提供了exports和require两个对象,其中exports是模块公开的接口,require用于从外部获取一个模块的接口,即所获取模块的exports对象。 创建hello.js文件,代码如下: exports.world=function(){ console.log("Hello module world"); }; hello.js通过exports对象把world作为模块的访问接口,在main.js中通过require("./hello")加载这个模块,然后就可以访问hello.js中exports对象的成员函数了。 把一个对象封装到模块中,格式如下: module.exports=function(){ ... };

seajs学习日志 简单尝试模板+数据合并、模块异步加载、非标准CMD模式定义define模块

二次信任 提交于 2019-12-22 21:39:09
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 今天继续尝试seajs 2.3的版本,那做点什么demo好呢,就来一个简单是数据模板吧,然后通过其他一些细节深入学习 先看看目录结构,按照官方demo架设 index.html只是简单入口 文件和seajs的配置项,最下面有一个seajs.use加载crontroller模块,然后回调暴露的combine方法 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>halo sea.js</title> <script type="text/javascript" src="../sea-modules/sea.js"></script> </head> <body> <div id="hello"></div> </body> </html> <script type="text/javascript"> seajs.config({ base : "../sea-modules/", alias : { "jquery" : "jquery.js" } }); seajs.use("../static/crontroller", function(c){ console.log(c.combine()); }); </script>

学习 Sea.js 笔记(三)

北城余情 提交于 2019-12-22 21:38:31
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> == require 书写约定 == 必须名为 require. define(function(require) { // 正确写法... ... }); 不用修改, 不要重命名 require (可能构造工具会查找名字 require?) 后续文档说是通过正则匹配 require 的方式来得到依赖信息. 因此必须遵守书写约定, 否则无法获得依赖项[]. require 的参数值必须是直接量: require('module'); // 不能用变量, 运算等. 简单性原则: 设计必须简单,这既是对实现的要求,也是对接口的要求。 实现的简单要比接口的简单更加重要。简单是设计中需要第一重视的因素。 CMD模块的压缩,自动构建: 1. 提取: 根据源文件, 找到模块标识 id 和依赖 dependencies, 转为临时文件. 2. 压缩: 调用 js 压缩工具进行压缩. 第1步相对其他构建多出来的步骤. 由于使用正则匹配方式获取 id, depend, 某些特定情形无法获取, 请避免. 推荐采用配套的构建工具压缩, 合并代码. (合并前要提取 id 等). == 模块的加载启动 == 1. 页面引入 sea.js (也可内嵌于网页) 2. seajs.use('xxx', callback?); == 调试 ==

seajs require("jquery")返回null解决办法

爷,独闯天下 提交于 2019-12-22 21:25:00
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> seajs require("jquery")返回null解决方法 seajs.use 某具名模块时发现其引用为 null 的问题,或是移动了文件位置导致引用为 null 或者 object is not function 的问题。这些问题都指向 Sea.js 的一个基本约定原则:ID 和路径匹配原则。 使用 seajs.use 或 require 进行引用的文件,如果是具名模块(即定义了 ID 的模块),会把 ID 和 seajs.use 的路径名进行匹配,如果一致,则正确执行模块返回结果。反之,则返回 null。 首先可以先参 看这个issue:https://github.com/seajs/seajs/issues/962 由于在 Sea.js 中,所有 JavaScript 模块都遵循 CMD(Common Module Definition) 模块定义规范。该规范明确了模块的基本书写格式和基本交互规则。 jQuery 1.7开始支持AMD规范,可以和遵循AMD规范的脚本加载器协作,比如RequireJS或者curl.js。 所以需要调整JQuery源码,如下: //old if ( typeof define === "function" && define.amd && define.amd

对 Sea.js 进行配置 seajs.config

限于喜欢 提交于 2019-12-22 21:24:46
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 可以对 Sea.js 进行配置,让模块编写、开发调试更方便。 seajs.config seajs.config(options) 用来进行配置的方法。 seajs.config({ // 别名配置 alias: { 'es5-safe': 'gallery/es5-safe/0.9.3/es5-safe', 'json': 'gallery/json/1.0.2/json', 'jquery': 'jquery/jquery/1.10.1/jquery' }, // 路径配置 paths: { 'gallery': 'https://a.alipayobjects.com/gallery' }, // 变量配置 vars: { 'locale': 'zh-cn' }, // 映射配置 map: [ ['http://example.com/js/app/', 'http://localhost/js/app/'] ], // 预加载项 preload: [ Function.prototype.bind ? '' : 'es5-safe', this.JSON ? '' : 'json' ], // 调试模式 debug: true, // Sea.js 的基础路径 base: 'http://example