@ecoding/base.build 0.0.12 → 0.0.13

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.
@@ -6,7 +6,7 @@ const getEntries = () => {
6
6
  return ssrEntry.pagesObj;
7
7
  }
8
8
  return {
9
- app: rootPath("./src/app.tsx")
9
+ app: rootPath("./src/server-render.tsx")
10
10
  };
11
11
  };
12
12
 
@@ -1,10 +1,11 @@
1
1
  const getImgRule = require("./img-loader");
2
+ const getTsRule = require('./ts-loader/ssr');
2
3
  const getSvgRule = require("./svg-loader");
3
4
  const getFontRule = require("./font-loader");
4
5
  const { getLessRule, getCssRule } = require("./css-loader/ssr");
5
- const { rootPath } = require("../z-helpers/paths");
6
6
 
7
7
  const getModule = () => {
8
+ const tsRule = getTsRule();
8
9
  const imgRule = getImgRule();
9
10
  const svgRule = getSvgRule();
10
11
  const fontRule = getFontRule();
@@ -14,12 +15,7 @@ const getModule = () => {
14
15
  return {
15
16
  // noParse:/test.js$/, 不编译正则匹配上的文件
16
17
  rules: [
17
- {
18
- test: /\.(tsx?|jsx?)$/, // js ts 都走一遍 ts 进行编译
19
- use: "ts-loader",
20
- exclude: /node_modules/,
21
- include: [rootPath("src"), /\/node_modules\/@ecoding.*/],
22
- },
18
+ tsRule,
23
19
  lessRule,
24
20
  cssRule,
25
21
  imgRule,
@@ -1,5 +1,79 @@
1
1
  const { rootPath } = require("../../z-helpers/paths");
2
- const babelLoader = require("./babel");
2
+
3
+ const presets = [
4
+ [
5
+ "@babel/preset-env",
6
+ {
7
+ ignoreBrowserslistConfig: true,
8
+
9
+ /**
10
+ * false 当我们使用preset-env传入useBuiltIns参数时候,默认为false。
11
+ * 它表示仅仅会转化最新的ES语法,并不会转化任何Api和方法。就是关闭垫片
12
+ *
13
+ * 当传入entry时,需要我们在项目入口文件中手动引入一次core-js,
14
+ * 它会根据我们配置的浏览器兼容性列表(browserList)然后全量引入不兼容的polyfill。
15
+ * 项目入口文件中需要额外引入polyfill
16
+ // core-js 2.0中是使用"@babel/polyfill" core-js3.0版本中变化成为了上边两个包
17
+ import "@babel/polyfill" // core-js 2.0
18
+
19
+ import "core-js/stable" // core-js3.0
20
+ import "regenerator-runtime/runtime" // core-js3.0
21
+
22
+ // babel
23
+ {
24
+ "presets": [
25
+ ["@babel/preset-env", {
26
+ "useBuiltIns": "entry"
27
+ }]
28
+ ]
29
+ }
30
+
31
+ * usage时,会根据配置的浏览器兼容,以及代码中 使用到的Api 进行引入polyfill按需添加。
32
+ */
33
+ useBuiltIns: "usage",
34
+ targets: {
35
+ browsers: [
36
+ "last 1 version",
37
+ "> 1%",
38
+ "IE 10",
39
+ "iOS >=6",
40
+ "Android >=4"
41
+ ]
42
+ },
43
+ // 如果设为true,则会编译 es6Module 语法,则会失去tree-shaking
44
+ modules: false,
45
+ corejs: 3,
46
+ // 需要忽略的预编译包
47
+ exclude: [
48
+ // 没使用Symbol,不需要_typeof方法兼容Symbol
49
+ 'transform-typeof-symbol'
50
+ ]
51
+ }
52
+ ],
53
+ ["@babel/preset-react", {
54
+ // automatic 自动模式 不需要引入 import React form 'react';
55
+ // classic 经典模式 需要引入 import React form 'react';
56
+ runtime: 'classic',
57
+ }],
58
+ ["@babel/preset-typescript"]
59
+ ].filter(Boolean);
60
+
61
+ const plugins = [
62
+ ["@babel/plugin-transform-runtime", { corejs: false }],
63
+ ["@babel/plugin-proposal-decorators", { legacy: true }],
64
+ ["@babel/plugin-proposal-class-properties", { loose: true }],
65
+ ["@babel/plugin-proposal-private-methods", { loose: true }],
66
+ ["@babel/plugin-proposal-private-property-in-object", { loose: true }]
67
+ ].filter(Boolean);
68
+
69
+ const babelLoader = {
70
+ loader: 'babel-loader',
71
+ options: {
72
+ presets,
73
+ plugins,
74
+ cacheDirectory: true
75
+ }
76
+ }
3
77
 
4
78
  const getTsRule = () => {
5
79
  return {
@@ -1,3 +1,5 @@
1
+ const { rootPath } = require("../../z-helpers/paths");
2
+
1
3
  const presets = [
2
4
  [
3
5
  "@babel/preset-env",
@@ -29,15 +31,7 @@ const presets = [
29
31
  * usage时,会根据配置的浏览器兼容,以及代码中 使用到的Api 进行引入polyfill按需添加。
30
32
  */
31
33
  useBuiltIns: "usage",
32
- targets: {
33
- browsers: [
34
- "last 1 version",
35
- "> 1%",
36
- "IE 10",
37
- "iOS >=6",
38
- "Android >=4"
39
- ]
40
- },
34
+ targets: "node 14.0",
41
35
  // 如果设为true,则会编译 es6Module 语法,则会失去tree-shaking
42
36
  modules: false,
43
37
  corejs: 3,
@@ -49,27 +43,40 @@ const presets = [
49
43
  }
50
44
  ],
51
45
  ["@babel/preset-react", {
52
- // automatic 自动模式 不需要引入 import React form 'react';
53
- // classic 经典模式 需要引入 import React form 'react';
46
+ // automatic 自动模式 不需要引入 import React form 'react'; 对应tsconfig.json jsx: react-jsx
47
+ // classic 经典模式 需要引入 import React form 'react'; 对应tsconfig.json jsx: react
54
48
  runtime: 'classic',
55
49
  }],
56
50
  ["@babel/preset-typescript"]
57
51
  ].filter(Boolean);
58
52
 
59
- const plugins = [
60
- ["@babel/plugin-transform-runtime", { corejs: false }],
61
- ["@babel/plugin-proposal-decorators", { legacy: true }],
62
- ["@babel/plugin-proposal-class-properties", { loose: true }],
63
- ["@babel/plugin-proposal-private-methods", { loose: true }],
64
- ["@babel/plugin-proposal-private-property-in-object", { loose: true }]
65
- ].filter(Boolean);
53
+ // const plugins = [
54
+ // ["@babel/plugin-transform-runtime", { corejs: false }],
55
+ // ["@babel/plugin-proposal-decorators", { legacy: true }],
56
+ // ["@babel/plugin-proposal-class-properties", { loose: true }],
57
+ // ["@babel/plugin-proposal-private-methods", { loose: true }],
58
+ // ["@babel/plugin-proposal-private-property-in-object", { loose: true }]
59
+ // ].filter(Boolean);
66
60
 
67
61
  const babelLoader = {
68
62
  loader: 'babel-loader',
69
63
  options: {
70
64
  presets,
71
- plugins,
65
+ // plugins,
72
66
  cacheDirectory: true
73
67
  }
74
68
  }
75
- module.exports = babelLoader;
69
+
70
+ const getTsRule = () => {
71
+ return {
72
+ test: /\.(tsx?|jsx?)$/,
73
+ use: [babelLoader],
74
+ // 指定要编译的路径
75
+ include: [rootPath("src"), /\/node_modules\/@ecoding.*/],
76
+
77
+ // 忽略要编译的路径
78
+ exclude: [/node_modules/]
79
+ };
80
+ };
81
+
82
+ module.exports = getTsRule;
@@ -14,7 +14,7 @@ const pubPath = () => {
14
14
  const getOutput = () => {
15
15
  return Object.assign({
16
16
  // 输出文件目录(将来所有资源输出的公共目录)
17
- path: rootPath(customConfig.outputPath || "./dist"),
17
+ path: rootPath(customConfig.outputPath || "../../src/ssr"),
18
18
 
19
19
  /**
20
20
  * 所有资源引入公共路径前缀 --> 'imgs/a.jpg' --> '/imgs/a.jpg'
@@ -26,7 +26,7 @@ const getOutput = () => {
26
26
  publicPath: pubPath(),
27
27
 
28
28
  // 入口代码块文件名称(指定名称+目录)
29
- filename: "[name].server-entry.js",
29
+ filename: "[name].server-render.js",
30
30
  libraryTarget: "commonjs2"
31
31
  });
32
32
  };
@@ -21,3 +21,20 @@ exports.getMPAEntries = () => {
21
21
  return entry;
22
22
  };
23
23
 
24
+ exports.getSSRMPAEntries = () => {
25
+ if (entry) {
26
+ return entry;
27
+ }
28
+ const filename = "server-render.tsx";
29
+ const dirPath = rootPath("./src/pages");
30
+ const pages = fs.readdirSync(dirPath);
31
+ const pagesObj = {};
32
+ pages.forEach((pageName) => {
33
+ pagesObj[pageName] = rootPath(`./src/pages/${pageName}/${filename}`);
34
+ });
35
+ entry = {
36
+ pagesObj,
37
+ pages
38
+ };
39
+ return entry;
40
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ecoding/base.build",
3
- "version": "0.0.12",
3
+ "version": "0.0.13",
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": "247243b7d008258a17064708b1abb15dcd361830"
56
+ "gitHead": "e95d9c3fa16848e2190709e30917b918935a366b"
57
57
  }