From c814f018143d3488ca0a7418de1197ace9975201 Mon Sep 17 00:00:00 2001 From: richard1015 <51844712@qq.com> Date: Wed, 15 Jun 2022 20:05:09 +0800 Subject: [PATCH] chore: add rollup terser option(drop_console) #1363 --- package.json | 1 + vite.config.build.disperse.ts | 17 ++++++++++------- vite.config.build.locale.ts | 17 ++++++++++------- vite.config.build.taro.vue.disperse.ts | 17 ++++++++++------- vite.config.build.taro.vue.ts | 17 ++++++++++------- vite.config.build.ts | 18 ++++++++++-------- vite.config.jdt.ts | 11 ++++++++++- vite.config.ts | 11 ++++++++++- 8 files changed, 71 insertions(+), 38 deletions(-) diff --git a/package.json b/package.json index 5a398e8899..99ac1811db 100644 --- a/package.json +++ b/package.json @@ -107,6 +107,7 @@ "markdown-it-container": "^3.0.0", "prettier": "^2.0.0", "remark-codesandbox": "^0.10.1", + "rollup-plugin-terser": "^7.0.2", "standard-version": "^9.3.0", "swiper": "6.5.1", "transliteration": "^2.2.0", diff --git a/vite.config.build.disperse.ts b/vite.config.build.disperse.ts index 0f3c7a0b24..0a88c8a25e 100644 --- a/vite.config.build.disperse.ts +++ b/vite.config.build.disperse.ts @@ -4,6 +4,7 @@ import vue from '@vitejs/plugin-vue'; import path from 'path'; import config from './package.json'; import configPkg from './src/config.json'; +import { terser } from 'rollup-plugin-terser'; const banner = `/*! * ${config.name} v${config.version} ${new Date()} @@ -60,12 +61,6 @@ declare module 'vue' { ], build: { minify: false, - terserOptions: { - compress: { - drop_console: true, - drop_debugger: true - } - }, lib: { entry: '', name: 'index', @@ -82,7 +77,15 @@ declare module 'vue' { '@/packages/locale': '../locale/lang' }, dir: path.resolve(__dirname, './dist/packages/_es'), - entryFileNames: '[name].js' + entryFileNames: '[name].js', + plugins: [ + terser({ + compress: { + drop_console: true, + drop_debugger: true + } + }) + ] } }, emptyOutDir: false diff --git a/vite.config.build.locale.ts b/vite.config.build.locale.ts index f782b01602..9cfe9ccf62 100644 --- a/vite.config.build.locale.ts +++ b/vite.config.build.locale.ts @@ -17,6 +17,7 @@ let input = { input[file] = `./src/packages/locale/lang/${file}`; }); import fs from 'fs-extra'; +import { terser } from 'rollup-plugin-terser'; // 构建index.scss 兼容插件市场按需加载插件 fs.outputFile(path.resolve(__dirname, './dist/packages/locale/index.scss'), ' ', 'utf8', (error) => {}); fs.outputFile(path.resolve(__dirname, './dist/packages/locale/lang/index.scss'), ' ', 'utf8', (error) => {}); @@ -34,12 +35,6 @@ export default defineConfig({ ], build: { minify: true, - terserOptions: { - compress: { - drop_console: true, - drop_debugger: true - } - }, lib: { entry: '', name: 'index', @@ -53,7 +48,15 @@ export default defineConfig({ output: { banner, dir: path.resolve(__dirname, './dist/packages/locale/lang'), - entryFileNames: '[name].js' + entryFileNames: '[name].js', + plugins: [ + terser({ + compress: { + drop_console: true, + drop_debugger: true + } + }) + ] } }, emptyOutDir: false diff --git a/vite.config.build.taro.vue.disperse.ts b/vite.config.build.taro.vue.disperse.ts index 5cf3404bb6..c0a4f7a9c0 100644 --- a/vite.config.build.taro.vue.disperse.ts +++ b/vite.config.build.taro.vue.disperse.ts @@ -5,6 +5,7 @@ import path from 'path'; const fs = require('fs-extra'); import config from './package.json'; import configPkg from './src/config.json'; +import { terser } from 'rollup-plugin-terser'; const banner = `/*! * ${config.name} v${config.version} ${new Date()} @@ -62,12 +63,6 @@ declare module 'vue' { ], build: { minify: false, - terserOptions: { - compress: { - drop_console: true, - drop_debugger: true - } - }, lib: { entry: '', name: 'index', @@ -84,7 +79,15 @@ declare module 'vue' { '@/packages/locale': '../locale/lang' }, dir: path.resolve(__dirname, './dist/packages/_es'), - entryFileNames: '[name].js' + entryFileNames: '[name].js', + plugins: [ + terser({ + compress: { + drop_console: true, + drop_debugger: true + } + }) + ] } }, emptyOutDir: false diff --git a/vite.config.build.taro.vue.ts b/vite.config.build.taro.vue.ts index 0d7690e8c4..e1e827ff84 100644 --- a/vite.config.build.taro.vue.ts +++ b/vite.config.build.taro.vue.ts @@ -2,6 +2,7 @@ import { defineConfig } from 'vite'; import vue from '@vitejs/plugin-vue'; import path from 'path'; import config from './package.json'; +import { terser } from 'rollup-plugin-terser'; const banner = `/*! * ${config.name} v${config.version} ${new Date()} @@ -41,12 +42,6 @@ export default defineConfig({ ], build: { minify: false, - terserOptions: { - compress: { - drop_console: true, - drop_debugger: true - } - }, rollupOptions: { // 请确保外部化那些你的库中不需要的依赖 external: ['vue', 'vue-router', '@tarojs/taro'], @@ -55,7 +50,15 @@ export default defineConfig({ // 在 UMD 构建模式下为这些外部化的依赖提供一个全局变量 globals: { vue: 'Vue' - } + }, + plugins: [ + terser({ + compress: { + drop_console: true, + drop_debugger: true + } + }) + ] } }, lib: { diff --git a/vite.config.build.ts b/vite.config.build.ts index c7659a2a74..a4a12039c5 100644 --- a/vite.config.build.ts +++ b/vite.config.build.ts @@ -3,7 +3,7 @@ import dts from 'vite-plugin-dts'; import vue from '@vitejs/plugin-vue'; import path from 'path'; import config from './package.json'; - +import { terser } from 'rollup-plugin-terser'; const banner = `/*! * ${config.name} v${config.version} ${new Date()} * (c) 2022 @jdf2e. @@ -33,12 +33,6 @@ export default defineConfig({ plugins: [vue()], build: { minify: false, - terserOptions: { - compress: { - drop_console: true, - drop_debugger: true - } - }, rollupOptions: { // 请确保外部化那些你的库中不需要的依赖 external: ['vue', 'vue-router'], @@ -47,7 +41,15 @@ export default defineConfig({ // 在 UMD 构建模式下为这些外部化的依赖提供一个全局变量 globals: { vue: 'Vue' - } + }, + plugins: [ + terser({ + compress: { + drop_console: true, + drop_debugger: true + } + }) + ] } }, lib: { diff --git a/vite.config.jdt.ts b/vite.config.jdt.ts index e8b544057c..a461bcfb78 100644 --- a/vite.config.jdt.ts +++ b/vite.config.jdt.ts @@ -6,6 +6,7 @@ import path from 'path'; import config from './package.json'; const hljs = require('highlight.js'); // https://highlightjs.org/ import { compressText } from './src/sites/doc/components/demo-block/basedUtil'; +import { terser } from 'rollup-plugin-terser'; const resolve = path.resolve; // https://vitejs.dev/config/ export default defineConfig({ @@ -100,7 +101,15 @@ export default defineConfig({ output: { entryFileNames: `demo-${config.version}/[name].js`, chunkFileNames: `demo-${config.version}/[name].js`, - assetFileNames: `demo-${config.version}/[name].[ext]` + assetFileNames: `demo-${config.version}/[name].[ext]`, + plugins: [ + terser({ + compress: { + drop_console: true, + drop_debugger: true + } + }) + ] } } } diff --git a/vite.config.ts b/vite.config.ts index d6a06c36c2..c65cebb9d9 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -6,6 +6,7 @@ import path from 'path'; import config from './package.json'; const hljs = require('highlight.js'); // https://highlightjs.org/ import { compressText } from './src/sites/doc/components/demo-block/basedUtil'; +import { terser } from 'rollup-plugin-terser'; const resolve = path.resolve; // https://vitejs.dev/config/ export default defineConfig({ @@ -100,7 +101,15 @@ export default defineConfig({ output: { entryFileNames: `demo-${config.version}/[name].js`, chunkFileNames: `demo-${config.version}/[name].js`, - assetFileNames: `demo-${config.version}/[name].[ext]` + assetFileNames: `demo-${config.version}/[name].[ext]`, + plugins: [ + terser({ + compress: { + drop_console: true, + drop_debugger: true + } + }) + ] } } }