Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(style-inject): 修复node环境下打包style #2791

Merged
merged 5 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions .changeset/good-books-live.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
---
"@hi-ui/env": patch
"@hi-ui/icons": patch
"@hi-ui/alert": patch
"@hi-ui/anchor": patch
"@hi-ui/avatar": patch
"@hi-ui/back-top": patch
"@hi-ui/badge": patch
"@hi-ui/breadcrumb": patch
"@hi-ui/button": patch
"@hi-ui/card": patch
"@hi-ui/carousel": patch
"@hi-ui/cascader": patch
"@hi-ui/check-cascader": patch
"@hi-ui/check-select": patch
"@hi-ui/check-tree-select": patch
"@hi-ui/checkbox": patch
"@hi-ui/collapse": patch
"@hi-ui/counter": patch
"@hi-ui/date-picker": patch
"@hi-ui/descriptions": patch
"@hi-ui/drawer": patch
"@hi-ui/dropdown": patch
"@hi-ui/ellipsis-tooltip": patch
"@hi-ui/empty-state": patch
"@hi-ui/file-select": patch
"@hi-ui/filter": patch
"@hi-ui/form": patch
"@hi-ui/grid": patch
"@hi-ui/highlighter": patch
"@hi-ui/hiui": patch
"@hi-ui/icon-button": patch
"@hi-ui/input": patch
"@hi-ui/input-group": patch
"@hi-ui/list": patch
"@hi-ui/loading": patch
"@hi-ui/locale-context": patch
"@hi-ui/menu": patch
"@hi-ui/message": patch
"@hi-ui/modal": patch
"@hi-ui/notification": patch
"@hi-ui/number-input": patch
"@hi-ui/pagination": patch
"@hi-ui/picker": patch
"@hi-ui/pop-confirm": patch
"@hi-ui/popover": patch
"@hi-ui/popper": patch
"@hi-ui/portal": patch
"@hi-ui/preview": patch
"@hi-ui/progress": patch
"@hi-ui/provider": patch
"@hi-ui/radio": patch
"@hi-ui/rating": patch
"@hi-ui/resize-box": patch
"@hi-ui/result": patch
"@hi-ui/scrollbar": patch
"@hi-ui/search": patch
"@hi-ui/select": patch
"@hi-ui/slider": patch
"@hi-ui/space": patch
"@hi-ui/spinner": patch
"@hi-ui/stepper": patch
"@hi-ui/svg-icon": patch
"@hi-ui/switch": patch
"@hi-ui/table": patch
"@hi-ui/tabs": patch
"@hi-ui/tag": patch
"@hi-ui/tag-input": patch
"@hi-ui/textarea": patch
"@hi-ui/time-picker": patch
"@hi-ui/timeline": patch
"@hi-ui/toast": patch
"@hi-ui/tooltip": patch
"@hi-ui/transfer": patch
"@hi-ui/tree": patch
"@hi-ui/tree-select": patch
"@hi-ui/upload": patch
"@hi-ui/virtual-list": patch
"@hi-ui/watermark": patch
"@hi-ui/zen-mode": patch
"@hi-ui/array-utils": patch
"@hi-ui/classname": patch
"@hi-ui/container": patch
---

build: style-inject(node 环境下有问题) 替换为 @hi-ui/style-inject
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"@babel/preset-typescript": "~7.12.7",
"@changesets/changelog-github": "^0.4.7",
"@changesets/cli": "^2.25.0",
"@hi-ui/hi-build": "4.1.1",
"@hi-ui/hi-build": "4.1.2",
"@storybook/addon-actions": "^6.3.12",
"@storybook/addon-essentials": "^6.3.12",
"@storybook/addon-links": "^6.3.12",
Expand Down
11 changes: 11 additions & 0 deletions packages/others/style-inject/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# `@hi-ui/style-inject`

> TODO: description

## Usage

```
const styleInject = require('@hi-ui/style-inject');

// TODO: DEMONSTRATE API
```
5 changes: 5 additions & 0 deletions packages/others/style-inject/__tests__/style-inject.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const styleInject = require('../src')

describe('@hi-ui/style-inject', () => {
it('needs tests', () => {})
})
1 change: 1 addition & 0 deletions packages/others/style-inject/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('../../../jest.config')
47 changes: 47 additions & 0 deletions packages/others/style-inject/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"name": "@hi-ui/styleinject",
"version": "4.0.0",
"description": "A sub-package for @hi-ui/utils.",
"keywords": [],
"author": "HiUI <[email protected]>",
"homepage": "https://github.com/XiaoMi/hiui/tree/master/packages/utils/style-inject#readme",
"license": "MIT",
"directories": {
"lib": "lib",
"test": "__tests__"
},
"files": [
"lib"
],
"main": "lib/cjs/index.js",
"module": "lib/esm/index.js",
"types": "lib/types/index.d.ts",
"typings": "lib/types/index.d.ts",
"exports": {
".": {
"require": "./lib/cjs/index.js",
"default": "./lib/esm/index.js"
}
},
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "git+https://github.com/XiaoMi/hiui.git"
},
"scripts": {
"test": "jest",
"clean": "rimraf lib",
"prebuild": "yarn clean",
"build:esm": "hi-build ./src/index.ts --format esm -d ./lib/esm",
"build:cjs": "hi-build ./src/index.ts --format cjs -d ./lib/cjs",
"build:types": "tsc --emitDeclarationOnly --declaration --declarationDir lib/types",
"build": "concurrently yarn:build:*"
},
"bugs": {
"url": "https://github.com/XiaoMi/hiui/issues"
},
"devDependencies": {
}
}
21 changes: 21 additions & 0 deletions packages/others/style-inject/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const isBrowser = !!(
typeof window !== 'undefined' &&
window.document &&
window.document.createElement
)

