//场景:让require.config配置文件成一个公共文件,每个页面引用这个公共配置
//方式一样例:
require.config({
baseUrl: (function () {
var pathName = document.location.pathname;
var index = pathName.substr(1).indexOf("assets/");
var result = pathName.substr(0, index + 1);
return result;
})()+'assets/js/', //基础目录,最好使用绝对路径,不然被路径搞得晕头转向,/开头, (../上一级目录 ./当前目录 /根目录)
paths:{
"jquery":"plugins/jquery/jquery-1.8.0.min",
"text":"plugins/require-text/text",
'Handlebars':'plugins/handlebars/handlebars',
'underscore':'plugins/underscore/underscore-min'
},
shim:{
'pocFilter':{
deps:['jquery'],
exports: 'pocFilter'
}
}
}); //引用require.js
<script src="scripts/require.js" data-main='scripts/business/example'></script> //example.js使用公共配置
require(['scripts/config'], function() {
// Configuration loaded now, safe to do other require calls
// that depend on that config.
require(['jquery'], function($) { });
}); //方式二: 1、html页面:
<script src="require.js" defer async="true" data-main="page1"></script> 2、page1.js:
require(['config'],function(){
require(['app/controller1'])
}) 3、controller1.js:
define(function(require,exports,module){
var $=require('jquery');
console.info($)
}) //参考资料-https://github.com/requirejs/example-multipage.git //模块定义方式 //1.简单的键值对形式 Simple Name/Value Pairs
define({
"name":"leyi",
"sex":"male"
}); //2.定义函数型模块 Definition Functions
define(function(){
function setName(name){
console.info(name)
}
function setSex(sex){
console.info(sex)
} return {
"setName":setName,
"setSex":setSex
}
}); //2.定义函数型模块(有依赖模块) Definition Functions with Dependencies define(['jquery'],function($){
return {
"lookDependencies":function(){
console.info($)
}
}
}); //3.模块不必返回对象。允许从函数中返回任何有效值 define(['jquery'],function($){
return function(){
return 'hello world!'
}
}); //4.用commonJS方式定义模块
define(function(require,exports, module){
var $=require('jquery');
return function(){
console.info($)
}
}) //5.定义一个有名称的模块(不推荐显式指定模块名称)
define("leyi",function(require,exports, module){
var $=require('jquery');
return function(){
console.info($)
}
}); //注意事项: /*一个文件一个模块: 每个Javascript文件应该只定义一个模块,
这是模块名-至-文件名查找机制的自然要求。
多个模块会被优化工具组织优化,但你在使用优化工具时应将多个模块放置到一个文件中。*/ /*
define()中的相对模块名: 为了可以在define()内部使用诸如require("./relative/name")的调用以正确解析相对名称,
记得将"require"本身作为一个依赖注入到模块中:
define(["require", "./relative/name"], function(require) {
var mod = require("./relative/name");
});
或者更好地,使用下述为转换CommonJS模块所设的更短的语法:
define(function(require) {
var mod = require("./relative/name");
});*/

  

requireJs require.config公共配置的更多相关文章

  1. spring cloud (八) Config client 和项目公共配置

    1 pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns="h ...

  2. SpringCloud创建Config多客户端公共配置

    1.说明 基于已经创建好的Spring Cloud配置中心, 在配置中心仅保存一套配置文件, 多个客户端可以通过配置中心读取到相同的配置, 而不需要在每个客户端重复配置一遍, 下面以一个Config ...

  3. requirejs、backbone.js配置

    requirejs初探 参考资料官网:http://requirejs.org中文译文:http://makingmobile.org/docs/tools/requirejs-api-zh reuq ...

  4. avalon 中require.config源码分析

    /********************************************************************* * 配置系统 在系统运行的开始就需要读取系统中requir ...

  5. vue-cli的webpack模版,相关配置文件dev-server.js与webpack.config.js配置解析

    1.下载vue-cli npm install vue-cli -g vue-cli的使用与详细介绍,可以到github上获取https://github.com/vuejs/vue-cli 2.安装 ...

  6. springcloud-spring cloud config统一配置中心

    统一配置中心 为什么需要统一配置中心? 统一配置中心顾名思义,就是将配置统一管理,配置统一管理的好处是在日后大规模集群部署服务应用时相同的服务配置一致,日后再修改配置只需要统一修改全部同步,不需要一个 ...

  7. @vue/cl构建得项目下,postcss.config.js配置,将px转化成rem

    依赖包: postcss-pxtorem 配置: 在项目根目录下创建 postcss.config.js 配置如下: module.exports = () => ({ plugins: [ r ...

  8. Spring Boot 揭秘与实战 附录 - Spring Boot 公共配置

    Spring Boot 公共配置,配置 application.properties/application.yml 文件中. 摘自:http://docs.spring.io/spring-boot ...

  9. html中require.config 缓存问题

    在html中,require的官方基本用法如下: <!DOCTYPE html> <html> <head> <title>My Sample Proj ...

随机推荐

  1. VMWare14 安装Mac OS系统(图解)

    ★ 背景 瞅了瞅自己干瘪的钱包,没忍心入手期待已久的 macPro,只好在虚拟机里玩一下 mac好了,等以后钱包傲气的时候再来个真实的. 安装环境: windows10 VMWare14.2 一.准备 ...

  2. 【mmall】递归查询子节点并排重

    代码 @Override public ServerResponse getSelfAndChildrenCategory(Integer categoryId) { if (categoryId ! ...

  3. 一个是EF内联多表查询,一个是EF中写SQL文。

    public IList<MenuModel> GetAllMenu() { using (IMMEntities context = new IMMEntities()) { var m ...

  4. HBSX2019 3月训练

    Day 1 3月有31天废话 今天先颓过了就只剩30天了 初步计划 每天一道字符串/数据结构题 图论学习 根据<若干图论模型探讨>(lyd)复习 二分图与网络流学习 <算法竞赛进阶指 ...

  5. Linux安装JDK(rpm)

    我以JDK1.8为例 ⒈下载 https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html ...

  6. Python笔记 【无序】 【二】

    序列list() ——把一个可迭代对象[可以是字符串,元组]转化为列表,可不带参数——生成空列表,或者带一个迭代器作为参数tuple() ——可迭代对象转化为元组str(obj) ——把obj对象转换 ...

  7. 用while实现阶乘

    题目描述: 用while语句求1!+2!+3!+...+10! #include<iostream> #include<cstdio> using namespace std; ...

  8. Python os.access() 方法

    概述 os.access() 方法使用当前的uid/gid尝试访问路径.大部分操作使用有效的 uid/gid, 因此运行环境可以在 suid/sgid 环境尝试. 语法 access()方法语法格式如 ...

  9. 题解-POI2014 FAR-FarmCraft

    Problem bzoj权限题,洛谷上可提交 洛谷上的奇葩翻译不要看,很多条件缺漏 题意简述:给定一棵树,每条边权为1,给定所有点点权,每条边仅能走两次,求以一定顺序遍历整棵树后,使所有点中的到达时间 ...

  10. 通过flask实现web页面简单的增删改查bootstrap美化版

    通过flask实现web页面简单的增删改查bootstrap美化版 项目目录结构 [root@node1 python]# tree -L 2 . ├── animate.css ├── fileut ...