Commit 8a344c7b by liguokang

feat:

parent 9b50e3d5
const cssLoaderConfig = require('@zeit/next-css/css-loader-config');
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const { ANALYZE } = process.env;
module.exports = (nextConfig = {}) => {
return Object.assign({}, nextConfig, {
webpack(config, options) {
if (!options.defaultLoaders) {
throw new Error('This plugin is not compatible with Next.js versions below 5.0.0 https://err.sh/next-plugins/upgrade');
}
// 打包分析插件
if (ANALYZE) {
config.plugins.push(
new BundleAnalyzerPlugin({
analyzerMode: 'static',
analyzerHost: '127.0.0.1',
analyzerPort: 8080,
reportFilename: 'report.html',
defaultSizes: 'parsed',
openAnalyzer: true,
generateStatsFile: false,
statsFilename: 'stats.json',
statsOptions: null,
logLevel: 'info',
}),
);
}
const { dev, isServer } = options;
// next-config中的函数
const { cssModules, cssLoaderOptions, postcssLoaderOptions, lessLoaderOptions = {} } = nextConfig;
options.defaultLoaders.less = cssLoaderConfig(config, {
extensions: ['less'],
cssModules,
cssLoaderOptions,
postcssLoaderOptions,
dev,
isServer,
loaders: [
{
loader: 'less-loader',
options: lessLoaderOptions,
},
],
});
options.defaultLoaders.lessZZ = cssLoaderConfig(config, {
extensions: ['less'],
cssModules,
cssLoaderOptions,
postcssLoaderOptions,
isServer: true,
dev,
loaders: [
{
loader: 'less-loader',
options: lessLoaderOptions,
},
],
});
config.module.rules.push({
test: /\.less$/,
exclude: /node_modules/,
use: options.defaultLoaders.less,
});
// config.module.rules.push({
// test: /\.less$/,
// use: options.defaultLoaders.lessZZ
// })
// 禁用了antd的cssModules
config.module.rules.push({
test: /\.less$/,
include: /node_modules/,
use: cssLoaderConfig(config, {
extensions: ['less'],
cssModules: false,
cssLoaderOptions: { importLoaders: 1 },
dev,
isServer,
loaders: [
{
loader: 'less-loader',
options: lessLoaderOptions,
},
],
}),
});
// react-svg-loader
config.module.rules.push({
test: /\.svg$/,
include: /baseTemplate/,
use: [
{
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'],
plugins: ['@babel/plugin-transform-runtime'],
},
},
{
loader: 'react-svg-loader',
options: {
svgo: {
plugins: [{ removeTitle: false }],
floatPrecision: 2,
},
},
},
],
});
if (typeof nextConfig.webpack === 'function') {
return nextConfig.webpack(config, options);
}
return config;
},
});
};
/* /*
* @Author: zhujiapeng * @Author: liguokang
* @Date: 2021-06-02 17:04:29 * @Date: 2021-07-14 20:36:28
* @LastEditors: zhujiapeng * @LastEditors: liguokang
* @LastEditTime: 2021-06-02 17:04:47 * @LastEditTime: 2021-07-15 10:05:20
* @Description: 描述一下咯 * @Description:
* @Copyright: ©2021 杭州杰竞科技有限公司 版权所有 * @Copyrigh: ©2021 杭州杰竞科技有限公司 版权所有
*/ */
const withLess = require('@zeit/next-less') const withLessExcludeAntd = require('./next-less.config.js');
module.exports = withLess({ const path = require('path');
/* config options here */
}) if (typeof require !== 'undefined') {
require.extensions['.less'] = (file) => {};
}
module.exports = withLessExcludeAntd({
cssModules: true,
cssLoaderOptions: {
localIdentName: '[local]___[hash:base64:5]',
},
lessLoaderOptions: {
javascriptEnabled: true,
},
exportPathMap: async function (defaultPathMap) {
return Object.assign({
'/': { page: '/' },
'/BusinessService': { page: '/BusinessService' },
'/404.html': { page: '/404' },
});
},
webpack(config, options) {
config.resolve.alias['@'] = path.join(__dirname, 'common');
config.resolve.alias['components'] = path.join(__dirname, 'components');
config.resolve.alias['baseTemplate'] = path.join(__dirname, 'baseTemplate');
config.resolve.alias['static'] = path.join(__dirname, 'static');
return config;
},
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment