require

webpack 入门三

不羁的心 提交于 2019-11-30 01:15:32
webpack各种优化 上一章节我们已经掌握了webpack常见的所有配置 这一节我们来看看如何实现webpack中的优化,我们先来编写最基本的webpack配置,然后依次实现各种优化! const MiniCssExtractPlugin = require("mini-css-extract-plugin"); const HtmlWebpackPlugin = require("html-webpack-plugin"); const path = require("path"); module.exports = mode => { return { mode: mode, entry: "./src/main.js", output: { filename: "bundle.js", path: path.resolve(__dirname, "dist") }, module: { rules: [ { test: /\.(png|jpg|gif)$/, use: "file-loader" }, { test: /\.js$/, use: "babel-loader" // .babelrc已经配置支持react }, { test: /\.css$/, use: [ mode !== "development" ? MiniCssExtractPlugin

requireJS学习笔记

一曲冷凌霜 提交于 2019-11-30 00:54:50
一、为什么要使用require.js? 1、在大型项目中,往往一个页面需要加载很多个js文件,而页面加载的时候,浏览器会停止网页渲染,因此加载文件越多,导致网页失去响应的时间就会越长; 2、其次,由于js文件之间存在依赖关系,因此必须严格保证加载顺序(比如上例的1.js要在2.js的前面),依赖性最大的模块一定要放到最后加载,当依赖关系很复杂的时候,代码的编写和维护都会变得困难。 所以,在开发大型Javascript应用程序的时候,就必须引入模块化机制。关于前端模块化的前世今生,可以参考此博客: https://www.cnblogs.com/scq000/p/10647128.html 二、require.js能干什么? 1、 RequireJS 是遵循AMD规范的模块化工具, 在导入模块的时候,会先加载对应的依赖模块,然后再执行接下来的代码,同时AMD模块可以并行加载所有依赖模块,从而很好地提高页面加载性能: 2、管理模块之间的依赖性,便于代码的编写和维护。 RequireJS的基本思想是,通过define方法,将代码定义为模块;通过require方法,实现代码的模块加载。 三、require.js的加载: <script src="js/require.js"></script> 引用js的过程,为了避免网页失去响应,我们可以将代码卸载网页底部进行加载,也可以采用异步加载

In Node.js, am I creating a new object when “Require”?

醉酒当歌 提交于 2019-11-30 00:05:21
So, what I'm not sure is that. if in ModuleA , I have: var mongoose = require('mongoose'); mongoose.connect(pathA); And in ModuleB , I have: var mongoose = require('mongoose'); mongoose.connect(pathB); And in the main program, I have: var mA = require('./moduleA.js'), mB = require('./moduleB.js'); So, when I run the main program, I guess I will create two mongoose "instances"; one connecting to pathA and one connecting to pathB, is that right? Also, in Module B, before I connect to pathB, is it connected to pathA or nothing? Thanks. murvinlai I just did a couple of tests with the latest node

wampserver环境配置局域网访问

本秂侑毒 提交于 2019-11-29 23:36:39
安装好wamp后,想用手机通过局域访问电脑上wamp下的网页,结果出现如下提示403错误: 第一步:找到 conf 这个文件 : 找到下图中红色方框中的onlineoffline tag - don’t remove,将原来的Require local替换为Require all granted; 注意几种常用格式,自己可以灵活配置: Require local 仅允许本地访问; Require all denied 拒绝所有访问; Require all granted 允许所有访问; Require ip 192.168.0.1 仅允许IP:192.168.0.1 访问; Require not ip 192.168.0.1 仅禁止IP:192.168.0.1访问; 修改为 :Require all granted(允许所有) 注意这里改的只是apche的全局配置,一般来说,这个配置是正对所有的,也就是权重等级是最低,所以还需要修改一个位置: 第二步:找到 httpd-vhosts.conf 这个文件 : 还需要修改这个: 这里可以: Require local #允许本地访问 Require ip 192.168.1 #允许本地访问 或者: Require local Require ip 192.168.1.100 Require ip 192.168.1.101 到此

Node.js - check if module is installed without actually requiring it [duplicate]

↘锁芯ラ 提交于 2019-11-29 23:34:02
This question already has an answer here: Check if a node.js module is available 5 answers I need to check whether "mocha" is installed, before running it. I came up with the following code: try { var mocha = require("mocha"); } catch(e) { console.error(e.message); console.error("Mocha is probably not found. Try running `npm install mocha`."); process.exit(e.code); } I dont like the idea to catch an exception. Is there a better way? user568109 You should use require.resolve() instead of require() . require will load the library if found, but require.resolve() will not, it will return the file

小米商品和腾讯招聘多线程爬取

风流意气都作罢 提交于 2019-11-29 22:00:27
该博文转载自:https://www.cnblogs.com/LXP-Never/p/11378709.html 目录   小米应用商店抓取(多线程)   腾讯招聘数据抓取(Ajax) 应用场景 1、多进程 :CPU密集程序 2、多线程 :爬虫(网络I/O)、本地磁盘I/O 知识点回顾 队列 # 导入模块 from queue import Queue # 使用 q = Queue() q.put(url) q.get() # 当队列为空时,阻塞 q.empty() # 判断队列是否为空,True/False 线程模块 # 导入模块 from threading import Thread ​ # 使用流程 t = Thread(target=函数名) # 创建线程对象 t.start() # 创建并启动线程 t.join() # 阻塞等待回收线程 小米应用商店抓取(多线程) 目标 网址 :百度搜 - 小米应用商店,进入官网,应用分类 - 聊天社交 目标 :爬取应用名称和应用链接 实现步骤 1、确认是否为动态加载 1、页面局部刷新 2、右键查看网页源代码,搜索关键字未搜到,因此此网站为动态加载网站,需要抓取网络数据包分析 2、F12抓取网络数据包 1、抓取返回json数据的URL地址(Headers中的Request URL) http://app.mi.com

Load Lua-files by relative path

只谈情不闲聊 提交于 2019-11-29 21:22:11
If I have a file structure like this: ./main.lua ./mylib/mylib.lua ./mylib/mylib-utils.lua ./mylib/mylib-helpers.lua ./mylib/mylib-other-stuff.lua From main.lua the file mylib.lua can be loaded with full path require('mylib.mylib') . But inside mylib.lua I would also like to load other necessary modules and I don't feel like always specifying the full path (e.g. mylib.mylib-utils ). If I ever decide to move the folder I'm going to have a lot of search and replace. Is there a way to use just the relative part of the path? UPD. I'm using Lua with Corona SDK, if that matters. There is a way of

When is RequireJS' require call asynchronous? When is it synchronous?

ぃ、小莉子 提交于 2019-11-29 20:21:14
问题 I use RequireJS to load my modules in one of my projects. I see around the web different ways to require modules using the require call (and not define ). Lets assume I have a module named "JQuery" and I would like to require it. Two ways are possible as I saw in examples: This: require(["JQuery"], function($){ $.doSomething(); }) And this: var $ = require("JQuery"); $.doSomething(); My question is if the load is async as RequireJS documantation says it is, how can the second convention work?

Is require File.expand_path(…, __FILE__) the best practice?

痞子三分冷 提交于 2019-11-29 20:20:22
Is require File.expand_path(..., __FILE__) the best way to require other files within a project? the Tin Man In Ruby 1.9.2 + require_relative is probably the more correct way to do it. require was changed to not include your '.' directory for security reasons. require_relative was added to provide a local-file solution for modules relative to your calling script's path. You can search here on StackOverflow , particularly in " What is require_relative in Ruby? ", and the internets and find usage tricks and the why-for messages explaining how it came about. Steve Benner In Ruby 2.x you can use

require()  module.export    Object.keys()

落爺英雄遲暮 提交于 2019-11-29 19:41:58
import API from"../../api/api.js"; var data = require('../../utils/data.js').songs; //代码导出 //require 用来加载代码,而 exports 和 module.exports 则用来导出代码 module.exports = { songs : songs } 语法 Object.keys(object) 参数 Object : 必需。包含属性和方法的对象。这可以是您创建的对象或现有文档对象模型 (DOM) 对象 返回值: 一个数组,其中包含对象的可枚举属性和方法的名称。 keys 方法仅返回可枚举属性和方法的名称。若要返回可枚举的和不可枚举的属性和方法的名称, module.exports = { getFavList: function (){ var favList = []; var data = wx.getStorageSync('favlist'); Object.keys(data).forEach(function(key){ favList.push({ picurl:data[key].picurl, name:key, count: data[key].list.length }); }); return favList; } } var Api = { //API