From dfd7ac2aec815a0cab98908e34231646cad7fa07 Mon Sep 17 00:00:00 2001 From: hongrunhui <15755191035@163.com> Date: Sat, 17 Jun 2023 06:44:29 +0000 Subject: [PATCH] feat(build): add source when build --- scripts/build.js | 8 +++++++- scripts/config.js | 3 ++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/scripts/build.js b/scripts/build.js index 2468512af4c..2389c20cc3c 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -41,7 +41,13 @@ function buildEntry (config) { const isProd = /(min|prod)\.js$/.test(file) return rollup.rollup(config) .then(bundle => bundle.generate(output)) - .then(async ({ output: [{ code }] }) => { + .then(async ({ output: [{ code, map }] }) => { + const hasMap = !!map; + const filename = file.split('/').pop(); + if (hasMap) { + code = code + `\n//# sourceMappingURL=${filename}.map`; + write(`${file}.map`, JSON.stringify(map)); + } if (isProd) { const {code: minifiedCode} = await terser.minify(code, { toplevel: true, diff --git a/scripts/config.js b/scripts/config.js index e9f519853f1..5f9eae14cda 100644 --- a/scripts/config.js +++ b/scripts/config.js @@ -258,7 +258,8 @@ function genConfig(name) { format: opts.format, banner: opts.banner, name: opts.moduleName || 'Vue', - exports: 'auto' + exports: 'auto', + sourcemap: !!process.env.SOURCE_MAP }, onwarn: (msg, warn) => { if (!/Circular/.test(msg)) {