How to use rollup-pluginutils - 10 common examples

To help you get started, we’ve selected a few rollup-pluginutils 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 adobe / coral-spectrum / coralui-gulp / plugins / rollup-plugin-resources.js View on Github external
function resources(opts) {
  opts = opts || {};
  
  if (!opts.include) {
    throw Error('include option should be specified');
  }
  
  if (!opts.output) {
    throw Error('output option should be specified');
  }
  
  const filter = rollupPluginUtils.createFilter(opts.include, opts.exclude);
  
  return {
    name: 'resources',
    transform: function transform(code, id) {
      if (filter(id)) {
        const file = id.split('/').pop();
        let outputPath = path.join(opts.output, file);
        
        if (outputPath.startsWith('./')) {
          outputPath = outputPath.replace('./', '');
        }
        
        fs.outputFile(path.join(process.cwd(), outputPath), code);
        
        // Export the file path
        return {
github andreasbm / web-config / rollup-plugins / rollup-plugin-lit-html.js View on Github external
export default function litHTML (config) {
	const {include, exclude} = {...defaultConfig, ...config};

	// Generate a filter that determines whether the file should be handled by the plugin or not.
	const filter = createFilter(include, exclude);

	return {
		name: 'litHTML',
		resolveId: (id, importer) => {
			if (!importer || !filter(id)) return;
			return path.resolve(path.dirname(importer), id);
		},
		transform: (code, id) => {
			if (!filter(id)) return;

			if (id.endsWith("my.component.ts")) {
				console.log("WUHUU", id, code);
			}
		}
	}
};
github aMarCruz / rollup-plugin-jscc / index.js View on Github external
const makeFilter = function makeFilter (opts, exts) {

  const _filt = rollupPluginutils.createFilter(opts.include, opts.exclude);

  exts = opts.extensions || exts;
  if (!exts || exts === '*') {
    return _filt   // do not filter extensions
  }

  if (!Array.isArray(exts)) {
    exts = [exts];
  }
  exts = exts.map((e) => (e[0] !== '.' ? `.${e}` : e));

  return (id) => _filt(id) && exts.indexOf(path.extname(id)) > -1
};
github andreasbm / web-config / src / lib / rollup-plugins / html-template / rollup-plugin-html-template.ts View on Github external
export function htmlTemplate(config: Partial = {}) {
	config = { ...defaultConfig, ...config };
	const { template, target, include, exclude, polyfillConfig } = { ...defaultConfig, ...config };
	const filter = createFilter(include, exclude);

	// Throw error if neither the template nor the target has been defined
	if (template == null || target == null) {
		throw new Error(`The htmlTemplate plugin needs both a template and a target.`);
	}

	return {
		name: "htmlTemplate",
		generateBundle: async (outputOptions: OutputOptions, bundle: OutputBundle, isWrite: boolean): Promise => {
			if (!isWrite) return;

			// @ts-ignore
			return generateFile({
				...config,
				polyfillConfig: { ...defaultPolyfillConfig, ...polyfillConfig },
				bundle,
github andreasbm / web-config / src / lib / rollup-plugins / minify-lit-html / rollup-plugin-minify-lit-html.js View on Github external
export function minifyLitHTML (config = defaultConfig) {
	const {include, exclude, esprima, htmlMinifier, verbose} = {...defaultConfig, ...config};

	// Generate a filter that determines whether the file should be handled by the plugin or not.
	const filter = createFilter(include, exclude);

	return {
		name: 'minifyLitHTML',
		resolveId: (id, importer) => {
			if (!importer || !filter(id)) return;
			return path.resolve(path.dirname(importer), id);
		},
		transform: (code, id) => {
			if (!filter(id)) return;
			return processFile({code, id, config: {esprima, htmlMinifier, verbose}});
		}
	}
}
github salesforce / lwc / packages / @lwc / rollup-plugin / src / index.js View on Github external
module.exports = function rollupLwcCompiler(pluginOptions = {}) {
    const { include, exclude } = pluginOptions;
    const filter = pluginUtils.createFilter(include, exclude);
    const mergedPluginOptions = Object.assign({}, DEFAULT_OPTIONS, pluginOptions);

    // Closure to store the resolved modules
    let modulePaths = {};

    return {
        name: 'rollup-plugin-lwc-compiler',

        options({ input }) {
            const { modules: userModules = [], rootDir } = mergedPluginOptions;
            const defaultModulesDir = rootDir ? path.resolve(rootDir) : path.dirname(input);
            const modules = [...userModules, ...DEFAULT_MODULES, defaultModulesDir];
            const resolvedModules = lwcResolver.resolveModules({ rootDir, modules });
            modulePaths = resolvedModules.reduce((map, m) => ((map[m.specifier] = m), map), {});
        },
github salesforce / lwc / packages / rollup-plugin-lwc-compiler / src / index.js View on Github external
module.exports = function rollupLwcCompiler(pluginOptions = {}) {
    const { include, exclude } = pluginOptions;
    const filter = pluginUtils.createFilter(include, exclude);
    const mergedPluginOptions = Object.assign({}, DEFAULT_OPTIONS, pluginOptions);
    const { resolveFromPackages, resolveFromSource } = mergedPluginOptions;

    // Closure to store the resolved modules
    let modulePaths = {};

    return {
        name: "rollup-plugin-lwc-compiler",

        options(rollupOptions) {
            modulePaths = {};
            const entry = rollupOptions.input || rollupOptions.entry;
            const entryDir = mergedPluginOptions.rootDir || path.dirname(entry);
            const externalPaths = resolveFromPackages ? lwcResolver.resolveLwcNpmModules(mergedPluginOptions) : {};
            const sourcePaths = resolveFromSource ? lwcResolver.resolveModulesInDir(entryDir, mergedPluginOptions) : {};
            Object.assign(modulePaths, externalPaths, sourcePaths);
github ezolenko / rollup-plugin-typescript2 / dist / rollup-plugin-typescript2.cjs.js View on Github external
options: function (config) {
            rollupOptions = config;
            context = new ConsoleContext(pluginOptions.verbosity, "rpt2: ");
            context.info("Typescript version: " + tsModule.version);
            context.debug("Plugin Options: " + JSON.stringify(pluginOptions, function (key, value) { return key === "typescript" ? "version " + value.version : value; }, 4));
            filter$$1 = createFilter(pluginOptions.include, pluginOptions.exclude);
            parsedConfig = parseTsConfig(pluginOptions.tsconfig, context, pluginOptions);
            servicesHost = new LanguageServiceHost(parsedConfig);
            service = tsModule.createLanguageService(servicesHost, tsModule.createDocumentRegistry());
            // printing compiler option errors
            if (pluginOptions.check)
                printDiagnostics(context, convertDiagnostic("options", service.getCompilerOptionsDiagnostics()));
            context.debug("rollupConfig: " + JSON.stringify(rollupOptions, undefined, 4));
            if (pluginOptions.clean)
                cache().clean();
        },
        resolveId: function (importee, importer) {
github ezolenko / rollup-plugin-typescript2 / dist / rollup-plugin-typescript2.es.js View on Github external
options: function (config) {
            rollupOptions = config;
            context = new ConsoleContext(pluginOptions.verbosity, "rpt2: ");
            context.info("Typescript version: " + tsModule.version);
            context.debug("Plugin Options: " + JSON.stringify(pluginOptions, function (key, value) { return key === "typescript" ? "version " + value.version : value; }, 4));
            filter$$1 = createFilter(pluginOptions.include, pluginOptions.exclude);
            parsedConfig = parseTsConfig(pluginOptions.tsconfig, context, pluginOptions);
            servicesHost = new LanguageServiceHost(parsedConfig);
            service = tsModule.createLanguageService(servicesHost, tsModule.createDocumentRegistry());
            // printing compiler option errors
            if (pluginOptions.check)
                printDiagnostics(context, convertDiagnostic("options", service.getCompilerOptionsDiagnostics()));
            context.debug("rollupConfig: " + JSON.stringify(rollupOptions, undefined, 4));
            if (pluginOptions.clean)
                cache().clean();
        },
        resolveId: function (importee, importer) {
github aMarCruz / rollup-plugin-pug / dist / rollup-plugin-pug.js View on Github external
const makeFilter = (opts, exts) => {
    opts = opts || {};
    // Create the rollup default filter
    const filter = rollupPluginutils.createFilter(opts.include, opts.exclude);
    exts = opts.extensions || exts;
    if (!exts || exts === '*') {
        return filter;
    }
    if (!Array.isArray(exts)) {
        exts = [exts];
    }
    // Create the normalized extension list
    const extensions = exts.map((e) => (e[0] !== '.' ? `.${e}` : e));
    return (id) => (filter(id) && extensions.indexOf(path.extname(id)) > -1);
};

rollup-pluginutils

Functionality commonly needed by Rollup plugins

MIT
Latest version published 5 years ago

Package Health Score

55 / 100
Full package analysis

Popular rollup-pluginutils functions