require

How to Nested use “Require.js” with “backbone.js”?

此生再无相见时 提交于 2019-12-21 06:32:09
问题 I'm doing the application, the use of backbone.js and require.js, I would like to achieve dynamic configuration module navigation by the "backbone.router" function, here is my question? This is my baserouter defined,I want to achieve dynamic load "backbone.view" according to "the viewPath" parameter.How can I do? define(['require', 'underscore', 'backbone'], function(require, _, Backbone) { var BaseRouter = Backbone.Router.extend({ container: "#page", loadView: function(viewPath) { **//Here

nodeJS require.paths resolve problem

删除回忆录丶 提交于 2019-12-21 04:08:42
问题 I am trying to require a file relatively and mysteriously the following is happening This works well which points to /Users/marcos/Desktop/Taper/lib/utils.js myPath = "/Users/marcos/Desktop/Taper/lib/./utils"; require(myPath); This doesn't but it should point to exactly the same file: require.paths.unshift("/Users/marcos/Desktop/Taper/lib") require("./utils"); //Doesn't work with './' require("utils"); //Works Fine Anyone knows why I can't still use ./ in this case for loading the path since

前端自动化Gulp工具常用插件

江枫思渺然 提交于 2019-12-20 21:09:40
npm init命令初始化当前文件夹后,在当前文件夹新建gulpfile.js文件。当前目录下的所有操作流都在gulpfile.js文件中定义。 gulp自动化 gulp-uglify (JS压缩) gulp-uglify安装: npm install --save-dev gulp-uglify gulp-uglify用来压缩js文件,使用的是uglify引擎。 var gulp = require('gulp'); //加载gulp var uglify = require('gulp-uglify'); //加载js压缩 // 定义一个任务 compass gulp.task('compass', function () { gulp.src(['js/*.js','!js/*.min.js']) //获取文件,同时过滤掉.min.js文件 .pipe(uglify()) .pipe(gulp.dest('javascript/')); //输出文件 }); 小技巧,第二个参数 '!js/*.min.js' 是用来过滤掉后缀为min.js,!感叹号为排除模式。 gulp-minify-css(CSS压缩) gulp-minify-css安装: npm install --save-dev gulp-minify-css 可以使用它来压缩CSS文件 var gulp =

Require file without executing code?

冷暖自知 提交于 2019-12-20 17:37:57
问题 Here I have two files: file.rb def method puts "This won't be outputted." end puts "This will be outputted." main.rb require "./file" When running main.rb it will load all the code inside file.rb so I will get "This will be outputted." on the screen. Is it possible to load a file without having it to run the code? Cause I want to load all the methods (in modules and classes too) without having to execute code outside these scopes. 回答1: Is it possible to load a file without having it to run

Require file without executing code?

依然范特西╮ 提交于 2019-12-20 17:36:40
问题 Here I have two files: file.rb def method puts "This won't be outputted." end puts "This will be outputted." main.rb require "./file" When running main.rb it will load all the code inside file.rb so I will get "This will be outputted." on the screen. Is it possible to load a file without having it to run the code? Cause I want to load all the methods (in modules and classes too) without having to execute code outside these scopes. 回答1: Is it possible to load a file without having it to run

NodeJs require('./file.js') issues

强颜欢笑 提交于 2019-12-20 10:15:32
问题 I am having issues including files to execute in my NodeJs project. I have two files in the same directory: a.js var test = "Hello World"; and b.js require('./a.js'); console.log(test); I execute b.js with node b.js and get the error ReferenceError: test is not defined . I have looked through the docs http://nodejs.org/api/modules.html#modules_file_modules What am I missing? Thanks in advance. 回答1: Change a.js to export the variable: exports.test = "Hello World"; and assign the return value

Override the require function

