require

webpack4.x 使用

ぐ巨炮叔叔 提交于 2019-11-29 12:35:16
webpack4.x webpack 模块打包工具,分析项目结构,找到js模块及一些浏览器不能运行的语言如ES6/sass等,并将其转换和打包为何时的格式供浏览器使用; 打包:将多个js文件打包成一个文件,减少服务器压力和下载带宽; 转换:把浏览器不能识别的语言转换为js,让浏览器能够正确识别 优化:优化项目,提高性能 安装 // 新建项目文件夹,并进入 mkdir webpack_demo cd webpack_demo //全局安装 npm install -g webpack // 全局安装后还需进行一个项目目录的安装,npm安装之前先进行初始化,目的-生成package.json文件(包括当前项目依赖模块,自定义脚本任务等) npm n init // 项目目录的安装 --save-dev保存到package.json中且在dev开发中使用,生产环境中不使用; npm install --save-dev webpack // 查看webpack版本 webpack -v // ps:查看webpack版本时会提示安装webpack-cli,因为此时安装的webpack版本是4.x;webpack 已经将 webpack 命令行相关的内容都迁移到 webpack-cli,所以除了 webpack 外,还需要安装 webpack-cli npm install --save

PHP - retrieve name of script that included or required it

拟墨画扇 提交于 2019-11-29 12:18:27
How do you retrieve the name of the script that included or required it? Example: script login.php has a require_once('validate.php') ... validate.php is also called by a number of other scripts. Other than manually setting a flag, is there a way to have validate.php know which script is including/requiring it? Try $_SERVER['SCRIPT_NAME']; More here: http://php.net/manual/en/reserved.variables.server.php 来源: https://stackoverflow.com/questions/3278757/php-retrieve-name-of-script-that-included-or-required-it

React应用渲染界面的入口

天涯浪子 提交于 2019-11-29 11:45:34
jsx代码: var React = require ( 'react' ) ; var ReactDOM = require ( 'react-dom' ) ; var MyButtonController = require ( './components/MyButtonController' ) ; ReactDOM . render ( < MyButtonController / > , document . querySelector ( '#example' ) ) ; 转换成对应的原生JavaScript代码: 要获取更多Jerry的原创文章,请关注公众号"汪子熙": 来源: https://blog.csdn.net/i042416/article/details/100803019

基于rollup打包组件实战

房东的猫 提交于 2019-11-29 10:15:41
前言 最近做项目,发现有很多可抽离出来的组件,以前开发组件是用gulp和webpack搭建的脚手架,需要配置一堆 loader 之类的东西,配置完成后,编译出来的代码不仅可读性差,而且代码体积偏大。因此想找寻新的编译工具,最后发现 vue.js , react.js 等流行库都用了 rollup.js 来编译代码,而且 rollup.js 可以编译输出各种模块规范的代码 AMD、Commonjs、UMD、IIFE 。所以也入门 rollup.js 。 rollup介绍 官方描述 Rollup 是一个 JavaScript 模块打包器,可以将小块代码编译成大块复杂的代码,例如 library 或应用程序。Rollup 对代码模块使用新的标准化格式,这些标准都包含在 JavaScript 的 ES6 版本中,而不是以前的特殊解决方案,如 CommonJS 和 AMD。ES6 模块可以使你自由、无缝地使用你最喜爱的 library 中那些最有用独立函数,而你的项目不必携带其他未使用的代码。ES6 模块最终还是要由浏览器原生实现,但当前 Rollup 可以使你提前体验。 rollupjs官网 1、配置文件 1、安装对应的包 // rollup编译的核心模块 npm install rollup -D // rollup的ES6编译插件 npm install rollup-plugin

Apache2.4服务器权限设置问题

