How to use the @lwc/compiler.transform function in @lwc/compiler

To help you get started, we’ve selected a few @lwc/compiler 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 muenzpraeger / create-lwc-app / packages / lwc-services / src / utils / webpack / module-loader.ts View on Github external
[
                    require.resolve('@babel/plugin-syntax-decorators'),
                    {
                        decoratorsBeforeExport: true
                    }
                ]
            ],
            presets: [require.resolve('@babel/preset-typescript')]
        })
        codeTransformed = code
    }

    // @ts-ignore
    const cb = this.async()

    compiler
        .transform(codeTransformed, resourcePath, {
            name: info.name,
            namespace: info.ns,
            outputConfig: compilerOutput,
            stylesheetConfig,
            experimentalDynamicComponent
        })
        .then((res: any) => {
            cb(null, res.code)
        })
        .catch((err: any) => {
            cb(err)
        })

    return
}
github salesforce / lwc / packages / @lwc / rollup-plugin / src / index.js View on Github external
async transform(src, id) {
            // Filter user-land config and lwc import
            if (!filter(id)) {
                return;
            }

            // If we don't find the moduleId, just resolve the module name/namespace
            const moduleEntry = Object.values(modulePaths).find(r => id === r.entry);
            const moduleRegistry = moduleEntry || getModuleQualifiedName(id, mergedPluginOptions);

            const { code, map } = await compiler.transform(src, id, {
                mode: DEFAULT_MODE, // Use always default mode since any other (prod or compat) will be resolved later
                name: moduleRegistry.moduleName,
                namespace: moduleRegistry.moduleNamespace,
                moduleSpecifier: moduleRegistry.moduleSpecifier,
                outputConfig: { sourcemap: mergedPluginOptions.sourcemap },
                stylesheetConfig: mergedPluginOptions.stylesheetConfig,
                experimentalDynamicComponent: mergedPluginOptions.experimentalDynamicComponent,
            });

            return { code, map };
        },
    };
github forcedotcom / lightning-language-server / packages / lwc-language-server / src / javascript / compiler.ts View on Github external
export async function compileSource(source: string, fileName: string = 'foo.js'): Promise {
    try {
        const name = fileName.substring(0, fileName.lastIndexOf('.'));
        const options: CompilerOptions = {
            name,
            namespace: 'x',
            files: {},
        };
        const transformerResult = await transform(source, fileName, options);
        const metadata = transformerResult.metadata as Metadata;
        patchComments(metadata);
        return { metadata, diagnostics: [] };
    } catch (err) {
        return { diagnostics: [toDiagnostic(err)] };
    }
}

@lwc/compiler

LWC compiler

MIT
Latest version published 2 days ago

Package Health Score

90 / 100
Full package analysis