/**
* TODO: What is styleInject
*/
const styleInject = (css: string) => {
if (!css || !isBrowser) return

const head = document.head || document.getElementsByTagName('head')[0]
const style = document.createElement('style')

head.appendChild(style)
style.appendChild(document.createTextNode(css))
}

export default styleInject
export { styleInject }
4 changes: 4 additions & 0 deletions packages/others/style-inject/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "../../../tsconfig.json",
"include": ["./src"]
}
3 changes: 1 addition & 2 deletions packages/utils/env/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
},
"homepage": "https://github.com/XiaoMi/hiui#readme",
"dependencies": {
"inject-head-style": "^1.0.0",
"style-inject": "^0.3.0"
"@hi-ui/style-inject": "^4.0.0"
}
}
4 changes: 2 additions & 2 deletions scripts/hi-build/lib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ const getRollupConfig = (input, outputPath, options, pkg) => {
// Extract styleInject as a external module
inject: !cssExtract ? (variableName) => {
if (isESM) {
return `;import __styleInject__ from 'style-inject';__styleInject__(${variableName});`
return `;import __styleInject__ from '@hi-ui/style-inject';__styleInject__(${variableName});`
}
return `;var __styleInject__=require('style-inject').default;__styleInject__(${variableName});`
return `;var __styleInject__=require('@hi-ui/style-inject').default;__styleInject__(${variableName});`
} : false,
extract: cssExtract,
modules: cssModules,
Expand Down
5 changes: 1 addition & 4 deletions scripts/hi-build/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hi-ui/hi-build",
"version": "4.1.1",
"version": "4.1.2",
"description": "Now I’m the model of a modern major general / The venerated Virginian veteran whose men are all / Lining up, to put me up on a pedestal / Writin’ letters to relatives / Embellishin’ my elegance and eloquence / But the elephant is in the room / The truth is in ya face when ya hear the British cannons go / BOOM",
"keywords": [],
"author": "Flcwl <[email protected]>",
Expand Down Expand Up @@ -64,8 +64,5 @@
},
"peerDependencies": {
"typescript": "^4.6.2"
},
"devDependencies": {
"@hi-ui/hi-build": "^4.1.1"
}
}
18 changes: 9 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2680,10 +2680,10 @@
minimatch "^3.0.4"
strip-json-comments "^3.1.1"

"@hi-ui/[email protected].1":
version "4.1.1"
resolved "https://registry.npmmirror.com/@hi-ui/hi-build/-/hi-build-4.1.1.tgz#1b586ca597c358ebb9c974433e488f02b61ef7bf"
integrity sha512-cXMJVsdhTjZizcSvH8fl9w2M5zUdBFUO/cEobzUTK2aKY4ia+ZVQ8OPSKbR5vbYn2d+j/7YwdXVg9novdnu9uw==
"@hi-ui/[email protected].2":
version "4.1.2"
resolved "https://registry.npmjs.org/@hi-ui/hi-build/-/hi-build-4.1.2.tgz#0125cac22a7b53a92146a405fe0eb3c33da08a0e"
integrity sha512-el7cyqRt6CRUAe6X/RzWImAppdDJtnIIzlxol1Oc1AwIXrwPfYzSjtVsibE5IeuATRhlhzEVswem9hngqn5jJQ==
dependencies:
"@babel/core" "^7.17.8"
"@babel/plugin-transform-runtime" "^7.17.0"
Expand Down Expand Up @@ -2715,6 +2715,11 @@
rollup-plugin-terser "^7.0.2"
rollup-plugin-visualizer "^5.9.2"

"@hi-ui/style-inject@^4.0.0":
version "4.0.0"
resolved "https://registry.npmjs.org/@hi-ui/style-inject/-/style-inject-4.0.0.tgz#62e3ecff2654e5149cd310db8ba8fbe078020bd3"
integrity sha512-f/WDX/a10y08gYY9UaSwX0V0CbLDxlzf/6UrwD8fZIyIPdlyrR3Jld8X18vz5zywxPTpOPwBQLf9PYZ9YdFMPA==

"@humanwhocodes/config-array@^0.5.0":
version "0.5.0"
resolved "https://registry.yarnpkg.com/@humanwhocodes/config-array/-/config-array-0.5.0.tgz#1407967d4c6eecd7388f83acf1eaf4d0c6e58ef9"
Expand Down Expand Up @@ -10601,11 +10606,6 @@ init-package-json@^2.0.2:
validate-npm-package-license "^3.0.4"
validate-npm-package-name "^3.0.0"

inject-head-style@^1.0.0:
version "1.0.0"
resolved "https://registry.npmmirror.com/inject-head-style/-/inject-head-style-1.0.0.tgz#159f843900d3f473fb691c67fce52b5d088f5f68"
integrity sha512-J6eyVFIiY3SgvguiUx/XXBZWTIxMryhiSosH2fan5+FhfA4LlNJkybUcYsINInM+zvsBmcrIHVWJxvi4lvjwqA==

[email protected]:
version "0.1.1"
resolved "https://registry.npm.taobao.org/inline-style-parser/download/inline-style-parser-0.1.1.tgz#ec8a3b429274e9c0a1f1c4ffa9453a7fef72cea1"
Expand Down