傳送門javascript
$ npm i ali-img-upload --save
本組件接入了阿里雲OSS SDK,配合antd Upload上傳組件,進行分片上傳圖片至阿里雲OSS對象存儲。css
組件使用了持久化受權,官網提供瞭如何去設置臨時受權模式,你能夠在本組件基礎進行二次開發。java
import React from 'react'; import { AliUpload } from 'ali-img-upload'; import { Form } from 'antd'; export default function Demo() { // antd form 實例 const [form] = Form.useForm(); return ( <AliUpload ossConfig={{ region: '', accessKeyId: '', accessKeySecret: '', bucket: '' }} baseURL={""} form={form} /> ) }
create-react-app
建立的項目爲例)採坑記:create-react-app
內部配置的babel是不支持的編譯node_modules
的jsx語法與less的,因此藉助cra
配置。node
customize-cra
與react-app-rewired
{ "scripts": { "start": "react-app-rewired start", "build": "react-app-rewired build", "test": "react-app-rewired test" } }
config-overrides.js
const { override, addWebpackAlias, addWebpackModuleRule, babelInclude, addLessLoader } = require('customize-cra'); const path = require('path'); const resolve = dir => path.resolve(__dirname, dir); module.exports = { webpack: override( addLessLoader({ javascriptEnabled: true, // modifyVars: { '@primary-color': '#1DA57A' }, }), addWebpackAlias({ "@": resolve("src") }), // addBabelPreset({ // test: ["./node_modules/ali-img-upload"], // presets: ["@babel/preset-react"] // }) addWebpackModuleRule({ test: /\.less$/, include: resolve('node_modules'), use: ['style-loader', 'css-loader', 'less-loader'], }), babelInclude([ resolve('src'), resolve('node_modules') ]) ) }
Copyright By Eric Wangreact