How to use the @babel/helper-module-imports.addSideEffect function in @babel/helper-module-imports

To help you get started, we’ve selected a few @babel/helper-module-imports 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 CraigCav / css-zero / src / macro / index.js View on Github external
// remove variable declarations of css``;
    cssRefs.forEach(ref => {
      ref.parentPath.parentPath.remove();
    });

    // if no styles have been used, there's no more work to do
    if (!Object.keys(styleSheet.usage).length) return;

    const filename = state.file.opts.filename;

    // choose a file to save the styles
    const outputFilename = relative(process.cwd(), filename.replace(/\.[^.]+$/, '.zero.css'));

    // include this file as an import to the referenced module, so that css-loader can pick it up at bundle-time
    addSideEffect(stylesRefs[0], './' + basename(outputFilename));

    // combine all the used styles
    const cssText = styleSheet.toString();

    // Read the file first to compare the content
    // Write the new content only if it's changed
    // This will prevent unnecessary reloads
    let currentCssText;

    try {
      currentCssText = readFileSync(outputFilename, 'utf-8');
    } catch (e) {
      // Ignore error
    }

    // if the files hasn't changed, nothing more to do
github ant-design / babel-plugin-import / src / Plugin.js View on Github external
? transCamel(methodName, '-')
          : methodName;
      const path = winPath(
        this.customName ? this.customName(transformedMethodName) : join(this.libraryName, libraryDirectory, transformedMethodName, this.fileName) // eslint-disable-line
      );
      pluginState.selectedMethods[methodName] = this.transformToDefaultImport  // eslint-disable-line
        ? addDefault(file.path, path, { nameHint: methodName })
        : addNamed(file.path, methodName, path);
      if (this.customStyleName) {
        const stylePath = winPath(this.customStyleName(transformedMethodName));
        addSideEffect(file.path, `${stylePath}`);
      } else if (this.styleLibraryDirectory) {
        const stylePath = winPath(
          join(this.libraryName, this.styleLibraryDirectory, transformedMethodName, this.fileName)
        );
        addSideEffect(file.path, `${stylePath}`);
      } else if (style === true) {
        addSideEffect(file.path, `${path}/style`);
      } else if (style === 'css') {
        addSideEffect(file.path, `${path}/style/css`);
      } else if (typeof style === 'function') {
        const stylePath = style(path, file);
        if (stylePath) {
          addSideEffect(file.path, stylePath);
        }
      }
    }
    return Object.assign({}, pluginState.selectedMethods[methodName]);
  }
github ant-design / babel-plugin-import / src / Plugin.js View on Github external
const libraryDirectory = this.libraryDirectory;
      const style = this.style;
      const transformedMethodName = this.camel2UnderlineComponentName  // eslint-disable-line
        ? transCamel(methodName, '_')
        : this.camel2DashComponentName
          ? transCamel(methodName, '-')
          : methodName;
      const path = winPath(
        this.customName ? this.customName(transformedMethodName) : join(this.libraryName, libraryDirectory, transformedMethodName, this.fileName) // eslint-disable-line
      );
      pluginState.selectedMethods[methodName] = this.transformToDefaultImport  // eslint-disable-line
        ? addDefault(file.path, path, { nameHint: methodName })
        : addNamed(file.path, methodName, path);
      if (this.customStyleName) {
        const stylePath = winPath(this.customStyleName(transformedMethodName));
        addSideEffect(file.path, `${stylePath}`);
      } else if (this.styleLibraryDirectory) {
        const stylePath = winPath(
          join(this.libraryName, this.styleLibraryDirectory, transformedMethodName, this.fileName)
        );
        addSideEffect(file.path, `${stylePath}`);
      } else if (style === true) {
        addSideEffect(file.path, `${path}/style`);
      } else if (style === 'css') {
        addSideEffect(file.path, `${path}/style/css`);
      } else if (typeof style === 'function') {
        const stylePath = style(path, file);
        if (stylePath) {
          addSideEffect(file.path, stylePath);
        }
      }
    }
github ant-design / babel-plugin-import / src / Plugin.js View on Github external
if (this.customStyleName) {
        const stylePath = winPath(this.customStyleName(transformedMethodName));
        addSideEffect(file.path, `${stylePath}`);
      } else if (this.styleLibraryDirectory) {
        const stylePath = winPath(
          join(this.libraryName, this.styleLibraryDirectory, transformedMethodName, this.fileName)
        );
        addSideEffect(file.path, `${stylePath}`);
      } else if (style === true) {
        addSideEffect(file.path, `${path}/style`);
      } else if (style === 'css') {
        addSideEffect(file.path, `${path}/style/css`);
      } else if (typeof style === 'function') {
        const stylePath = style(path, file);
        if (stylePath) {
          addSideEffect(file.path, stylePath);
        }
      }
    }
    return Object.assign({}, pluginState.selectedMethods[methodName]);
  }
github babel / babel / packages / babel-preset-env / src / utils.js View on Github external
export function createImport(path: NodePath, mod: string) {
  return addSideEffect(path, getModulePath(mod));
}

@babel/helper-module-imports

Babel helper functions for inserting module loads

MIT
Latest version published 2 months ago

Package Health Score

95 / 100
Full package analysis

Similar packages