akfun 3.3.0 → 3.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -388,7 +388,44 @@ module.exports = {
|
|
|
388
388
|
}
|
|
389
389
|
```
|
|
390
390
|
|
|
391
|
-
16.
|
|
391
|
+
16. 自定义css-loader的配置
|
|
392
|
+
> 比如用于启用/禁用 @import 解析。
|
|
393
|
+
```bash
|
|
394
|
+
module.exports = {
|
|
395
|
+
...
|
|
396
|
+
webpack: {
|
|
397
|
+
...
|
|
398
|
+
cssLoaderOption: {
|
|
399
|
+
import: false, // 启用/禁用 @import 解析
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
...
|
|
403
|
+
}
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
17. 自定义postcss-loader的配置
|
|
407
|
+
> 比如用于添加 PostCSS 选项与插件。
|
|
408
|
+
```bash
|
|
409
|
+
module.exports = {
|
|
410
|
+
...
|
|
411
|
+
webpack: {
|
|
412
|
+
...
|
|
413
|
+
postCssLoaderOption: {
|
|
414
|
+
postcssOptions: {
|
|
415
|
+
plugins: [
|
|
416
|
+
require('postcss-pxtorem')({ // 用于将px自动转化为rem
|
|
417
|
+
rootValue: 16, // 1rem 等于 16px
|
|
418
|
+
propList: ['*'], // 所有属性都转换
|
|
419
|
+
}),
|
|
420
|
+
],
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
...
|
|
425
|
+
}
|
|
426
|
+
```
|
|
427
|
+
|
|
428
|
+
18. 本地开启https服务
|
|
392
429
|
> 使用 https://localhost/index.html 访问当前项目。
|
|
393
430
|
```bash
|
|
394
431
|
module.exports = {
|
package/package.json
CHANGED
|
@@ -42,7 +42,7 @@ exports.cssLoaders = function (options) {
|
|
|
42
42
|
if (options.cssLoaderUrlDir && resourcePath.includes(options.cssLoaderUrlDir)) {
|
|
43
43
|
// 指定处理某类路径下的中相关 css 文件中的 url
|
|
44
44
|
return true;
|
|
45
|
-
}
|
|
45
|
+
}
|
|
46
46
|
if (url.startsWith('data:')) {
|
|
47
47
|
// 不处理 css 中的 bas64 url
|
|
48
48
|
return false;
|
|
@@ -60,7 +60,10 @@ exports.cssLoaders = function (options) {
|
|
|
60
60
|
|
|
61
61
|
const postCssLoader = {
|
|
62
62
|
loader: 'postcss-loader',
|
|
63
|
-
options:
|
|
63
|
+
options: {
|
|
64
|
+
...postCssConfig,
|
|
65
|
+
...(options.postCssLoaderOption || {})
|
|
66
|
+
}
|
|
64
67
|
};
|
|
65
68
|
|
|
66
69
|
// generate loader string to be used with extract text plugin
|
|
@@ -7,7 +7,6 @@ const projectConfig = require('../config/index');
|
|
|
7
7
|
const getBaseWebpackConfig = require('./webpack.base.conf');
|
|
8
8
|
const entrys2htmlWebpackPlugin = require('../utils/entrys2htmlWebpackPlugin');
|
|
9
9
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
|
10
|
-
const config = require('../config');
|
|
11
10
|
// const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
|
|
12
11
|
|
|
13
12
|
module.exports = (akfunConfig) => {
|
|
@@ -36,7 +35,7 @@ module.exports = (akfunConfig) => {
|
|
|
36
35
|
resolve: {
|
|
37
36
|
// dev环境默认使用 require
|
|
38
37
|
conditionNames: ['require'],
|
|
39
|
-
...baseWebpackConfig.resolve
|
|
38
|
+
...baseWebpackConfig.resolve
|
|
40
39
|
},
|
|
41
40
|
module: {
|
|
42
41
|
rules: utils.styleLoaders({
|
|
@@ -45,6 +44,7 @@ module.exports = (akfunConfig) => {
|
|
|
45
44
|
cssLoaderUrl: config.webpack.cssLoaderUrl,
|
|
46
45
|
cssLoaderUrlDir: config.webpack.cssLoaderUrlDir,
|
|
47
46
|
cssLoaderOption: config.webpack.cssLoaderOption, // 用于自定义css-loader配置项(优先级最高)
|
|
47
|
+
postCssLoaderOption: config.webpack.postCssLoaderOption // 用于自定义postcss-loader配置项(优先级最高)
|
|
48
48
|
})
|
|
49
49
|
},
|
|
50
50
|
// devtool: '#cheap-module-eval-source-map', // 本地开发环境中的取值
|
|
@@ -3,6 +3,7 @@ const MiniCssExtractPlugin = require('mini-css-extract-plugin'); // 替换extrac
|
|
|
3
3
|
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
|
|
4
4
|
const CompressionWebpackPlugin = require('compression-webpack-plugin');
|
|
5
5
|
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
|
|
6
|
+
const deepMergeConfig = require('../utils/deepMergeConfig');
|
|
6
7
|
|
|
7
8
|
const utils = require('./loaderUtils');
|
|
8
9
|
// 引入当前项目配置文件
|
|
@@ -41,6 +42,7 @@ module.exports = (akfunConfig) => {
|
|
|
41
42
|
cssLoaderUrl: config.webpack.cssLoaderUrl,
|
|
42
43
|
cssLoaderUrlDir: config.webpack.cssLoaderUrlDir,
|
|
43
44
|
cssLoaderOption: config.webpack.cssLoaderOption, // 用于自定义css-loader配置项(优先级最高)
|
|
45
|
+
postCssLoaderOption: config.webpack.postCssLoaderOption // 用于自定义postcss-loader配置项(优先级最高)
|
|
44
46
|
})
|
|
45
47
|
},
|
|
46
48
|
devtool: curEnvConfig.productionSourceMap ? curEnvConfig.devtool || 'source-map' : false, // 线上生成环境
|
|
@@ -68,6 +70,11 @@ module.exports = (akfunConfig) => {
|
|
|
68
70
|
]
|
|
69
71
|
});
|
|
70
72
|
|
|
73
|
+
// 优先使用当前环境配置中的output
|
|
74
|
+
if (curEnvConfig.output) {
|
|
75
|
+
webpackLibConfig.output = deepMergeConfig(webpackLibConfig.output, curEnvConfig.output);
|
|
76
|
+
}
|
|
77
|
+
|
|
71
78
|
// 是否开启Gzip
|
|
72
79
|
if (curEnvConfig.productionGzip) {
|
|
73
80
|
webpackLibConfig.plugins.push(
|
|
@@ -55,6 +55,7 @@ module.exports = (akfunConfig) => {
|
|
|
55
55
|
cssLoaderUrl: config.webpack.cssLoaderUrl,
|
|
56
56
|
cssLoaderUrlDir: config.webpack.cssLoaderUrlDir,
|
|
57
57
|
cssLoaderOption: config.webpack.cssLoaderOption, // 用于自定义css-loader配置项(优先级最高)
|
|
58
|
+
postCssLoaderOption: config.webpack.postCssLoaderOption // 用于自定义postcss-loader配置项(优先级最高)
|
|
58
59
|
})
|
|
59
60
|
},
|
|
60
61
|
devtool: curEnvConfig.productionSourceMap ? curEnvConfig.devtool || 'source-map' : false, // 线上生成环境
|