next-oss-webpack-plugin
v1.0.0
Published
aliyun oss webpack plugin for next.js
Downloads
17
Readme
oss webpack plugin
webpack插件,将打包的静态资源上传至oss(仅限阿里云)
在next.js项目中使用
- 安装
npm install next-oss-webpack-plugin --save-dev
- 配置
next.config.js
const NextOSSPlugin = require('next-oss-webpack-plugin');
const isProd = process.env.NODE_ENV === 'production';
const assetPrefix = isProd ? 'https://cdn.domain.com/path' : ''; // path自定义
module.exports = {
assetPrefix,
webpack: (config, { buildId }) => {
if (isProd && buildId) {
config.plugins.push(new NextOSSPlugin({
region: 'oss-cn-hangzhou', // bucket所在区域
accessKeyId: 'xxx',
accessKeySecret: 'xxx',
bucket: 'xxx',
filter: assert => /\.js$/.test(assert),
assetPrefix: `${assetPrefix}/_next/`, // 上传资源前缀
customizedOssPaths: [
// 替换为 /:buildId/page/xxx.js ,使能正常访问
{ pattern: /bundles\/pages/g, replace: `${buildId}/page` },
],
}));
}
return config;
}
}