坚强是说给别人听的谎言 提交于 2019-12-20 09:37:08
问题 Is it possible to override the global require function, affecting it at process level? From what I know, the require function is provided as argument in the function that wraps the NodeJS scripts: (function (..., require, __dirname) { // something like this // The wrapped code })(...); Is there any way to modify the require function? (function () { var _require = require; require = function () { console.log("..."); _require.apply(this, arguments); }; })(); This will probably affect only the

EggJs+Vue服务端渲染实践

亡梦爱人 提交于 2019-12-20 09:28:32
最近需要把公司基于Vue进行开发的webView页面改造成ssr的。由于现有的node后台是基于EggJs开发的,如果改用其他脚手架搭建需要的成本也忒大了,这得加多少班啊,索性就自己瞎捣鼓一下吧。 我们先来看看当我们使用vue客户端渲染时一个页面的加载过程。首先是我们请求的index.html到达浏览器,然后浏览器再根据index.html中的script标签去请求js文件,请求到了js文件后开始执行Vue实例的初始化操作。 vue的实例初始化大体上需要经过: 实例初始属性设置,挂载createElement方法->beforecreate->initState中对Props/data声明响应式对象,初始化methods并bind执行上下文,对computed属性生成computed watcher->created->生成渲染watcher->执行updateComponent->执行render方法,通过之前挂载的createElement方法生成vnode节点->执行_update方法,调用_ patch _方法根据虚拟dom生成真实的dom节点->mounted 这么多步骤的处理之后,我们才能在浏览器上看到我们的页面,而且注意是每一个组件都需要经历这么多步骤才可以哦,所以如果在对首屏加载时间有一定要求的页面中我们还使用客户端渲染的方式去处理。那么大概,可能

VUE2组件懒加载浅析

情到浓时终转凉″ 提交于 2019-12-20 07:18:25
VUE2组件懒加载浅析 vue2组件懒加载浅析 一、 什么是懒加载 懒加载也叫延迟加载,即在需要的时候进行加载,随用随载。 二、为什么需要懒加载 在单页应用中,如果没有应用懒加载,运用webpack打包后的文件将会异常的大,造成进入首页时,需要加载的内容过多,延时过长,不利于用户体验,而运用懒加载则可以将页面进行划分,需要的时候加载页面,可以有效的分担首页所承担的加载压力,减少首页加载用时 三、如何与webpack配合实现组件懒加载   1、在webpack配置文件中的output路径配置chunkFilename属性 1 2 3 4 5 6 output: { path: resolve(__dirname, 'dist' ), filename: options.dev ? '[name].js' : '[name].js?[chunkhash]' , chunkFilename: 'chunk[id].js?[chunkhash]' , publicPath: options.dev ? '/assets/' : publicPath },   chunkFilename路径将会作为组件懒加载的路径   2、配合webpack支持的异步加载方法 resolve => require([URL], resolve), 支持性好 () => system.import(URL)

webpack构建vue项目(配置篇)

社会主义新天地 提交于 2019-12-20 07:18:09
最近公司要求用vue重构项目,还涉及到模块化开发,于是乎,我专门花了几天的时间研究了一下webpack这个目前来看比较热门的模块加载兼打包工具,发现上手并不是很容易,现将总结的一些有关配置的心得分享出来,欢迎大神来拍砖。。。 一、新建一个项目目录,cd /d 定位进去,然后输入npm init,会提示你填写一些项目的信息,一直回车默认就好了,或者直接执行npm init -y 直接跳过,这样就在项目目录下生成了一个package.json文件。 二、接下来就是通过npm安装项目依赖项,命令行输入:npm install babel-loader babel-core babel-plugin-transform-runtime babel-preset-es2015 babel-preset-stage-0 babel-runtime vue-loader vue-html-loader vue-hot-reload-api css-loader style-loader webpack webpack-dev-server --save-dev ,继续输入npm install vue@^1.0.26 --save 。 这里注意的几个点如下: 1.需要安装的依赖项视具体的项目需求来定,我只是安了几个必需的,后期会再加; 2.输入之后如果一直报错或者光标一直在转动