喜你入骨 提交于 2019-11-29 08:11:34
Apache 从2.2升级到 Apache2.4.x 后配置文件 httpd.conf 的设置方法有了大变化,以前是将 deny from all 全部改成 Allow from all 实现外网访问,现在是将 Require all denied 以及 Require local 都该为 Require all granted 就可以了。 .htaccess 如果不起作用将 LoadModule rewrite_module modules/mod_rewrite.so 前面的注释(#)去掉就可以了。 下面看一下 Apache2.4 的变化:( 官方英文说明 ) 所有的请求都被拒绝 2.2上的配置 Order deny,allow Deny from all 2.4上的配置 Require all denied 所有请求都是允许的 2.2上的配置 Order allow,deny Allow from all 2.4上的配置 Require all granted 在域中的所有主机都可以访问example,所有其他外网主机的访问被拒绝 2.2上的配置 Order Deny,Allow Deny from all Allow from example.org 2.4上的配置 Require host example.org 要想外网访问将 Require local 该为

04 Node.js学习之模块的加载

早过忘川 提交于 2019-11-29 07:54:10
A文件代码: //1、require是一个方法,它的作用就是用来加载模块的 console.log("执行 B ") require('./b.js'); console.log("执行 C ") require('./c');//这里的JS后缀名是可以省略的 //2、在Node中,没有全局作用域,只有模块作用域 //2.1外部访问不到内部 //2.2内部也访问不到外部 var cc=require('./c'); //这样是获取不到C文件下的CC变量的 // console.log(cc.cc); //3、require方法有两个作用 //3.1、加载文件模块并执行里面的代码 //3.2、拿到被加载文件模块导出的对接独享 var ex=require('./b'); //将会执行B文件下Add方法 console.log(ex.add(30,20)); //获取B文件的foo变量值 console.log(ex.foo); B文件代码 console.log("B文件执行了"); var foo="bbb"; exports.foo=foo; exports.add=function (x,y) { return x*y; } C文件代码 console.log("C文件执行了"); var cc="我是C文件" 来源: https://www.cnblogs.com

Ruby: how to “require” a file from the current working dir?

…衆ロ難τιáo~ 提交于 2019-11-29 06:17:49
问题 How do I require a file from the current folder? I have a file called sql_parser.rb that contains a class. I want to include this in another file also in the same folder, so I used: require 'sql_parser' That fails when I run from that folder: LoadError: no such file to load -- sql_parser I tried using IRB in the folder where this file exists and requiring it from there, but had the same issue. 回答1: In ruby 1.9.x, you can use the method require_relative . See http://www.ruby-doc.org/core-1.9.3

雷林鹏分享Node.js Express 框架

蹲街弑〆低调 提交于 2019-11-29 06:17:20
  Express 简介   Express 是一个简洁而灵活的 node.js Web应用框架, 提供了一系列强大特性帮助你创建各种 Web 应用,和丰富的 HTTP 工具。   使用 Express 可以快速地搭建一个完整功能的网站。   Express 框架核心特性:   可以设置中间件来响应 HTTP 请求。   定义了路由表用于执行不同的 HTTP 请求动作。   可以通过向模板传递参数来动态渲染 HTML 页面。   安装 Express   安装 Express 并将其保存到依赖列表中:   $ cnpm install express --save   以上命令会将 Express 框架安装在当前目录的 node_modules 目录中, node_modules 目录下会自动创建 express 目录。以下几个重要的模块是需要与 express 框架一起安装的:   body-parser - node.js 中间件,用于处理 JSON, Raw, Text 和 URL 编码的数据。   cookie-parser - 这就是一个解析Cookie的工具。通过req.cookies可以取到传过来的cookie,并把它们转成对象。   multer - node.js 中间件,用于处理 enctype="multipart/form-data"(设置表单的MIME编码

webpack4基础知识点(二)

不打扰是莪最后的温柔 提交于 2019-11-29 05:50:25
1.解析css,less,sass 先下载依赖包 //解析css npm i style - loader css - loader - D //解析less npm i less less - loader - D //解析sass npm i sass sass - loader - D module . exports = { module : { rules : [ { test / \ . css$ / , use : [ 'style-loader' , //因为loader是链式从右向左调用,因此顺序千万不能错,先使用css-loader再使用style-loader 'css-loader' ] } , { test : /\.less$ / , use : [ 'style-loader' , //因为loader是链式从右向左调用,因此顺序千万不能错,先使用css-loader再使用style-loader 'css-loader' , 'less-loader' ] } , { test : /\.sass$ / , use : [ 'style-loader' , //因为loader是链式从右向左调用,因此顺序千万不能错,先使用css-loader再使用style-loader 'css-loader' , 'sass-loader' ] } , ] }

PHP include/require inside functions

我怕爱的太早我们不能终老 提交于 2019-11-29 05:45:22
Having functions that are quite big and they are loading every time the page is loaded, would be better to write function foo(){ include(.../file_with_function's_code); return; } to minimize the size of the functions script? Or it doesn't matter because when a function is loaded (but not executed) also is loaded the content even if it is into an include? Thank you. (Edit: my question is not about if it's possible or not) While @Luceos answer is technically correct (the best kind of correct), it does not answer the question you asked, namely is doing this better, or do includes happen