文章目录
Q1解决 webpack-dev-server 不能使用 IP 访问
your-project/package.json
添加参数 --host 0,0,0,0
"dev": "webpack-dev-server --inline --host 0.0.0.0 --progress --config build/webpack.dev.conf.js"
Q2 Module not found: Error: Can’t resolve ‘util’ in webpack
https://stackoverflow.com/questions/64402821/module-not-found-error-cant-resolve-util-in-webpack
function getBrowserConfig(wco) {
return {
devtool: false,
resolve: {
mainFields: ['es2015', 'browser', 'module', 'main'],
fallback: { //added this line
dgram: false, //added this line
fs: false, //added this line
net: false, //added this line
tls: false, //added this line
util: false, //added this line
https: false, //added this line
crypto: false, //added this line
assert: false, //added this line
stream: false, //added this line
http: false, //added this line
zlib : false, //added this line
path: false //added this line
} //added this line
},
node: false,
};
}
Q3 Marked is not a function
https://stackoverflow.com/questions/70645855/marked-is-not-a-function
import { marked } from 'marked'
或者
const { marked } = require("marked");
Q4 console计算代码运行时间
参考自:https://blog.csdn.net/qq_30100043/article/details/77509087
使用console.log配合Date对象计算
var arr = [];
for(var i=0; i<100000; i++){
arr.push(Math.random());
}
var beginTime = +new Date();
arr.sort();
var endTime = +new Date();
console.log("排序用时共计"+(endTime-beginTime)+"ms");
使用console.time进行时间计算,这种方法比上一种更准确,而且专门为性能产生的方法:
var arr = [];
for(var i=0; i<100000; i++){
arr.push(Math.random());
}
console.time("sort");
arr.sort();
console.timeEnd("sort");
Q5 Using Node.JS, how do I read a JSON file into (server) memory?
参考自:https://stackoverflow.com/questions/10011011/using-node-js-how-do-i-read-a-json-file-into-server-memory
Sync:
var fs = require('fs');
var obj = JSON.parse(fs.readFileSync('file', 'utf8'));
Async:
var fs = require('fs');
var obj;
fs.readFile('file', 'utf8', function (err, data) {
if (err) throw err;
obj = JSON.parse(data);
});