require

React require(“history”).createBrowserHistory` instead of `require(“history/createBrowserHistory”)

社会主义新天地 提交于 2019-11-28 22:36:25
看见bug惊讶,代码中并没有require(“history/createBrowserHistory”) //原有代码为 import createBrowserHistory from "history/createBrowserHistory"; const customHistory = createBrowserHistory(); bug解决方式为 import {createBrowserHistory} from 'history' const customHistory = createBrowserHistory(); 本文借鉴自: https://stackoverflow.com/questions/55466802/react-requirehistory-createbrowserhistory-instead-of-requirehistory-crea 来源: https://www.cnblogs.com/smart-girl/p/11427746.html

babel填坑笔记

核能气质少年 提交于 2019-11-28 22:10:18
cnpm install --save-dev @babel/core //安装//用npm安装一直报错,改用cnpm安装就可以了 创建一个.babelre文件并配置 { "presets": [    "@babel/env"     ], "plugins": [] } cnpm install --save-dev @babel/preset-env //安装 避免报错 统一用cnpm//安装@babel/register 模块 可以使用imort的方式导入模块cnpm install --save-dev @babel/register // main.js require('@babel/register'); require('./app.js'); 来源: https://www.cnblogs.com/flyerya/p/11429080.html

vue-cli中引入jquery的相关配置

大兔子大兔子 提交于 2019-11-28 21:47:16
一:在我们的vue项目中安装好jquery后,一般在脚手架中会自动引入,接着我们在main.js文件中引入即可,接下来就是该我们进行配置的时候了,首先在我们的项目目录汇总打开webpack.base.conf.js文件,开始顶部是这样的 紧接着再代码块中加上一句: var path = require('path') var utils = require('./utils') var webpack = require("webpack") //新添加的 var config = require('../config') var vueLoaderConfig = require('./vue-loader.conf') 然后还是在webpack.base.conf.js文件中修改下面的module.exports部分 plugins: [ new webpack.optimize.CommonsChunkPlugin('common.js'), new webpack.ProvidePlugin({ jQuery: "jquery", $: "jquery" }) ], 最后,重启项目即可! 来源: https://blog.csdn.net/WebDestiny/article/details/100121054

require file as string

北城余情 提交于 2019-11-28 20:59:18
I'm using node + express and I am just wondering how I can import any file as a string. Lets say I have a txt file all I want is to load it into a variable as such. var string = require("words.txt"); I am against modules.exports = function(){ var string = "whatever"; return string; } If it's for a (few) specific extension(s), you can add your own require.extensions handler: var fs = require('fs'); require.extensions['.txt'] = function (module, filename) { module.exports = fs.readFileSync(filename, 'utf8'); }; var words = require("./words.txt"); console.log(typeof words); // string Otherwise,

How to catch error of require() or include() in PHP?

谁说我不能喝 提交于 2019-11-28 20:39:31
I'm writing a script in PHP5 that requires the code of certain files. When A file is not available for inclusion, first a warning and then a fatal error are thrown. I'd like to print an own error message, when it was not possible to include the code. Is it possible to execute one last command, if requeire did not work? the following did not work: require('fileERROR.php5') or die("Unable to load configuration file."); Supressing all error messages using error_reporting(0) only gives a white screen, not using error_reporting gives the PHP-Errors, which I don't want to show. Sjan Evardsson You

webpack多页面配置

自闭症网瘾萝莉.ら 提交于 2019-11-28 19:28:16
项目目录结构如下: config文件夹内代码如下:   index.js:    module.exports = { dev: { assetsSubDirectory: 'static', assetsPublicPath: '', devtool: 'cheap-module-eval-source-map', proxy: { '/api': { target: 'http://localhost:8888', changeOrigin: true, pathRewrite: { '^/api': '/api' } } }, // host: 'localhost', host:'0.0.0.0', port: 8888 }, prod: { assetsSubDirectory: 'static', assetsPublicPath: './', devtool: 'source-map' }, templatePc(data) { //PC sprite template return data.sprites.map(sprite => { return ( `.icon-${sprite.name} { width: ${sprite.px.width}; height: ${sprite.px.height}; background: url(${sprite

Is there a shorter way to require a file in the same directory in ruby?

纵饮孤独 提交于 2019-11-28 19:04:31
Is there a shorter way to require a file located in the same directory (as the script being executed)? require File.expand_path(File.dirname(__FILE__) + '/some_other_script') I read that require "my_script" and require "./my_script" will actually load the script twice (ruby will not recognize that it is actually the same script), and this is the reason why File.expand_path is recommended: if it is used every time the script is required, then it will only be loaded once. It seems weird to me that a concise language like Ruby does not seem to have a shorter solution. For example, python simply

AST 抽象语法树

点点圈 提交于 2019-11-28 17:52:15
提起 AST 抽象语法树,大家可能并不感冒。但是提到它的使用场景,也许会让你大吃一惊。原来它一直在你左右与你相伴,而你却不知。 一、什么是抽象语法树 在计算机科学中,抽象语法树( abstract syntax tree 或者缩写为 AST ),或者语法树( syntax tree ),是源代码的抽象语法结构的树状表现形式,这里特指编程语言的源代码。树上的每个节点都表示源代码中的一种结构。 之所以说语法是「抽象」的,是因为这里的语法并不会表示出真实语法中出现的每个细节。 二、使用场景 JS 反编译,语法解析 Babel 编译 ES6 语法 代码高亮 关键字匹配 作用域判断 代码压缩 三、AST Explorer 我们来看一个 ES6 的解释器,声明如下的代码: 1 let tips = [ 2 "Jartto's AST Demo" 3 ]; 看看是如何解析的, JSON 格式如下: 1 { 2 "type": "Program", 3 "start": 0, 4 "end": 38, 5 "body": [ 6 { 7 "type": "VariableDeclaration", 8 "start": 0, 9 "end": 37, 10 "declarations": [ 11 { 12 "type": "VariableDeclarator", 13 "start": 4,

Load Lua-files by relative path

馋奶兔 提交于 2019-11-28 17:26:49
问题 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

NodeJS基础学习总结

你说的曾经没有我的故事 提交于 2019-11-28 16:30:14
一、nodeJS解释   JS是脚本语言,脚本语言都需要一个解析器才能运行。对于写在HTML页面里的JS,浏览器充当了解析器的角色。而对于需要独立运行的JS,NodeJS就是一个解析器。    每一种解析器都是一个运行环境,不但允许JS定义各种数据结构,进行各种计算,还允许JS使用运行环境提供的内置对象和方法做一些事情 。例如运行在浏览器中的JS的用途是操作DOM, 浏览器就提供了 document 之类的内置对象 。而运行在NodeJS中的JS的用途是操作磁盘文件或搭建HTTP服务器, NodeJS就相应提供了 fs 、 http 等内置对象 。   尽管存在一听说可以直接运行JS文件就觉得很酷的同学,但大多数同学在接触新东西时首先关心的是有啥用处,以及能带来啥价值。   NodeJS的作者说,他创造 NodeJS的目的是为了 实现高性能Web服务器 ,他 首先看重的是事件机制和异步IO模型的优越性 ,而不是JS。但是他需要选择一种编程语言实现他的想法,这种编程语言不能自带IO功能,并且需要能良好支持事件机制。JS没有自带IO功能,天生就用于处理浏览器中的DOM事件,并且拥有一大群程序员,因此就成为了天然的选择。   如他所愿,NodeJS在服务端活跃起来,出现了大批基于NodeJS的Web服务。而另一方面,NodeJS让前端众如获神器,终于可以让自己的能力覆盖范围跳出浏览器窗口