gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 14:31:54 24 4
gpt4 key购买 nike

警告:我是新手。

我正在开发一个通过 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com