javascript - 使用react-app-rewired将webpack配置添加到react-create-app

标签 javascript reactjs webpack yarnpkg wavesurfer.js

警告:我是新手。

我正在开发一个通过 yarn 使用react-create-app的react应用程序。

我正在尝试使用这些说明安装react-wavesurfer https://github.com/mspae/react-wavesurfer#prerequisites-and-common-pitfalls

我需要以某种方式将 Wavesurfer.js 引入应用程序。这些说明包括对 webpack 配置进行更改,我试图避免弹出这些配置。

我发现了这个react-app-rewired和这篇文章https://jaketrent.com/post/change-webpack-config-create-react-app-without-ejecting/

所以我将其添加到 config-overrides.js

const rewireProvidePlugin = require('react-app-rewire-provide-plugin')

// Use `webpack.ProvidePlugin` to add jQuery globally


module.exports = function override(config, env) {
  // add a plugin
  config = rewireProvidePlugin(config, env, {
    'WaveSurfer': 'wavesurfer.js',
  })

    resolve: {
        alias: {
            wavesurfer: require.resolve('wavesurfer.js')
        }
    }

  return config
}

哪个构建,但我仍然无法在具有这些导入的页面中访问wavesurfer

import React, {Component} from 'react'
import history from '../../../history'
import Wavesurfer from 'react-wavesurfer'

import * as _ from 'lodash'

require('wavesurfer.js')
require('wavesurfer.js/dist/plugin/wavesurfer.timeline.min.js')
require('wavesurfer.js/dist/plugin/wavesurfer.regions.min.js')
require('wavesurfer.js/dist/plugin/wavesurfer.minimap.min.js')

当我尝试运行react-app-rewired start时

关于如何解决这个问题有任何线索吗?

最佳答案

改用npm版本,将wavesurfer添加到依赖项下的package.json文件中,然后执行npm install,或者如果您使用的是yarn,则执行yarn install

如何在项目内部使用。

import WaveSurfer from 'wavesurfer.js';

关于javascript - 使用react-app-rewired将webpack配置添加到react-create-app,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48197078/

相关文章:

javascript - 使用测试框架时如何启动 Node 服务器?

javascript - Chrome 无法从 JavaScript 创建的图像中获取宽度和高度

javascript - 在 React 中从 Firebase 获取用户对象属性

ruby-on-rails - 带有 Vue 和 webpacker 3 的 Rails 5.1 应用程序,css 未编译

javascript - Webpack Less-Loader 与 Style-Loader 不注入(inject) <style> 标签

javascript - React.js 错误 : Invariant Violation: Minified React error #37

javascript - JQuery for 循环

javascript - Babel-node : one await works, 不止一个没有;因语法错误而中断:意外的标记

javascript - 根据对象的属性之一删除数组中的对象

javascript - react 数据网格中水平滚动的卡住列抖动