Javascript React、webpack和Wavesurfer.js
我试图使用npmJavascript React、webpack和Wavesurfer.js,javascript,reactjs,webpack,create-react-app,wavesurfer.js,Javascript,Reactjs,Webpack,Create React App,Wavesurfer.js,我试图使用npmreact wavesurfer软件包,但出现了错误 this._wavesurfer.init is not a function 这似乎是因为wavesurfer未正确设置。github上的页面声明“WaveSurfer需要是一个全局可访问变量。” 我的react项目是使用create react app创建的,因此我没有网页包配置文件如何包含这些wavesurfer插件? 注意:询问同样的问题,但唯一的答案是直接使用非react,wavesurfer.js包。我更喜欢使用
react wavesurfer
软件包,但出现了错误
this._wavesurfer.init is not a function
这似乎是因为wavesurfer未正确设置。github上的页面声明“WaveSurfer需要是一个全局可访问变量。”
我的react项目是使用create react app
创建的,因此我没有网页包配置文件如何包含这些wavesurfer插件?
注意:询问同样的问题,但唯一的答案是直接使用非react,
wavesurfer.js
包。我更喜欢使用react wavesurfer
看起来你需要添加自定义webpack.config.js
参数,我认为你不能在create react app
中立即添加这些参数。如果你在谷歌上搜索,你可以使用一些工具来解决这个问题,但一个更简单的方法可能是下载你需要的相关wavesurfer.js
文件,并将它们包含在你index.html
的
中,因此它们都是在你实际加载应用程序之前加载的,因此可以在全球范围内使用,自从react wavesurfer
不再受支持以来,似乎已经有了一系列的变化和新版本,因此使用非react wavesurfer可能不是一个坏主意
// provide WaveSurfer as a globally accessible variable
plugins: [
new webpack.ProvidePlugin({
WaveSurfer: 'wavesurfer.js'
})
],
// Alias `wavesurfer` to the correct wavesurfer package.
// (wavesurfer.js has some non-standard naming convention)
resolve: {
alias: {
wavesurfer: require.resolve('wavesurfer.js')
}
},