From a25a3d577d23c23db99a1bd604032fd55258036f Mon Sep 17 00:00:00 2001 From: oasis Date: Thu, 14 Nov 2024 16:40:07 +0800 Subject: [PATCH] chore: harmonyOS supports global stylesheets --- packages/nutui-taro-demo/config/index.js | 5 +-- .../nutui-taro-demo/plugins/inject-scss.js | 39 ------------------- 2 files changed, 2 insertions(+), 42 deletions(-) delete mode 100644 packages/nutui-taro-demo/plugins/inject-scss.js diff --git a/packages/nutui-taro-demo/config/index.js b/packages/nutui-taro-demo/config/index.js index 18f1e28a4a..b3968fc8e6 100644 --- a/packages/nutui-taro-demo/config/index.js +++ b/packages/nutui-taro-demo/config/index.js @@ -1,5 +1,4 @@ const path = require('path') -const injectScss = require('../plugins/inject-scss') let fileStr = `src/styles/variables.scss` let themeStr = `src/styles/theme-default.scss` @@ -71,7 +70,7 @@ const config = { }, sourceRoot: 'src', outputRoot: `dist/${process.env.TARO_ENV === 'h5' ? 'demo' : process.env.TARO_ENV}`, - plugins: [path.resolve(__dirname, '../plugins/inject-scss.js'), ...plugins], + plugins: [...plugins], compiler: 'webpack5', alias: process.env.TARO_ENV === 'rn' || process.env.TARO_ENV === 'jdrn' @@ -129,7 +128,7 @@ const config = { }, }, // 将编译方式设置为使用 Vite 编译 - compiler: { type: 'vite', vitePlugins: [injectScss()] }, + compiler: { type: 'vite' }, // 【必填】鸿蒙主应用的绝对路径,例如: projectPath: path.resolve( process.cwd(), diff --git a/packages/nutui-taro-demo/plugins/inject-scss.js b/packages/nutui-taro-demo/plugins/inject-scss.js deleted file mode 100644 index 697ead72c5..0000000000 --- a/packages/nutui-taro-demo/plugins/inject-scss.js +++ /dev/null @@ -1,39 +0,0 @@ -const { readFileSync } = require('node:fs') -const path = require('path') -const configJson = require('../../../src/config.json') - -const logPrefix = 'inject-scss-for-harmony' -const components = configJson.nav.map(nav => nav.packages.map(package => package.name.toLowerCase())).flat() - -function injectScss() { - return { - enforce: 'pre', - name: logPrefix, - async load(id) { - let find = -1 - components.forEach((component, index) => { - if (id.indexOf('/' + component + '.taro') > -1 && component !== 'icon') { - find = index - return - } - }) - if (find !== -1) { - const filePath = path.resolve(process.cwd(), id) - const code = await readFileSync(filePath, 'utf-8') - // 因为构建了 *.harmony.css 文件,所以需要将 import scss 改为 import css - // const modifiedCode = `import "./${components[find]}.scss"\n` + code - - const modifiedCode = `import "./${components[find]}.harmony.css"\n` + code - // - // const modifiedCode = ` - // import '../../styles/theme-default.scss'\n - // import '../../styles/variables.scss'\n - // import "./${components[find]}.scss"\n` + code - - return modifiedCode - } - }, - } -} - -module.exports = injectScss