From 7a5e3f9bcc1d67d212a139d18d7a3de9ceb450d6 Mon Sep 17 00:00:00 2001 From: 07akioni <07akioni2@gmail.com> Date: Mon, 7 Dec 2020 23:49:32 +0800 Subject: [PATCH] fix: external fonts are not included (due to side effects https://github.com/rollup/plugins/issues/692) --- build/clear-side-effects.js | 8 ++++++++ build/restore-side-effects.js | 8 ++++++++ package.json | 6 +++--- vue3.md | 2 +- 4 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 build/clear-side-effects.js create mode 100644 build/restore-side-effects.js diff --git a/build/clear-side-effects.js b/build/clear-side-effects.js new file mode 100644 index 000000000..7cec035e5 --- /dev/null +++ b/build/clear-side-effects.js @@ -0,0 +1,8 @@ +const packageJson = require('../package.json') + +packageJson.sideEffects = false + +require('fs-extra').writeFileSync( + require('path').resolve(__dirname, '..', 'package.json'), + JSON.stringify(packageJson, 0, 2) + '\n' +) diff --git a/build/restore-side-effects.js b/build/restore-side-effects.js new file mode 100644 index 000000000..6cebb2466 --- /dev/null +++ b/build/restore-side-effects.js @@ -0,0 +1,8 @@ +const packageJson = require('../package.json') + +delete packageJson.sideEffects + +require('fs-extra').writeFileSync( + require('path').resolve(__dirname, '..', 'package.json'), + JSON.stringify(packageJson, 0, 2) + '\n' +) diff --git a/package.json b/package.json index 200e924b9..39353ba78 100644 --- a/package.json +++ b/package.json @@ -4,13 +4,12 @@ "description": "A Vue UI Framework. Caring About Styles, Themed, Batteries Included, Not Rather Slow.", "main": "lib/index.js", "module": "es/index.js", - "sideEffects": false, "scripts": { "start": "npm run dev", "deprecated:build:icons": "npm run clean && node build/build-icons.js", "build:js": "npm run gen-version && npm run clean && node build/before-build.js && rollup -c", "build:package": "npm run gen-version && npm run clean && node build/build-icons.js && node build/before-build.js && rollup -c", - "build:site": "npm run build:package && ./build/before-build-site.sh && cross-env NODE_ENV=production NODE_OPTIONS=--max-old-space-size=4096 vite build && rm -rf node_modules/naive-ui && cp site/index.html site/404.html", + "build:site": "npm run build:package && ./build/before-build-site.sh && node build/restore-side-effects.js && cross-env NODE_ENV=production NODE_OPTIONS=--max-old-space-size=4096 vite build && rm -rf node_modules/naive-ui && cp site/index.html site/404.html && node build/clear-side-effects.js", "build:doc": "npm run gen-version && npm run build && rm -rf build-doc/dist && cross-env NODE_ENV=production webpack --config build/webpack.doc.js", "clean": "rm -rf site lib es src-mirror node_modules/naive-ui", "dev": "npm run clean && npm run gen-version && cross-env NODE_ENV=development vite", @@ -95,5 +94,6 @@ "vooks": "^0.0.6", "vue": "^3.0.4", "vueuc": "^0.0.1" - } + }, + "sideEffects": false } diff --git a/vue3.md b/vue3.md index 0e25cc567..54b13e01d 100644 --- a/vue3.md +++ b/vue3.md @@ -355,7 +355,7 @@ - [x] chrome date-picker overflow (focus({ preventScroll })) - [x] slider 键盘好像会激活不该激活的 tooltip... - [x] transfer 打包之后有问题 - - [x] side effects = false 好像会影响 rollup 的打包(这让我很不安,要是生效 css 怎么办?要是不生效 JS 怎么办?) https://github.com/rollup/plugins/issues/692 + - [x] side effects = false 好像会影响 rollup 的打包(这让我很不安,要是生效 css 怎么办?要是不生效 JS 怎么办?)(事实上确实会影响网站对于 fonts 的打包,只能先靠脚本凑活一下) https://github.com/rollup/plugins/issues/692 - [x] vue 在 $attrs 的处理上 dev 和 prod 还是有差别 https://github.com/vuejs/vue-next/issues/2741 ## Info