如果无效/不必要,你怎么告诉webpack忽略package.json的main
属性?
这是一个例子:GitHub的octicons包有一个mainme的readme.md:
{
"name": "octicons",
"version": "3.5.0",
"description": "GitHub's icon font",
"main": "README.md", <-------------------------------------
"repository": {
"type": "git",
"url": "https://github.com/github/octicons.git"
},
...
}
https://github.com/github/octicons/blob/master/package.json#L5
导致此错误:
ERROR in ./~/octicons/README.md
Module parse failed: C:\repos\foo\node_modules\octicons\README.md Unexpected character '#' (1:0)
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected character '#' (1:0)
at Parser.pp.raise (C:\repos\foo\node_modules\acorn\dist\acorn.js:920:13)
at Parser.pp.getTokenFromCode (C:\repos\foo\node_modules\acorn\dist\acorn.js:2813:8)
at Parser.pp.readToken (C:\repos\foo\node_modules\acorn\dist\acorn.js:2508:15)
at Parser.pp.nextToken (C:\repos\foo\node_modules\acorn\dist\acorn.js:2500:71)
at Parser.parse (C:\repos\foo\node_modules\acorn\dist\acorn.js:1615:10)
at Object.parse (C:\repos\foo\node_modules\acorn\dist\acorn.js:882:44)
at Parser.parse (C:\repos\foo\node_modules\webpack\lib\Parser.js:902:15)
at DependenciesBlock.<anonymous> (C:\repos\foo\node_modules\webpack\lib\NormalModule.js:104:16)
at DependenciesBlock.onModuleBuild (C:\repos\foo\node_modules\webpack-core\lib\NormalModuleMixin.js:31
0:10)
at nextLoader (C:\repos\foo\node_modules\webpack-core\lib\NormalModuleMixin.js:275:25)
@ ./src ^\.\/.*$
octicons包仅在一个地点引用 - 我的main.js(入口点):
import '../node_modules/octicons/octicons/octicons.css';
答案 0 :(得分:4)
我不确定这是否是正确的解决方案,但它让我超越了错误。如果有人发布了更好的解决方案,我很乐意接受并投票。
安装null-loader:npm install --save null-loader
将所有.md
个文件发送到空加载器:
<强> webpack.config 强>
...
module: {
loaders: [
...
{ test: /\.md$/, loader: 'null' }
]
},
...