diff --git a/plugins/plugin-vue/plugin.js b/plugins/plugin-vue/plugin.js index e1fa048f1f..3ec85e339c 100644 --- a/plugins/plugin-vue/plugin.js +++ b/plugins/plugin-vue/plugin.js @@ -108,6 +108,10 @@ module.exports = function plugin(snowpackConfig) { if (sourceMaps && js.map) output['.js'].map += JSON.stringify(js.map); } + // clean up + if (!output['.js'].code) delete output['.js']; + if (!output['.css'].code) delete output['.css']; + return output; }, }; diff --git a/plugins/plugin-vue/test/__snapshots__/plugin-vue-ts-tsx-jsx.test.js.snap b/plugins/plugin-vue/test/__snapshots__/plugin-vue-ts-tsx-jsx.test.js.snap index 6e9a5aa518..1945f41efe 100644 --- a/plugins/plugin-vue/test/__snapshots__/plugin-vue-ts-tsx-jsx.test.js.snap +++ b/plugins/plugin-vue/test/__snapshots__/plugin-vue-ts-tsx-jsx.test.js.snap @@ -2,10 +2,6 @@ exports[`plugin vue with jsx 1`] = ` Object { - ".css": Object { - "code": "", - "map": "", - }, ".js": Object { "code": "import { Fragment } from 'vue'; import {createVNode, isVNode} from 'vue'; @@ -31,10 +27,6 @@ export default defineComponent({ exports[`plugin vue with ts 1`] = ` Object { - ".css": Object { - "code": "", - "map": "", - }, ".js": Object { "code": "import {defineComponent} from \\"vue\\"; const defaultExport = defineComponent({ @@ -58,10 +50,6 @@ export default defaultExport", exports[`plugin vue with tsx 1`] = ` Object { - ".css": Object { - "code": "", - "map": "", - }, ".js": Object { "code": "import { Fragment } from 'vue'; import {createVNode, isVNode} from 'vue'; diff --git a/plugins/plugin-vue/test/__snapshots__/plugin.test.js.snap b/plugins/plugin-vue/test/__snapshots__/plugin.test.js.snap index ceac50242f..07df9a2a36 100644 --- a/plugins/plugin-vue/test/__snapshots__/plugin.test.js.snap +++ b/plugins/plugin-vue/test/__snapshots__/plugin.test.js.snap @@ -87,10 +87,6 @@ export default defaultExport", exports[`plugin base only tpl 1`] = ` Object { - ".css": Object { - "code": "", - "map": "", - }, ".js": Object { "code": "const defaultExport = {}; import { createVNode as _createVNode, openBlock as _openBlock, createBlock as _createBlock } from \\"vue\\" diff --git a/snowpack/src/build/build-pipeline.ts b/snowpack/src/build/build-pipeline.ts index 859d08ad3e..8169bf7466 100644 --- a/snowpack/src/build/build-pipeline.ts +++ b/snowpack/src/build/build-pipeline.ts @@ -1,7 +1,12 @@ import path from 'path'; import {validatePluginLoadResult} from '../config'; import {logger} from '../logger'; -import {SnowpackBuildMap, SnowpackConfig, SnowpackPlugin, PluginTransformResult} from '../types/snowpack'; +import { + SnowpackBuildMap, + SnowpackConfig, + SnowpackPlugin, + PluginTransformResult, +} from '../types/snowpack'; import {getExt, readFile, replaceExt} from '../util'; import {SourceMapConsumer, SourceMapGenerator, RawSourceMap} from 'source-map'; @@ -84,6 +89,9 @@ async function runPipelineLoadStep( // if source maps disabled, don’t return any if (!sourceMaps) result[ext].map = undefined; + + // clean up empty files + if (!result[ext].code) delete result[ext]; }); return result; } @@ -101,10 +109,14 @@ async function runPipelineLoadStep( }; } -async function composeSourceMaps(id: string, base: string | RawSourceMap, derived: string | RawSourceMap) : Promise { +async function composeSourceMaps( + id: string, + base: string | RawSourceMap, + derived: string | RawSourceMap, +): Promise { const [baseMap, transformedMap] = await Promise.all([ new SourceMapConsumer(base), - new SourceMapConsumer(derived) + new SourceMapConsumer(derived), ]); try { const generator = SourceMapGenerator.fromSourceMap(transformedMap); @@ -159,12 +171,17 @@ async function runPipelineTransformStep( // V2 API, simple string variant output[destExt].code = result; output[destExt].map = undefined; - } else if (result && typeof result === 'object' && (result as PluginTransformResult).contents) { + } else if ( + result && + typeof result === 'object' && + (result as PluginTransformResult).contents + ) { // V2 API, structured result variant output[destExt].code = (result as PluginTransformResult).contents; const map = (result as PluginTransformResult).map; let outputMap: string | undefined = undefined; - if (map && sourceMaps) { // if source maps disabled, don’t return any + if (map && sourceMaps) { + // if source maps disabled, don’t return any if (output[destExt].map) { outputMap = await composeSourceMaps(filePath, output[destExt].map!, map); } else { @@ -172,9 +189,13 @@ async function runPipelineTransformStep( } } output[destExt].map = outputMap; - } else if (result && typeof result === 'object' && (result as unknown as {result: string}).result) { + } else if ( + result && + typeof result === 'object' && + ((result as unknown) as {result: string}).result + ) { // V1 API, deprecated - output[destExt].code = (result as unknown as {result: string}).result; + output[destExt].code = ((result as unknown) as {result: string}).result; output[destExt].map = undefined; } }