我正在尝试构建一个扩展了Quill编辑器并将其与我的项目集成的模块。通过Webpack导入节点模块时出错,“您可能需要一个合适的加载程序来处理这种文件类型”
当我尝试我的自定义奎尔模块中导入特定奎尔模块的WebPack抛出一个错误:
Uncaught Error: Cannot find module "quill/core/quill"
at webpackMissingModule (QuillLinkTooltip.js:15)
at eval (QuillLinkTooltip.js:15)
再后来就:
./~/quill/core/quill.js
Module parse failed: /Users/path_to_my_app_folder/node_modules/quill/core/quill.js Line 1: Unexpected token
You may need an appropriate loader to handle this file type.
| import './polyfill';
| import Delta from 'quill-delta';
| import Editor from './editor';
下面是从自定义奎尔模块的摘录(QuillLinkTooltip.js
)我正在建设并抛出错误:
import Quill from 'quill/core/quill';
import { Range } from 'quill/core/selection';
import Keyboard from 'quill/modules/keyboard';
import LinkBlot from 'quill/formats/link';
import Tooltip from 'quill/ui/tooltip';
我在我的项目中使用了Webpack,babel和babel es2015预设。我可以通过使用诸如import get from 'lodash/get';
之类的东西导入其他节点模块,如lodash。
我怀疑webpack可以找到模块,但是在解析它时遇到困难。这是我的webpack.config.js文件的摘录:
module: {
loaders: [
{
test: /.*\.js$/,
loader: 'babel-loader',
exclude: [ /node_modules/, /frontend/ ],
query: {
presets: [ 'babel-preset-es2015' ].map(require.resolve),
plugins: [ 'babel-plugin-add-module-exports' ].map(require.resolve)
}
},
我读过https://quilljs.com/guides/adding-quill-to-your-build-pipeline/其中提到Webback,巴贝尔和巴贝尔ES2015预设的需要,这样看来我有正确的WebPack设置。但也许我错过了什么?