https://www.webpackjs.com/guides/asset-management/
ERROR in ./src/data.yaml
Module parse failed: Cannot parse JSON: Unable to parse.
跟着官网一步步撸还是有问题,看不懂是哪里出了错。
webpack.config.js
const { type } = require('os');
const path = require('path');
const toml = require('toml');
const yaml = require('yamljs');
const json5 = require('json5');
// const { Parser } = require('webpack');
module.exports = {
entry:'./src/index.js',
output: {
filename:'bundle.js',
path:path.resolve(__dirname,'dist'),
},
module:{
rules:[
{
test:/\.css$/i,
use:['style-loader','css-loader']
},
{
test:/\.(png|svg|jpg|jpeg|gif)$/i,
type:'asset/resource',
},
{
test:/\.(woff|woff2|eot|ttf|otf)$/i,
type:'asset/resource',
},
{
test:/\.(csv|tsv)$/i,
use:['csv-loader'],
},
{
test:/\.xml$/i,
use:['xml-loader'],
},
{
test: /\.toml$/i,
type: 'json',
parser: {
parse: toml.parse,
},
},
{
test: /\.yaml$/i,
type: 'json',
parser: {
parse: yaml.parse,
},
},
{
test: /\.json5$/i,
type: 'json',
parser: {
parse: json5.parse,
},
},
]
}
}
data.toml
title = "TOML Example"
[owner]
name = "Tom Preston-Werner"
organization = "GitHub
bio = "GitHub Cofounder & CEO\nLikes tater tots and beer."
dob = 1979-05-27T07:32:00Z
data.yaml
title:YAML Example
owner:
name:Tom Preston-Werner
organization:GitHub
bio:|-
Github Cofounder & CEO
Likes tater tots and beer.
dob:1979-05-27T07:32:00:000Z
data.json5
{
//coment
title:'JSON5 Example',
owner:{
name:'Tom Preston-Werner',
organization:'GitHub',
bio:'GitHub Cofounder & CEO \n\ Liles tater tots and beer.',
dob:'1979-05-27T07:32:00.000Z',
},
}
index.js
import _ from 'lodash';
import './style.css';
import Icon from './1.jpg';
import Data from './data.xml';
import Notes from './data.csv';
import toml from './data.toml';
import yaml from './data.yaml';
import json from './data.json5';
console.log(toml.title);
console.log(toml.owner.name);
console.log(yaml.title);
console.log(yaml.owner.name);
console.log(json.title);
console.log(json.owner.name);
function component() {
const element = document.createElement('div');
// 执行这一行需要引入loadsh (目前通过 script 脚本引入)
// lodash 现在使用import引入
element.innerHTML = _.join(['Hello','Webpack'],' ');
element.classList.add('hello')
// 将图像添加到已经存在的div中
const myIcon = new Image();
myIcon.src = Icon;
element.appendChild(myIcon);
console.log(Data);
console.log(Notes);
return element;
}
document.body.appendChild(component());
package.json
{
"name": "webpack",
"version": "1.0.0",
"private": true,
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "webpack"
},
"keywords": [],
"author": "",
"license": "ISC",
"description": "",
"devDependencies": {
"css-loader": "^7.1.2",
"csv-loader": "^3.0.5",
"json5": "^2.2.3",
"style-loader": "^4.0.0",
"toml": "^3.0.0",
"webpack": "^5.96.1",
"webpack-cli": "^5.1.4",
"xml-loader": "^1.2.1",
"yamljs": "^0.3.0"
},
"dependencies": {
"lodash": "^4.17.21"
}
}
第一个error是因为data.toml 中organization 的值缺少引号
第二个error 是因为data.yaml 中 冒号(:)之后没有空格导致的
C# CS1061是什么原因? 我写了一个函数模板 我编写此模版方法后尝试传入structT调用中,我确保我的structT中绝对含有name字段,但是编译依然报错: error:CS1061,T未包含name的定义,并且找不到可接受第一个"T"类型参数的可访问方法"name"(是否缺少using指令或程序集引用) 而后我注释了调用部分,即没有任何地方调用我的Test<T>(ref T struc
找不到init? 那起的函数名有什么用?
找不到init? 那起的函数名有什么用?
1,问题背景: 使用audio标签进行aac音频文件的播放,播放报错,获取音频文件错误。 有没有大佬遇到过,感谢!!! 具体报错信息:
最近公司需要把前端打包后的代码上传到oss,我在想这么做的优势是啥,难道不比服务器访问要方便吗?
webpack版本为最新5.88 如图,在加入这段代码后,运行npm run build报错 报错问题 完整代码 在使用了大佬提供的代码后,成功压缩了图片,但是出现了新的报错问题 目前代码
webpack1.0 直接升到 webpack5.0 各种依赖冲突,已经根据报错提示一个一个慢慢升级完了。在1.0的时候虽然很慢,但是能运行起来的,所以业务逻辑代码肯定是没问题么也动过。 现在升级完依赖,改完webpack配置 npm run start 项目启动报错如下: 根据chatGPT 和 文心一言的就解答就是“多个 chunk 尝试输出到相同的文件名” 造成的。如图: 在webpack配