UNPKG

vscode-nls-dev

Version:

Development time npm module to generate strings bundles from Javascript files

45 lines 1.89 kB
/* -------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. * ------------------------------------------------------------------------------------------ */ 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.NLSBundlePlugin = void 0; const lib_1 = require("./lib"); class NLSBundlePlugin { constructor(id) { this.id = id; } apply(compiler) { compiler.hooks.emit.tap('NLSBundlePlugin', (compilation) => { const assets = {}; const bundler = new lib_1.MetaDataBundler(this.id, 'dist'); for (const name of Object.keys(compilation.assets)) { if (!/nls\.metadata\.json$/.test(name)) { assets[name] = compilation.assets[name]; continue; } const json = JSON.parse(compilation.assets[name].source().toString('utf8')); bundler.add(json); } // Skip empty NLS files if (bundler.size === 0) { return; } const [header, content] = bundler.bundle(); const rawHeader = JSON.stringify(header); const rawContent = JSON.stringify(content); assets['nls.metadata.header.json'] = { source() { return rawHeader; }, size() { return rawHeader.length; } }; assets['nls.metadata.json'] = { source() { return rawContent; }, size() { return rawContent.length; } }; compilation.assets = assets; }); } } exports.NLSBundlePlugin = NLSBundlePlugin; //# sourceMappingURL=webpack-bundler.js.map