@ecoding/base.build 0.2.0 → 0.2.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
@@ -9,6 +9,7 @@
9
9
  mpa: boolean; // 是否是多页
10
10
  dll:boolean; // 是否打dll
11
11
  micro:"main" | "child"; // 微前端主应用或子应用 默认null
12
+ electron: boolean; // electron 是否是electron
12
13
  outputLibrary: string; // micro == child时生效,整个库向外暴露的变量名
13
14
  publicPath: string; // client cdn 资源前缀
14
15
  outputPath: string; // client build bundle 目录,相对命令执行目录
@@ -19,6 +20,7 @@
19
20
  {
20
21
  "@alilc/lowcode-engine": "var window.AliLowCodeEngine",
21
22
  "@alilc/lowcode-engine-ext": "var window.AliLowCodeEngineExt",
23
+ "electron": true,
22
24
  };
23
25
  */
24
26
  dev:{
@@ -36,6 +38,20 @@
36
38
  }
37
39
  ```
38
40
 
41
+ ## 注意:
42
+
43
+ 内部已经支持了 sass 和 less 配置,默认 less,如果想要使用 sass,还需额外安装:
44
+
45
+ ```bash
46
+ # "node-sass": "^7.0.3",
47
+ # "sass-loader": "^13.1.0",
48
+
49
+ npm i sass-loader node-sass -D --registry http://r.cnpmjs.org
50
+ # 或
51
+ npm i sass-loader node-sass -D --registry https://registry.npm.taobao.org
52
+
53
+ ```
54
+
39
55
  ## 复杂自定义打包配置
40
56
 
41
57
  在工程下新建 build.js,return webpack 的配置即可,注意完全按照 webpack 配置规则,框架无做任何干涉
@@ -75,7 +91,7 @@ module.exports = {
75
91
  "babel-eslint": "10.1.0",
76
92
  "babel-loader": "8.2.5",
77
93
  "clean-webpack-plugin": "^4.0.0",
78
- "concurrently": "^7.3.0", // 并行执行node 命令
94
+ "concurrently": "^7.3.0", // 并行执行node 命令
79
95
  "core-js": "3.23.1",
80
96
  "cross-env": "7.0.3",
81
97
  "css-loader": "6.7.1",
@@ -88,6 +104,7 @@ module.exports = {
88
104
  "less-loader": "11.0.0",
89
105
  "mini-css-extract-plugin": "2.6.1", // css压缩
90
106
  "postcss-loader": "7.0.0", // css向下兼容
107
+ "rimraf": "^3.0.2",
91
108
  "style-loader": "3.3.1", // 编译 style 内联css
92
109
  "terser-webpack-plugin": "5.3.3", // js压缩
93
110
  "typescript": "4.8.3",
@@ -1,11 +1,14 @@
1
1
  const { customConfig } = require("../z-helpers/config");
2
2
 
3
3
  const getExternals = () => {
4
- return {
5
- // "@alilc/lowcode-engine": "var window.AliLowCodeEngine",
6
- // "@alilc/lowcode-engine-ext": "var window.AliLowCodeEngineExt",
7
- ...customConfig.externals
8
- };
4
+ return Object.assign(
5
+ {
6
+ // "@alilc/lowcode-engine": "var window.AliLowCodeEngine",
7
+ // "@alilc/lowcode-engine-ext": "var window.AliLowCodeEngineExt",
8
+ ...customConfig.externals
9
+ },
10
+ customConfig.electron ? { electron: true } : {}
11
+ );
9
12
  };
10
13
 
11
14
  module.exports = getExternals;
@@ -7,10 +7,11 @@ const loaders = [
7
7
  {
8
8
  loader: "css-loader",
9
9
  options: {
10
- modules: { // enable CSS modules for all files matching /\.module\.\w+$/i.test(filename) and /\.icss\.\w+$/i.test(filename) regexp.
10
+ modules: {
11
+ // enable CSS modules for all files matching /\.module\.\w+$/i.test(filename) and /\.icss\.\w+$/i.test(filename) regexp.
11
12
  auto: true,
12
13
  mode: "local",
13
- localIdentName: '[name]-[local]--[hash:base64:5]',
14
+ localIdentName: "[name]-[local]--[hash:base64:5]"
14
15
  }
15
16
  }
16
17
  },
@@ -46,6 +47,18 @@ const getLessRule = () => {
46
47
  };
47
48
  };
48
49
 
50
+ const getSassRule = () => {
51
+ return {
52
+ test: /\.scss$/,
53
+ use: [
54
+ ...loaders,
55
+ {
56
+ loader: "sass-loader"
57
+ }
58
+ ]
59
+ };
60
+ };
61
+
49
62
  const getCssRule = () => {
50
63
  return {
51
64
  test: /\.css$/,
@@ -55,5 +68,6 @@ const getCssRule = () => {
55
68
 
56
69
  module.exports = {
57
70
  getCssRule,
71
+ getSassRule,
58
72
  getLessRule
59
73
  };
@@ -2,10 +2,11 @@ const loaders = [
2
2
  {
3
3
  loader: "css-loader",
4
4
  options: {
5
- modules: { // enable CSS modules for all files matching /\.module\.\w+$/i.test(filename) and /\.icss\.\w+$/i.test(filename) regexp.
5
+ modules: {
6
+ // enable CSS modules for all files matching /\.module\.\w+$/i.test(filename) and /\.icss\.\w+$/i.test(filename) regexp.
6
7
  auto: true,
7
8
  mode: "local",
8
- localIdentName: '[name]-[local]--[hash:base64:5]',
9
+ localIdentName: "[name]-[local]--[hash:base64:5]",
9
10
  exportOnlyLocals: true
10
11
  }
11
12
  }
@@ -41,6 +42,18 @@ const getLessRule = () => {
41
42
  };
42
43
  };
43
44
 
45
+ const getSassRule = () => {
46
+ return {
47
+ test: /\.scss$/,
48
+ use: [
49
+ ...loaders,
50
+ {
51
+ loader: "sass-loader"
52
+ }
53
+ ]
54
+ };
55
+ };
56
+
44
57
  const getCssRule = () => {
45
58
  return {
46
59
  test: /\.css$/,
@@ -50,5 +63,6 @@ const getCssRule = () => {
50
63
 
51
64
  module.exports = {
52
65
  getCssRule,
66
+ getSassRule,
53
67
  getLessRule
54
68
  };
@@ -1,29 +1,22 @@
1
- const getTsRule = require('./ts-loader');
2
- const { getCssRule, getLessRule } = require('./css-loader');
3
- const getImgRule = require('./img-loader');
4
- const getSvgRule = require('./svg-loader');
5
- const getFontRule = require('./font-loader');
1
+ const getTsRule = require("./ts-loader");
2
+ const { getCssRule, getLessRule, getSassRule } = require("./css-loader");
3
+ const getImgRule = require("./img-loader");
4
+ const getSvgRule = require("./svg-loader");
5
+ const getFontRule = require("./font-loader");
6
6
 
7
7
  const getModule = () => {
8
8
  const tsRule = getTsRule();
9
9
  const lessRule = getLessRule();
10
10
  const cssRule = getCssRule();
11
+ const sassRule = getSassRule();
11
12
  const imgRule = getImgRule();
12
13
  const svgRule = getSvgRule();
13
14
  const fontRule = getFontRule();
14
15
 
15
16
  return {
16
17
  // noParse:/test.js$/, 不编译正则匹配上的文件
17
- rules: [
18
- tsRule,
19
- lessRule,
20
- cssRule,
21
- imgRule,
22
- svgRule,
23
- fontRule
24
- ]
25
- }
26
- }
18
+ rules: [tsRule, lessRule, sassRule, cssRule, imgRule, svgRule, fontRule]
19
+ };
20
+ };
27
21
 
28
-
29
- module.exports = getModule;
22
+ module.exports = getModule;
@@ -1,8 +1,8 @@
1
1
  const getImgRule = require("./img-loader");
2
- const getTsRule = require('./ts-loader/ssr');
2
+ const getTsRule = require("./ts-loader/ssr");
3
3
  const getSvgRule = require("./svg-loader");
4
4
  const getFontRule = require("./font-loader");
5
- const { getLessRule, getCssRule } = require("./css-loader/ssr");
5
+ const { getLessRule, getCssRule, getSassRule } = require("./css-loader/ssr");
6
6
 
7
7
  const getModule = () => {
8
8
  const tsRule = getTsRule();
@@ -11,17 +11,11 @@ const getModule = () => {
11
11
  const fontRule = getFontRule();
12
12
  const cssRule = getCssRule();
13
13
  const lessRule = getLessRule();
14
+ const sassRule = getSassRule();
14
15
 
15
16
  return {
16
17
  // noParse:/test.js$/, 不编译正则匹配上的文件
17
- rules: [
18
- tsRule,
19
- lessRule,
20
- cssRule,
21
- imgRule,
22
- svgRule,
23
- fontRule
24
- ]
18
+ rules: [tsRule, lessRule, sassRule, cssRule, imgRule, svgRule, fontRule]
25
19
  };
26
20
  };
27
21
 
@@ -29,8 +29,8 @@ const getOptimization = () => {
29
29
  // 这里的体积大小时指压缩前的
30
30
  obj.splitChunks = {
31
31
  chunks: "all", // initial | all | async all 表明了在异步和同步之间共享
32
- minSize: 10000, // 生成 chunk 的最小体积(以 bytes 为单位) 不限制
33
- maxSize: 500000, // 封装的模块的最小体积 0 不限制
32
+ minSize: 1000000, // 生成 chunk 的最小体积(以 bytes 为单位) 不限制,想要达到dll效果 这里是关键
33
+ maxSize: 2000000, // 封装的模块的最小体积 0 不限制
34
34
  minRemainingSize: 10000, // 分割后剩下的模块大小 0 不限制
35
35
  minChunks: 1, // 模块的最小被引用次数
36
36
  maxAsyncRequests: 30, // 异步模块按需加载的最大并行请求数 import('xxx.js').then
@@ -38,7 +38,7 @@ const getOutput = () => {
38
38
  // library: '[name]', // 整个库向外暴露的变量名
39
39
  // libraryTarget: 'var' // 默认
40
40
  },
41
- customConfig.micro === "child"
41
+ !customConfig.electron && customConfig.micro === "child"
42
42
  ? {
43
43
  library: {
44
44
  name: customConfig.outputLibrary,
@@ -47,7 +47,8 @@ const getOutput = () => {
47
47
  chunkLoadingGlobal: `webpackJsonp_${customConfig.outputLibrary}`,
48
48
  globalObject: "window"
49
49
  }
50
- : {}
50
+ : {},
51
+ customConfig.electron ? { libraryTarget: "commonjs2" } : {}
51
52
  );
52
53
  };
53
54
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ecoding/base.build",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "tpl building",
5
5
  "author": "cxc",
6
6
  "license": "MIT",
@@ -29,6 +29,7 @@
29
29
  "cross-env": "7.0.3",
30
30
  "css-loader": "6.7.1",
31
31
  "css-minimizer-webpack-plugin": "4.0.0",
32
+ "eslint": "8.18.0",
32
33
  "globby": "^11.0.2",
33
34
  "html-webpack-plugin": "5.5.0",
34
35
  "inline-chunk-html-plugin": "1.1.1",
@@ -50,5 +51,5 @@
50
51
  "publishConfig": {
51
52
  "access": "public"
52
53
  },
53
- "gitHead": "214f9ec730c9f5257a99cab28ebe3ff9af4bb689"
54
+ "gitHead": "3e1dc18ba738b70dc75d79e88f366cc8d6a3f666"
54
55
  }