How to use the svg-sprite-loader/lib/utils/stringify.js function in svg-sprite-loader

To help you get started, we’ve selected a few svg-sprite-loader examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github zuzucheFE / guido / lib / utils / svgSpriteRuntimeGenerator.js View on Github external
let runtime;
	let symbolId = symbol.id.replace('--sprite', '');

	if (extract) {
		const spritePlaceholder = generateSpritePlaceholder(
			symbol.request.file
		);
		const publicPath = stringify(publicPath) || '__webpack_public_path__';

		const viewBoxParts = symbol.viewBox.split(' ');
		const width = parseInt(viewBoxParts[2], 10);
		const height = parseInt(viewBoxParts[3], 10);

		const data = `{
            id: ${stringify(symbolId)},
            viewBox: ${stringify(symbol.viewBox)},
            url: ${publicPath} + ${stringify(spritePlaceholder)},
            width: ${width},
            height: ${height},
            toString: function () {
                return this.url;
            }
        }`;

		runtime = generateExport(data, esModule);
	} else {
		const spriteModuleAbsPath = path.isAbsolute(spriteModule)
			? spriteModule
			: path.join(context, spriteModule);
		const symbolModuleAbsPath = path.isAbsolute(symbolModule)
			? symbolModule
github zuzucheFE / guido / lib / utils / svgSpriteRuntimeGenerator.js View on Github external
extract,
		esModule,
		spriteModule,
		symbolModule,
		runtimeCompat,
		publicPath,
	} = config;

	let runtime;
	let symbolId = symbol.id.replace('--sprite', '');

	if (extract) {
		const spritePlaceholder = generateSpritePlaceholder(
			symbol.request.file
		);
		const publicPath = stringify(publicPath) || '__webpack_public_path__';

		const viewBoxParts = symbol.viewBox.split(' ');
		const width = parseInt(viewBoxParts[2], 10);
		const height = parseInt(viewBoxParts[3], 10);

		const data = `{
            id: ${stringify(symbolId)},
            viewBox: ${stringify(symbol.viewBox)},
            url: ${publicPath} + ${stringify(spritePlaceholder)},
            width: ${width},
            height: ${height},
            toString: function () {
                return this.url;
            }
        }`;
github zuzucheFE / guido / lib / config / svg-sprite-runtime-generator.js View on Github external
let runtime;
    let symbolId = symbol.id.replace('--sprite', '');

    if (extract) {
        const spritePlaceholder = generateSpritePlaceholder(symbol.request.file);
        const publicPath = loaderContext._compiler.options.output.publicPath;

        const viewBoxParts = symbol.viewBox.split(' ');
        const width = parseInt(viewBoxParts[2], 10);
        const height = parseInt(viewBoxParts[3], 10);

        const data = `{
      id: ${stringify(symbolId)},
      viewBox: ${stringify(symbol.viewBox)},
      url: ${publicPath} + ${stringify(spritePlaceholder)},
      width: ${width},
      height: ${height}
    }`;

        runtime = generateExport(data, esModule);
    } else {
        const spriteModuleImport = stringifyRequest({ context }, spriteModule);
        const symbolModuleImport = stringifyRequest({ context }, symbolModule);

        runtime = [
            generateImport('SpriteSymbol', symbolModuleImport, esModule),
            generateImport('sprite', spriteModuleImport, esModule),
            generateImport('React', 'react', esModule),

            `let symbol = new SpriteSymbol(${stringifySymbol(symbol)})`,
            'sprite.add(symbol)',
github zuzucheFE / guido / lib / utils / svgSpriteRuntimeGenerator.js View on Github external
let symbolId = symbol.id.replace('--sprite', '');

	if (extract) {
		const spritePlaceholder = generateSpritePlaceholder(
			symbol.request.file
		);
		const publicPath = stringify(publicPath) || '__webpack_public_path__';

		const viewBoxParts = symbol.viewBox.split(' ');
		const width = parseInt(viewBoxParts[2], 10);
		const height = parseInt(viewBoxParts[3], 10);

		const data = `{
            id: ${stringify(symbolId)},
            viewBox: ${stringify(symbol.viewBox)},
            url: ${publicPath} + ${stringify(spritePlaceholder)},
            width: ${width},
            height: ${height},
            toString: function () {
                return this.url;
            }
        }`;

		runtime = generateExport(data, esModule);
	} else {
		const spriteModuleAbsPath = path.isAbsolute(spriteModule)
			? spriteModule
			: path.join(context, spriteModule);
		const symbolModuleAbsPath = path.isAbsolute(symbolModule)
			? symbolModule
			: path.join(context, symbolModule);
github zuzucheFE / guido / lib / utils / svgSpriteRuntimeGeneratorNotReact.js View on Github external
let runtime;
	let symbolId = symbol.id.replace('--sprite-notrc', '');

	if (extract) {
		const spritePlaceholder = generateSpritePlaceholder(
			symbol.request.file
		);
		const publicPath = stringify(publicPath) || '__webpack_public_path__';

		const viewBoxParts = symbol.viewBox.split(' ');
		const width = parseInt(viewBoxParts[2], 10);
		const height = parseInt(viewBoxParts[3], 10);

		const data = `{
            id: ${stringify(symbolId)},
            viewBox: ${stringify(symbol.viewBox)},
            url: ${publicPath} + ${stringify(spritePlaceholder)},
            width: ${width},
            height: ${height},
            toString: function () {
                return this.url;
            }
        }`;

		runtime = generateExport(data, esModule);
	} else {
		const spriteModuleAbsPath = path.isAbsolute(spriteModule)
			? spriteModule
			: path.join(context, spriteModule);
		const symbolModuleAbsPath = path.isAbsolute(symbolModule)
			? symbolModule
github zuzucheFE / guido / lib / config / svg-sprite-runtime-generator.js View on Github external
const { extract, esModule, spriteModule, symbolModule, runtimeCompat } = config;

    let runtime;
    let symbolId = symbol.id.replace('--sprite', '');

    if (extract) {
        const spritePlaceholder = generateSpritePlaceholder(symbol.request.file);
        const publicPath = loaderContext._compiler.options.output.publicPath;

        const viewBoxParts = symbol.viewBox.split(' ');
        const width = parseInt(viewBoxParts[2], 10);
        const height = parseInt(viewBoxParts[3], 10);

        const data = `{
      id: ${stringify(symbolId)},
      viewBox: ${stringify(symbol.viewBox)},
      url: ${publicPath} + ${stringify(spritePlaceholder)},
      width: ${width},
      height: ${height}
    }`;

        runtime = generateExport(data, esModule);
    } else {
        const spriteModuleImport = stringifyRequest({ context }, spriteModule);
        const symbolModuleImport = stringifyRequest({ context }, symbolModule);

        runtime = [
            generateImport('SpriteSymbol', symbolModuleImport, esModule),
            generateImport('sprite', spriteModuleImport, esModule),
            generateImport('React', 'react', esModule),

            `let symbol = new SpriteSymbol(${stringifySymbol(symbol)})`,
github zuzucheFE / guido / lib / config / svg-sprite-runtime-generator.js View on Github external
module.exports = function runtimeGenerator({ symbol, config, context, loaderContext }) {
    const { extract, esModule, spriteModule, symbolModule, runtimeCompat } = config;

    let runtime;
    let symbolId = symbol.id.replace('--sprite', '');

    if (extract) {
        const spritePlaceholder = generateSpritePlaceholder(symbol.request.file);
        const publicPath = loaderContext._compiler.options.output.publicPath;

        const viewBoxParts = symbol.viewBox.split(' ');
        const width = parseInt(viewBoxParts[2], 10);
        const height = parseInt(viewBoxParts[3], 10);

        const data = `{
      id: ${stringify(symbolId)},
      viewBox: ${stringify(symbol.viewBox)},
      url: ${publicPath} + ${stringify(spritePlaceholder)},
      width: ${width},
      height: ${height}
    }`;

        runtime = generateExport(data, esModule);
    } else {
        const spriteModuleImport = stringifyRequest({ context }, spriteModule);
        const symbolModuleImport = stringifyRequest({ context }, symbolModule);

        runtime = [
            generateImport('SpriteSymbol', symbolModuleImport, esModule),
            generateImport('sprite', spriteModuleImport, esModule),
            generateImport('React', 'react', esModule),
github zuzucheFE / guido / lib / utils / svgSpriteRuntimeGenerator.js View on Github external
function stringifySymbol(symbol) {
	let content = symbol.render().replace(/id="(.*)--sprite"/, 'id="$1"');
	return stringify({
		id: symbol.id.replace('--sprite', ''),
		use: symbol.useId.replace('--sprite', ''),
		viewBox: symbol.viewBox,
		content: content,
	});
}
github zuzucheFE / guido / lib / utils / svgSpriteRuntimeGeneratorNotReact.js View on Github external
function stringifySymbol(symbol) {
	let content = symbol.render().replace(/id="(.*)--sprite-notrc"/, 'id="$1"');
	return stringify({
		id: symbol.id.replace('--sprite-notrc', ''),
		use: symbol.useId.replace('--sprite-notrc', ''),
		viewBox: symbol.viewBox,
		content: content,
	});
}