@lark-apaas/miaoda-presets 0.1.0-alpha.13 → 0.1.0-alpha.15

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.
@@ -15,8 +15,8 @@ function createEslintConfig() {
15
15
  return typescript_eslint_1.default.config({ ignores: ['dist', 'node_modules', 'build'] }, {
16
16
  extends: [
17
17
  js_1.default.configs.recommended,
18
- eslint_1.default,
19
18
  ...typescript_eslint_1.default.configs.recommended,
19
+ eslint_1.default,
20
20
  ],
21
21
  files: ['src/**/*.{ts,tsx}'],
22
22
  languageOptions: {
@@ -18,11 +18,22 @@ exports.default = {
18
18
  'react/no-unknown-property': 'off', // 允许未知属性
19
19
  'react-hooks/exhaustive-deps': 'off', // 不强制检查依赖数组
20
20
  // JavaScript 基础规则
21
- 'no-undef': 'error', // 禁止使用未声明的变量
21
+ // 通过 tsc 来控制,默认 AI 不写 js 文件
22
+ 'no-undef': 'off', // 禁止使用未声明的变量
22
23
  'no-console': 'off', // 允许使用 console
23
24
  'prefer-const': 'off', // 不强制使用 const
24
25
  // Import 相关检查
25
26
  'import/no-unresolved': 'error', // 检查导入路径是否存在
26
27
  'import/named': 'error', // 检查命名导入是否存在
28
+ // 效果相关:模型不会
29
+ 'no-constant-binary-expression': 'off', // 不强制使用常量二进制表达式
30
+ // 效果相关:希望模型使用内置 logger
31
+ 'no-restricted-syntax': [
32
+ 'error',
33
+ {
34
+ selector: "CallExpression[callee.object.name='console'][callee.property.name=/^(log|warn|info|debug|trace)$/]",
35
+ message: 'Avoid using console.log, console.warn, etc. Use `@byted/spark-framework/logger` instead.',
36
+ },
37
+ ],
27
38
  },
28
39
  };
@@ -9,7 +9,7 @@ const core_1 = __importDefault(require("@rspack/core"));
9
9
  const RouteParserPlugin = require('../rspack-plugins/route-parser-plugin');
10
10
  // eslint-disable-next-line max-lines-per-function
11
11
  function createRecommendRspackConfig(options) {
12
- const { enableReactRefresh = false, isDev = true } = options;
12
+ const { enableReactRefresh = false, isDev = true, needRoutes = true, } = options;
13
13
  return {
14
14
  experiments: {
15
15
  css: true,
@@ -36,7 +36,31 @@ function createRecommendRspackConfig(options) {
36
36
  },
37
37
  {
38
38
  test: /\.css$/,
39
- use: ['postcss-loader'],
39
+ use: [
40
+ {
41
+ loader: 'postcss-loader',
42
+ options: {
43
+ postcssOptions: {
44
+ plugins: [
45
+ [
46
+ 'postcss-import',
47
+ {
48
+ resolve: (id, _basedir) => {
49
+ // 只有dev环境需要打包选中精调所需的一些预置样式, prod环境则不打包
50
+ if (id === '@/inspector.dev.css') {
51
+ return isDev
52
+ ? path_1.default.join(_basedir, '/inspector.dev.css')
53
+ : [];
54
+ }
55
+ return id;
56
+ },
57
+ },
58
+ ],
59
+ ],
60
+ },
61
+ },
62
+ },
63
+ ],
40
64
  type: 'css',
41
65
  },
42
66
  {
@@ -94,52 +118,57 @@ function createRecommendRspackConfig(options) {
94
118
  new core_1.default.optimize.LimitChunkCountPlugin({
95
119
  maxChunks: 1,
96
120
  }),
97
- isDev && new RouteParserPlugin({
98
- appPath: './client/src/app.tsx',
99
- outputPath: path_1.default.resolve(__dirname, 'dist/client/routes.json'),
100
- }),
121
+ // 开发环境下,解析路由
122
+ isDev &&
123
+ needRoutes &&
124
+ new RouteParserPlugin({
125
+ appPath: './client/src/app.tsx',
126
+ outputPath: path_1.default.resolve(__dirname, 'dist/client/routes.json'),
127
+ }),
101
128
  ],
102
- optimization: isDev ? {} : {
103
- moduleIds: 'deterministic',
104
- concatenateModules: true,
105
- minimize: true, // 对应vite的minify配置
106
- minimizer: [
107
- new core_1.default.SwcJsMinimizerRspackPlugin({
108
- minimizerOptions: {
109
- // 保持不压缩
110
- minify: !isDev,
111
- mangle: !isDev,
112
- format: {
113
- beautify: isDev,
114
- comments: false,
115
- },
116
- compress: {
117
- keep_classnames: true,
118
- keep_fnames: true,
119
- keep_fargs: !isDev,
120
- unused: true,
121
- dead_code: true,
122
- drop_debugger: true,
123
- // FIXME: 先临时开始 console.log
124
- // drop_console: !isDev,
125
- const_to_let: !isDev,
126
- booleans_as_integers: !isDev,
127
- booleans: !isDev,
128
- // maybe unsafe
129
- reduce_funcs: !isDev,
130
- reduce_vars: !isDev,
129
+ optimization: isDev
130
+ ? {}
131
+ : {
132
+ moduleIds: 'deterministic',
133
+ concatenateModules: true,
134
+ minimize: true, // 对应vite的minify配置
135
+ minimizer: [
136
+ new core_1.default.SwcJsMinimizerRspackPlugin({
137
+ minimizerOptions: {
138
+ // 保持不压缩
139
+ minify: !isDev,
140
+ mangle: !isDev,
141
+ format: {
142
+ beautify: isDev,
143
+ comments: false,
144
+ },
145
+ compress: {
146
+ keep_classnames: true,
147
+ keep_fnames: true,
148
+ keep_fargs: !isDev,
149
+ unused: true,
150
+ dead_code: true,
151
+ drop_debugger: true,
152
+ // FIXME: 先临时开始 console.log
153
+ // drop_console: !isDev,
154
+ const_to_let: !isDev,
155
+ booleans_as_integers: !isDev,
156
+ booleans: !isDev,
157
+ // maybe unsafe
158
+ reduce_funcs: !isDev,
159
+ reduce_vars: !isDev,
160
+ },
131
161
  },
132
- },
133
- }),
134
- new core_1.default.LightningCssMinimizerRspackPlugin(),
135
- ],
136
- sideEffects: true,
137
- usedExports: true,
138
- innerGraph: true,
139
- providedExports: true,
140
- mergeDuplicateChunks: true,
141
- splitChunks: false, // 禁用代码分割,保持单文件输出
142
- },
162
+ }),
163
+ new core_1.default.LightningCssMinimizerRspackPlugin(),
164
+ ],
165
+ sideEffects: true,
166
+ usedExports: true,
167
+ innerGraph: true,
168
+ providedExports: true,
169
+ mergeDuplicateChunks: true,
170
+ splitChunks: false, // 禁用代码分割,保持单文件输出
171
+ },
143
172
  devtool: isDev ? 'source-map' : false, // 对应vite的sourcemap配置
144
173
  };
145
174
  }
@@ -40,12 +40,14 @@ function createRecommendTailwindConfig(options) {
40
40
  // 默认扫描外网包依赖
41
41
  const { packageName = '@lark-apaas/miaoda-core' } = options;
42
42
  let pkgPath = '';
43
- try {
44
- // 扫描依赖中的tailwind样式
45
- pkgPath = path.join(path.dirname(require.resolve(packageName)), '/**/*.js');
46
- }
47
- catch (e) {
48
- console.warn(`Failed to resolve package ${packageName}, use default path`);
43
+ if (packageName) {
44
+ try {
45
+ // 扫描依赖中的tailwind样式
46
+ pkgPath = path.join(path.dirname(require.resolve(packageName)), '/**/*.js');
47
+ }
48
+ catch (e) {
49
+ console.warn(`Failed to resolve package ${packageName}, use default path`);
50
+ }
49
51
  }
50
52
  return {
51
53
  darkMode: 'class',
@@ -8,13 +8,14 @@ const path_1 = __importDefault(require("path"));
8
8
  const core_1 = __importDefault(require("@rspack/core"));
9
9
  const rspack_1 = require("./recommend/rspack");
10
10
  const webpack_merge_1 = __importDefault(require("webpack-merge"));
11
+ // 妙搭应用使用的rspack配置
11
12
  // eslint-disable-next-line max-lines-per-function
12
13
  function createRspackConfig(options) {
13
- const { enableReactRefresh = false, isDev = true } = options;
14
- console.log('isDev:', isDev);
14
+ const { enableReactRefresh = false, isDevBuildMode = true } = options;
15
+ console.log('isDevBuildMode:', isDevBuildMode);
15
16
  console.log('enableReactRefresh:', enableReactRefresh);
16
17
  // 构建外部依赖配置,对应vite的rollupOptions.external和globals
17
- const externals = isDev
18
+ const externals = isDevBuildMode
18
19
  ? {
19
20
  antd: 'antd',
20
21
  '@ant-design/icons': 'icons',
@@ -26,10 +27,11 @@ function createRspackConfig(options) {
26
27
  : {};
27
28
  const recommendConfig = (0, rspack_1.createRecommendRspackConfig)({
28
29
  enableReactRefresh,
29
- isDev,
30
+ isDev: isDevBuildMode,
31
+ needRoutes: false,
30
32
  });
31
33
  return (0, webpack_merge_1.default)(recommendConfig, {
32
- mode: isDev ? 'development' : 'production',
34
+ mode: isDevBuildMode ? 'development' : 'production',
33
35
  entry: './src/index.tsx',
34
36
  output: {
35
37
  publicPath: '/',
@@ -60,7 +62,7 @@ function createRspackConfig(options) {
60
62
  },
61
63
  extensions: ['.js', '.jsx', '.ts', '.tsx', '.json'],
62
64
  },
63
- devServer: isDev
65
+ devServer: isDevBuildMode
64
66
  ? undefined
65
67
  : {
66
68
  host: '::',
@@ -90,5 +92,46 @@ function createRspackConfig(options) {
90
92
  },
91
93
  }),
92
94
  ],
95
+ optimization: {
96
+ moduleIds: 'deterministic',
97
+ concatenateModules: true,
98
+ minimize: true, // 对应vite的minify配置
99
+ minimizer: [
100
+ new core_1.default.SwcJsMinimizerRspackPlugin({
101
+ minimizerOptions: {
102
+ // 保持不压缩
103
+ minify: !isDevBuildMode,
104
+ mangle: !isDevBuildMode,
105
+ format: {
106
+ beautify: isDevBuildMode,
107
+ comments: false,
108
+ },
109
+ compress: {
110
+ keep_classnames: true,
111
+ keep_fnames: true,
112
+ keep_fargs: !isDevBuildMode,
113
+ unused: true,
114
+ dead_code: true,
115
+ drop_debugger: true,
116
+ // FIXME: 先临时开始 console.log
117
+ // drop_console: !isDevBuildMode,
118
+ const_to_let: !isDevBuildMode,
119
+ booleans_as_integers: !isDevBuildMode,
120
+ booleans: !isDevBuildMode,
121
+ // maybe unsafe
122
+ reduce_funcs: !isDevBuildMode,
123
+ reduce_vars: !isDevBuildMode,
124
+ },
125
+ },
126
+ }),
127
+ new core_1.default.LightningCssMinimizerRspackPlugin(),
128
+ ],
129
+ sideEffects: true,
130
+ usedExports: true,
131
+ innerGraph: true,
132
+ providedExports: true,
133
+ mergeDuplicateChunks: true,
134
+ splitChunks: false, // 禁用代码分割,保持单文件输出
135
+ },
93
136
  });
94
137
  }
@@ -6,10 +6,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.createTailwindConfig = createTailwindConfig;
7
7
  const webpack_merge_1 = __importDefault(require("webpack-merge"));
8
8
  const tailwind_1 = require("./recommend/tailwind");
9
+ /** 妙搭使用的tailwind配置 */
9
10
  function createTailwindConfig(options) {
10
11
  const { isDevBuildMode = true } = options;
11
12
  const recommendConfig = (0, tailwind_1.createRecommendTailwindConfig)({
12
13
  isDev: isDevBuildMode,
14
+ // 妙搭需要扫描内网包
15
+ packageName: '@byted/spark-framework',
13
16
  });
14
17
  return (0, webpack_merge_1.default)(recommendConfig, {
15
18
  content: ['./src/**/*.{ts,tsx}'],
package/package.json CHANGED
@@ -1,18 +1,33 @@
1
1
  {
2
2
  "name": "@lark-apaas/miaoda-presets",
3
- "version": "0.1.0-alpha.13",
3
+ "version": "0.1.0-alpha.15",
4
4
  "files": [
5
5
  "lib"
6
6
  ],
7
7
  "publishConfig": {
8
8
  "access": "public"
9
9
  },
10
+ "scripts": {
11
+ "build": "tsc && npm run copy:json",
12
+ "copy:json": "cp -r src/*.json lib",
13
+ "watch": "tsc --watch",
14
+ "bump": "changeset version",
15
+ "change": "changeset",
16
+ "check": "biome check --write",
17
+ "dev": "rslib build --watch",
18
+ "format": "biome format --write",
19
+ "storybook": "storybook dev",
20
+ "test": "echo 0",
21
+ "prepublishOnly": "npm run build"
22
+ },
10
23
  "dependencies": {
11
24
  "@babel/core": "^7.28.0",
12
25
  "@babel/parser": "^7.28.0",
13
26
  "@babel/traverse": "^7.28.0",
14
27
  "@babel/types": "^7.28.2",
15
28
  "@eslint/js": "^9.34.0",
29
+ "@lark-apaas/miaoda-inspector-babel-plugin": "workspace:*",
30
+ "@lark-apaas/miaoda-inspector-jsx-runtime": "workspace:*",
16
31
  "@react-dev-inspector/middleware": "^2.0.1",
17
32
  "@rsdoctor/rspack-plugin": "^1.1.8",
18
33
  "@rspack/dev-server": "^1.1.3",
@@ -25,12 +40,11 @@
25
40
  "eslint-plugin-react-refresh": "^0.4.20",
26
41
  "globals": "^15.15.0",
27
42
  "magic-string": "^0.30.18",
43
+ "postcss-import": "^16.1.1",
44
+ "tailwindcss": "^4.1.13",
28
45
  "tsconfig-paths-webpack-plugin": "^4.2.0",
29
46
  "typescript-eslint": "^8.41.0",
30
- "webpack-merge": "^6.0.1",
31
- "tailwindcss": "^4.1.13",
32
- "@lark-apaas/miaoda-inspector-babel-plugin": "0.1.0-alpha.5",
33
- "@lark-apaas/miaoda-inspector-jsx-runtime": "0.1.0-alpha.6"
47
+ "webpack-merge": "^6.0.1"
34
48
  },
35
49
  "devDependencies": {
36
50
  "@babel/parser": "^7.28.4",
@@ -47,17 +61,5 @@
47
61
  "peerDependencies": {
48
62
  "react": ">=16.14.0",
49
63
  "react-dom": ">=16.14.0"
50
- },
51
- "scripts": {
52
- "build": "tsc && npm run copy:json",
53
- "copy:json": "cp -r src/*.json lib",
54
- "watch": "tsc --watch",
55
- "bump": "changeset version",
56
- "change": "changeset",
57
- "check": "biome check --write",
58
- "dev": "rslib build --watch",
59
- "format": "biome format --write",
60
- "storybook": "storybook dev",
61
- "test": "echo 0"
62
64
  }
63
- }
65
+ }