使用 webpack-aliyun-oss 包上传到oss
const { defineConfig } = require('@vue/cli-service')
const WebpackAliyunOss = require('webpack-aliyun-oss');
const isProduction = process.env.NODE_ENV === 'production';
module.exports = defineConfig({
transpileDependencies: true,
css: {
loaderOptions: {
scss: {
additionalData: `@import '~@/assets/sass/_variable.scss';`
}
}
},
publicPath: isProduction ? 'https://xxxxx/chat-ai/' : './', // 生产环境使用oss 资源访问路径
devServer: {
historyApiFallback: true
},
configureWebpack: config => {
if (isProduction) {
config.plugins.push(
new WebpackAliyunOss({
accessKeyId: 'xxxx',
accessKeySecret: 'xxxx',
region: 'xxxx',
bucket: 'xxxx',
dist: "chat-ai", // 上传oss文件存储路径文件夹
from: "./dist/**",
setOssPath: filePath => {
let index = filePath.lastIndexOf("dist");
let Path = filePath.substring(index + 4, filePath.length);
return Path.replace(/\\/g, "/");
},
setHeaders: () => {
return {
"Cache-Control": "max-age=31536000"
};
}
})
)
}
}
})