@fibrae/semi-next 0.0.0-stage → 0.1.1
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/LICENSE +84 -0
- package/README.md +82 -2
- package/dist/index.d.mts +3 -0
- package/dist/index.mjs +73 -0
- package/package.json +31 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 DouyinFE
|
|
4
|
+
Copyright (c) 2026 smile-alive
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
|
23
|
+
|
|
24
|
+
The code implementation of the external library is referenced by DouyinFe are:
|
|
25
|
+
|
|
26
|
+
- animate.css
|
|
27
|
+
|
|
28
|
+
The MIT License (MIT)
|
|
29
|
+
|
|
30
|
+
Copyright (c) 2020 Daniel Eden
|
|
31
|
+
|
|
32
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
33
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
34
|
+
in the Software without restriction, including without limitation the rights
|
|
35
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
36
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
37
|
+
furnished to do so, subject to the following conditions:
|
|
38
|
+
|
|
39
|
+
The above copyright notice and this permission notice shall be included in all
|
|
40
|
+
copies or substantial portions of the Software.
|
|
41
|
+
|
|
42
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
43
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
44
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
45
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
46
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
47
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
48
|
+
SOFTWARE.
|
|
49
|
+
|
|
50
|
+
- Ant Design
|
|
51
|
+
MIT LICENSE
|
|
52
|
+
|
|
53
|
+
Copyright (c) 2015-present Ant UED, https://xtech.antfin.com/
|
|
54
|
+
|
|
55
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
56
|
+
a copy of this software and associated documentation files (the
|
|
57
|
+
"Software"), to deal in the Software without restriction, including
|
|
58
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
59
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
60
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
61
|
+
the following conditions:
|
|
62
|
+
|
|
63
|
+
The above copyright notice and this permission notice shall be
|
|
64
|
+
included in all copies or substantial portions of the Software.
|
|
65
|
+
|
|
66
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
67
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
68
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
69
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
70
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
71
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
72
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
73
|
+
|
|
74
|
+
- rc-tree
|
|
75
|
+
|
|
76
|
+
MIT LICENSE
|
|
77
|
+
|
|
78
|
+
Copyright (c) 2015-present Alipay.com, https://www.alipay.com/
|
|
79
|
+
|
|
80
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
81
|
+
|
|
82
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
83
|
+
|
|
84
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,83 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @fibrae/semi-next
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Semi Design Next 的 Next.js 构建插件,给使用 Semi React 组件包的 Next.js 应用用。Semi 的组件 JS 会导入自己的 `.css`;插件让这些导入在 Turbopack、Pages Router 与自定义前缀下也能构建和服务端渲染。包名中的 next 指 Next.js。
|
|
4
|
+
|
|
5
|
+
## 何时需要
|
|
6
|
+
|
|
7
|
+
| 场景 | 写法 |
|
|
8
|
+
| ------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- |
|
|
9
|
+
| App Router,`next dev --webpack`、`next build --webpack` | 不需要本插件,装 `@fibrae/semi-ui-react` 即可 |
|
|
10
|
+
| Next.js 16 默认的 Turbopack、Pages Router,或两种 Router 混用 | `semiNext()`,样式无需另外导入 |
|
|
11
|
+
| 自定义类名前缀 | `semiNext({ prefixCls: 'my', omitCss: true })`,再导入一次 `semi-build-scss --prefix my` 生成的样式表 |
|
|
12
|
+
|
|
13
|
+
## 安装
|
|
14
|
+
|
|
15
|
+
```shell
|
|
16
|
+
pnpm add -D @fibrae/semi-next
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
仅提供 ESM。依赖 [`@fibrae/semi-webpack-plugin`](../semi-webpack/README.md);`next` 由应用自带。
|
|
20
|
+
|
|
21
|
+
## 使用
|
|
22
|
+
|
|
23
|
+
### Turbopack 与 Pages Router
|
|
24
|
+
|
|
25
|
+
```js
|
|
26
|
+
// next.config.mjs
|
|
27
|
+
import semiNext from '@fibrae/semi-next';
|
|
28
|
+
|
|
29
|
+
export default semiNext()({
|
|
30
|
+
// 你的 Next.js 配置
|
|
31
|
+
});
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
组件按需带出自己的样式,不导入 `styles.css`。`semiNext(options)` 返回 `(nextConfig) => nextConfig`,在你的配置上:
|
|
35
|
+
|
|
36
|
+
- 把 `@fibrae/semi-ui-react`、`@fibrae/semi-ai-react`、`@fibrae/semi-icons-react`、`@fibrae/semi-illustrations-react` 合并进 `transpilePackages`:Pages Router 的服务端用 Node 直接加载 `node_modules`,而 Node 不能导入 `.css`。
|
|
37
|
+
- 加 `turbopack.rules`:`omitCss`、`prefixCls` 时给 Semi 的 JS 挂对应 loader。你已有的其他规则保留;与插件同 glob 的规则(`*.js`)抛错,请改用别的 glob。
|
|
38
|
+
- 加 `webpack()`:`--webpack` 下按选项挂 `SemiWebpackPlugin`,再调用你原有的 `webpack` 函数;不传选项时不挂插件,Next 直接处理组件导入的 `.css`。
|
|
39
|
+
|
|
40
|
+
Next.js 16 在 Turbopack 下遇到只有 `webpack` 键的配置会报错退出,所以两个键总是一起返回。
|
|
41
|
+
|
|
42
|
+
### 自定义前缀
|
|
43
|
+
|
|
44
|
+
```js
|
|
45
|
+
// next.config.mjs
|
|
46
|
+
import semiNext from '@fibrae/semi-next';
|
|
47
|
+
|
|
48
|
+
export default semiNext({ prefixCls: 'my', omitCss: true })({});
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
`omitCss` 去掉 Semi 包内的 `.css` 导入,`prefixCls` 改写 Semi JS 里的类名前缀。样式改由一份带同样前缀的完整样式表提供,用 [`@fibrae/semi-scss-compile`](../semi-scss-compile/README.md) 生成后在根 layout(Pages Router 为 `pages/_app`)导入一次:
|
|
52
|
+
|
|
53
|
+
```shell
|
|
54
|
+
pnpm add -D @fibrae/semi-scss-compile
|
|
55
|
+
semi-build-scss --prefix my -o app/semi-my.css --min
|
|
56
|
+
# 使用 @fibrae/semi-ai-react 时另装 -D @fibrae/semi-ai-foundation,在 app/semi-my.css 之后导入
|
|
57
|
+
semi-build-scss --ai node_modules/@fibrae/semi-ai-foundation/dist -o app/semi-ai-my.css --min --prefix my
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
`prefixCls` 必须配 `omitCss: true`,否则读取配置时抛错(Turbopack 不能重编译 Semi 的 SCSS,`--webpack` 下重编译会与 Next 自己的样式规则冲突)。
|
|
61
|
+
|
|
62
|
+
## 选项
|
|
63
|
+
|
|
64
|
+
选项即 [`@fibrae/semi-webpack-plugin`](../semi-webpack/README.md) 的 `SemiWebpackPluginOptions`(本包导出别名类型 `SemiNextOptions`)。
|
|
65
|
+
|
|
66
|
+
| 选项 | 类型 | 默认值 | 说明 |
|
|
67
|
+
| ------------------------------------------------------------ | --------- | ------- | ---------------------------------------------------------------------------------- |
|
|
68
|
+
| `omitCss` | `boolean` | `false` | 去掉 Semi 包内的 `.css` 导入,样式改由应用导入的完整样式表提供。 |
|
|
69
|
+
| `prefixCls` | `string` | `semi` | 类名前缀,必须与所导入样式表的前缀一致。必须配 `omitCss: true`。 |
|
|
70
|
+
| `cssLayer`、`extractCssOptions`、`overrideStylesheetLoaders` | - | - | 重编译 SCSS 的选项,只在 `--webpack` 下传给 webpack 插件;Turbopack 下传入即抛错。 |
|
|
71
|
+
|
|
72
|
+
插件判断打包器靠 Next 在读取 `next.config` 前设置的 `process.env.TURBOPACK`:默认打包器为 `auto`,`--turbopack` 为 `1`,`--webpack` 与 `next start` 下未设置。
|
|
73
|
+
|
|
74
|
+
已知限制:Next.js 16.4.3 的 `--webpack` 下,`cssLayer` 触发的 webpack 插件重编译 SCSS 与 Next 自己的样式规则冲突,构建报 `Invalid generator object`;`extractCssOptions`、`overrideStylesheetLoaders` 未验证。
|
|
75
|
+
|
|
76
|
+
Turbopack 的 `*.css` 规则不改变模块类型,应用自己的 `*.module.css` 仍按 CSS Modules 处理。
|
|
77
|
+
|
|
78
|
+
## 开发
|
|
79
|
+
|
|
80
|
+
- `pnpm --filter @fibrae/semi-next build`:`vp pack` 构建。
|
|
81
|
+
- `pnpm --filter @fibrae/semi-next test`:先构建,再用 `test/run.ts` 验证返回的 `transpilePackages`、`turbopack.rules`(loader 路径指向已发布文件,`*.css` 规则不带 `as` 以保留 CSS Modules)、`webpack()` 何时挂插件,以及 `prefixCls` 与 Turbopack 下的选项校验。
|
|
82
|
+
|
|
83
|
+
通用命令见根目录 [README.md](../../README.md) 的「常用命令」。
|
package/dist/index.d.mts
ADDED
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import SemiWebpackPlugin from "@fibrae/semi-webpack-plugin";
|
|
3
|
+
// src/index.ts
|
|
4
|
+
const require = createRequire(import.meta.url);
|
|
5
|
+
const TRANSPILE_PACKAGES = [
|
|
6
|
+
"@fibrae/semi-ui-react",
|
|
7
|
+
"@fibrae/semi-ai-react",
|
|
8
|
+
"@fibrae/semi-icons-react",
|
|
9
|
+
"@fibrae/semi-illustrations-react"
|
|
10
|
+
];
|
|
11
|
+
function loader(name) {
|
|
12
|
+
return require.resolve(`@fibrae/semi-webpack-plugin/${name}`);
|
|
13
|
+
}
|
|
14
|
+
function turbopackRules({ omitCss, prefixCls }) {
|
|
15
|
+
const js = [];
|
|
16
|
+
if (omitCss) js.push({
|
|
17
|
+
condition: { path: /@fibrae\/semi-(ui|ai|icons)-react\/dist\// },
|
|
18
|
+
loaders: [loader("semi-omit-css-loader")]
|
|
19
|
+
});
|
|
20
|
+
if (prefixCls) js.push({
|
|
21
|
+
condition: { path: /@fibrae\/semi-[^/]+\/.+env\.js$/ },
|
|
22
|
+
loaders: [{
|
|
23
|
+
loader: loader("semi-prefix-loader"),
|
|
24
|
+
options: { replacers: { BASE_CLASS_PREFIX: prefixCls } }
|
|
25
|
+
}]
|
|
26
|
+
});
|
|
27
|
+
return js.length > 0 ? { "*.js": js } : {};
|
|
28
|
+
}
|
|
29
|
+
function assertTurbopackOptions({ cssLayer, extractCssOptions, overrideStylesheetLoaders }) {
|
|
30
|
+
const webpackOnly = Object.entries({
|
|
31
|
+
cssLayer,
|
|
32
|
+
extractCssOptions,
|
|
33
|
+
overrideStylesheetLoaders
|
|
34
|
+
}).find(([, value]) => value !== void 0);
|
|
35
|
+
if (webpackOnly) throw new Error(`semi-next: ${webpackOnly[0]} only works with webpack; run Next with --webpack or remove it`);
|
|
36
|
+
}
|
|
37
|
+
function semiNext(options = {}) {
|
|
38
|
+
const { omitCss = false, ...restOptions } = options;
|
|
39
|
+
return (nextConfig = {}) => {
|
|
40
|
+
if (restOptions.prefixCls && !omitCss) throw new Error("semi-next: prefixCls needs omitCss: true and a stylesheet built by semi-build-scss --prefix");
|
|
41
|
+
if (process.env.TURBOPACK) assertTurbopackOptions({
|
|
42
|
+
omitCss,
|
|
43
|
+
...restOptions
|
|
44
|
+
});
|
|
45
|
+
const userRules = nextConfig.turbopack?.rules ?? {};
|
|
46
|
+
const semiRules = turbopackRules({
|
|
47
|
+
omitCss,
|
|
48
|
+
...restOptions
|
|
49
|
+
});
|
|
50
|
+
const clash = Object.keys(semiRules).find((glob) => Object.hasOwn(userRules, glob));
|
|
51
|
+
if (clash) throw new Error(`semi-next: turbopack.rules["${clash}"] is set by semi-next; match your files with another glob`);
|
|
52
|
+
return {
|
|
53
|
+
...nextConfig,
|
|
54
|
+
transpilePackages: [.../* @__PURE__ */ new Set([...nextConfig.transpilePackages ?? [], ...TRANSPILE_PACKAGES])],
|
|
55
|
+
turbopack: {
|
|
56
|
+
...nextConfig.turbopack,
|
|
57
|
+
rules: {
|
|
58
|
+
...userRules,
|
|
59
|
+
...semiRules
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
webpack(config, context) {
|
|
63
|
+
if (omitCss || Object.keys(restOptions).length > 0) config.plugins.push(new SemiWebpackPlugin({
|
|
64
|
+
omitCss,
|
|
65
|
+
...restOptions
|
|
66
|
+
}));
|
|
67
|
+
if (typeof nextConfig.webpack === "function") return nextConfig.webpack(config, context);
|
|
68
|
+
return config;
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
export { semiNext as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fibrae/semi-next",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Plugin that support Semi Design Next in Next.js",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"homepage": "https://semi-design-next.pages.dev",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/smile-alive/semi-design-next.git",
|
|
10
|
+
"directory": "packages/semi-next"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/smile-alive/semi-design-next/issues"
|
|
14
|
+
},
|
|
15
|
+
"type": "module",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": "./dist/index.mjs",
|
|
18
|
+
"./package.json": "./package.json"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist",
|
|
22
|
+
"README.md"
|
|
23
|
+
],
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"typescript": "^6.0.3"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@fibrae/semi-webpack-plugin": "0.1.1"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "vp pack",
|
|
32
|
+
"test": "vp pack && node test/run.ts"
|
|
33
|
+
}
|
|
6
34
|
}
|