@ecoding/base.build 0.0.10 → 0.0.12
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/libs/dev/index.js +3 -1
- package/libs/entries/index.js +3 -1
- package/libs/externals/ssr.js +0 -2
- package/libs/module/css-loader/index.js +5 -1
- package/libs/module/css-loader/ssr.js +54 -0
- package/libs/module/ssr.js +10 -5
- package/libs/plugins/index.js +3 -1
- package/libs/webpack.ssr.js +4 -2
- package/libs/z-helpers/mpa.entries.js +23 -0
- package/libs/z-helpers/paths.js +1 -19
- package/package.json +2 -2
package/libs/dev/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
const mock = require("@ecoding/base.mock").default;
|
|
2
|
-
const { rootPath
|
|
2
|
+
const { rootPath } = require("../z-helpers/paths");
|
|
3
|
+
const { getMPAEntries } = require("../z-helpers/mpa.entries");
|
|
3
4
|
const { customConfig } = require("../z-helpers/config");
|
|
4
5
|
|
|
5
6
|
const entryRewrites = () => {
|
|
6
7
|
const ary = [];
|
|
8
|
+
const entry = getMPAEntries();
|
|
7
9
|
entry.pages.forEach((pageName) => {
|
|
8
10
|
const reg = new RegExp(`${pageName}\\.*`, "i");
|
|
9
11
|
ary.push({ from: reg, to: `/${pageName}.html` });
|
package/libs/entries/index.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
const { rootPath
|
|
1
|
+
const { rootPath } = require("../z-helpers/paths");
|
|
2
|
+
const { getMPAEntries } = require("../z-helpers/mpa.entries");
|
|
2
3
|
const { customConfig } = require("../z-helpers/config");
|
|
3
4
|
|
|
4
5
|
const getEntries = () => {
|
|
5
6
|
if (customConfig.mpa) {
|
|
7
|
+
const entry = getMPAEntries();
|
|
6
8
|
return entry.pagesObj;
|
|
7
9
|
}
|
|
8
10
|
return {
|
package/libs/externals/ssr.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
const { packageJSON } = require("../z-helpers/paths");
|
|
2
1
|
const nodeExternals = require("webpack-node-externals");
|
|
3
2
|
|
|
4
3
|
const getExternals = () => {
|
|
@@ -6,7 +5,6 @@ const getExternals = () => {
|
|
|
6
5
|
// "@alilc/lowcode-engine": "var window.AliLowCodeEngine",
|
|
7
6
|
// "@alilc/lowcode-engine-ext": "var window.AliLowCodeEngineExt",
|
|
8
7
|
...nodeExternals(),
|
|
9
|
-
...Object.keys(packageJSON.dependencies)
|
|
10
8
|
};
|
|
11
9
|
};
|
|
12
10
|
|
|
@@ -7,7 +7,11 @@ const loaders = [
|
|
|
7
7
|
{
|
|
8
8
|
loader: "css-loader",
|
|
9
9
|
options: {
|
|
10
|
-
modules:
|
|
10
|
+
modules: { // enable CSS modules for all files matching /\.module\.\w+$/i.test(filename) and /\.icss\.\w+$/i.test(filename) regexp.
|
|
11
|
+
auto: true,
|
|
12
|
+
mode: "local",
|
|
13
|
+
localIdentName: '[name]-[local]--[hash:base64:5]',
|
|
14
|
+
}
|
|
11
15
|
}
|
|
12
16
|
},
|
|
13
17
|
{
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
const loaders = [
|
|
2
|
+
{
|
|
3
|
+
loader: "css-loader",
|
|
4
|
+
options: {
|
|
5
|
+
modules: { // enable CSS modules for all files matching /\.module\.\w+$/i.test(filename) and /\.icss\.\w+$/i.test(filename) regexp.
|
|
6
|
+
auto: true,
|
|
7
|
+
mode: "local",
|
|
8
|
+
localIdentName: '[name]-[local]--[hash:base64:5]',
|
|
9
|
+
exportOnlyLocals: true
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
loader: "postcss-loader",
|
|
15
|
+
options: {
|
|
16
|
+
postcssOptions: {
|
|
17
|
+
plugins: {
|
|
18
|
+
autoprefixer: {
|
|
19
|
+
overrideBrowserslist: ["IE 10", "iOS >=6", "Android >=4"],
|
|
20
|
+
remove: false
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
].filter(Boolean);
|
|
27
|
+
const getLessRule = () => {
|
|
28
|
+
return {
|
|
29
|
+
test: /\.less$/,
|
|
30
|
+
use: [
|
|
31
|
+
...loaders,
|
|
32
|
+
{
|
|
33
|
+
loader: "less-loader",
|
|
34
|
+
options: {
|
|
35
|
+
lessOptions: {
|
|
36
|
+
javascriptEnabled: true
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
]
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const getCssRule = () => {
|
|
45
|
+
return {
|
|
46
|
+
test: /\.css$/,
|
|
47
|
+
use: [...loaders]
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
module.exports = {
|
|
52
|
+
getCssRule,
|
|
53
|
+
getLessRule
|
|
54
|
+
};
|
package/libs/module/ssr.js
CHANGED
|
@@ -1,22 +1,27 @@
|
|
|
1
|
-
const getTsRule = require("./ts-loader");
|
|
2
1
|
const getImgRule = require("./img-loader");
|
|
3
2
|
const getSvgRule = require("./svg-loader");
|
|
4
3
|
const getFontRule = require("./font-loader");
|
|
4
|
+
const { getLessRule, getCssRule } = require("./css-loader/ssr");
|
|
5
|
+
const { rootPath } = require("../z-helpers/paths");
|
|
5
6
|
|
|
6
7
|
const getModule = () => {
|
|
7
|
-
const tsRule = getTsRule();
|
|
8
8
|
const imgRule = getImgRule();
|
|
9
9
|
const svgRule = getSvgRule();
|
|
10
10
|
const fontRule = getFontRule();
|
|
11
|
+
const cssRule = getCssRule();
|
|
12
|
+
const lessRule = getLessRule();
|
|
11
13
|
|
|
12
14
|
return {
|
|
13
15
|
// noParse:/test.js$/, 不编译正则匹配上的文件
|
|
14
16
|
rules: [
|
|
15
|
-
tsRule,
|
|
16
17
|
{
|
|
17
|
-
test: /\.(
|
|
18
|
-
|
|
18
|
+
test: /\.(tsx?|jsx?)$/, // js ts 都走一遍 ts 进行编译
|
|
19
|
+
use: "ts-loader",
|
|
20
|
+
exclude: /node_modules/,
|
|
21
|
+
include: [rootPath("src"), /\/node_modules\/@ecoding.*/],
|
|
19
22
|
},
|
|
23
|
+
lessRule,
|
|
24
|
+
cssRule,
|
|
20
25
|
imgRule,
|
|
21
26
|
svgRule,
|
|
22
27
|
fontRule
|
package/libs/plugins/index.js
CHANGED
|
@@ -9,7 +9,8 @@ const MiniCssExtractPlugin = require("mini-css-extract-plugin"); // 提取分离
|
|
|
9
9
|
const { CleanWebpackPlugin } = require("clean-webpack-plugin"); // 提取分离css
|
|
10
10
|
const { isEnvProduction } = require("../z-helpers/util");
|
|
11
11
|
const { customConfig } = require("../z-helpers/config");
|
|
12
|
-
const { rootPath
|
|
12
|
+
const { rootPath } = require("../z-helpers/paths");
|
|
13
|
+
const { getMPAEntries } = require("../z-helpers/mpa.entries");
|
|
13
14
|
|
|
14
15
|
let dllJS = "";
|
|
15
16
|
let dllJSON = "";
|
|
@@ -33,6 +34,7 @@ const getHtmlWebpack = () => {
|
|
|
33
34
|
const template = rootPath("./template/index.ejs");
|
|
34
35
|
|
|
35
36
|
if (customConfig.mpa) {
|
|
37
|
+
const entry = getMPAEntries();
|
|
36
38
|
entry.pages.forEach((pageName) => {
|
|
37
39
|
const filename = `${pageName}.html`;
|
|
38
40
|
const obj = {
|
package/libs/webpack.ssr.js
CHANGED
|
@@ -9,6 +9,7 @@ const { getResolve, getResolveLoader } = require("./resolve");
|
|
|
9
9
|
const getPlugins = require("./plugins/ssr");
|
|
10
10
|
const getExternals = require("./externals/ssr");
|
|
11
11
|
|
|
12
|
+
|
|
12
13
|
/**
|
|
13
14
|
*
|
|
14
15
|
* @param {*} cmdOpts : build时 { WEBPACK_BUNDLE: true, WEBPACK_BUILD: true } | 本地开发dev时 { WEBPACK_SERVE: true }
|
|
@@ -55,7 +56,6 @@ const getWebpackConfig = (env) => {
|
|
|
55
56
|
|
|
56
57
|
// 配置externals
|
|
57
58
|
const externals = getExternals();
|
|
58
|
-
|
|
59
59
|
const config = {
|
|
60
60
|
target: "node",
|
|
61
61
|
mode,
|
|
@@ -68,8 +68,10 @@ const getWebpackConfig = (env) => {
|
|
|
68
68
|
resolve,
|
|
69
69
|
plugins,
|
|
70
70
|
externalsPresets: { node: true }, // 不打包 node 模块,什么 fs path 那些
|
|
71
|
-
externals
|
|
71
|
+
externals, // 不打包 node_modules 内的模块,什么 express react react-dom 那些
|
|
72
72
|
};
|
|
73
|
+
// tsx 配置
|
|
74
|
+
// 服务器端代码构建
|
|
73
75
|
return config;
|
|
74
76
|
};
|
|
75
77
|
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
const {rootPath} = require("./paths");
|
|
3
|
+
|
|
4
|
+
let entry;
|
|
5
|
+
|
|
6
|
+
exports.getMPAEntries = () => {
|
|
7
|
+
if (entry) {
|
|
8
|
+
return entry;
|
|
9
|
+
}
|
|
10
|
+
const filename = "index.tsx";
|
|
11
|
+
const dirPath = rootPath("./src/pages");
|
|
12
|
+
const pages = fs.readdirSync(dirPath);
|
|
13
|
+
const pagesObj = {};
|
|
14
|
+
pages.forEach((pageName) => {
|
|
15
|
+
pagesObj[pageName] = rootPath(`./src/pages/${pageName}/${filename}`);
|
|
16
|
+
});
|
|
17
|
+
entry = {
|
|
18
|
+
pagesObj,
|
|
19
|
+
pages
|
|
20
|
+
};
|
|
21
|
+
return entry;
|
|
22
|
+
};
|
|
23
|
+
|
package/libs/z-helpers/paths.js
CHANGED
|
@@ -1,31 +1,13 @@
|
|
|
1
1
|
const { resolve } = require("path");
|
|
2
|
-
const fs = require("fs");
|
|
3
2
|
const cwd = process.cwd();
|
|
4
3
|
|
|
5
4
|
const rootPath = (pathname) => {
|
|
6
5
|
return resolve(cwd, pathname);
|
|
7
6
|
};
|
|
8
|
-
const packageJSON = require(rootPath("./package.json"));
|
|
9
7
|
|
|
10
8
|
const resolvePath = resolve;
|
|
11
9
|
|
|
12
|
-
const getEntries = (filename) => {
|
|
13
|
-
const dirPath = rootPath("./src/pages");
|
|
14
|
-
const pages = fs.readdirSync(dirPath);
|
|
15
|
-
const pagesObj = {};
|
|
16
|
-
pages.forEach((pageName) => {
|
|
17
|
-
pagesObj[pageName] = rootPath(`./src/pages/${pageName}/${filename}`);
|
|
18
|
-
});
|
|
19
|
-
return {
|
|
20
|
-
pagesObj,
|
|
21
|
-
pages
|
|
22
|
-
};
|
|
23
|
-
};
|
|
24
|
-
|
|
25
10
|
module.exports = {
|
|
26
11
|
rootPath,
|
|
27
|
-
resolvePath
|
|
28
|
-
packageJSON,
|
|
29
|
-
entry: getEntries("index.tsx"),
|
|
30
|
-
ssrEntry: getEntries("index.server.tsx")
|
|
12
|
+
resolvePath
|
|
31
13
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ecoding/base.build",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.12",
|
|
4
4
|
"description": "tpl building",
|
|
5
5
|
"author": "cxc",
|
|
6
6
|
"license": "MIT",
|
|
@@ -53,5 +53,5 @@
|
|
|
53
53
|
"publishConfig": {
|
|
54
54
|
"access": "public"
|
|
55
55
|
},
|
|
56
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "247243b7d008258a17064708b1abb15dcd361830"
|
|
57
57
|
}
|