GithubHelp home page GithubHelp logo

rollup / rollup-plugin-image Goto Github PK

View Code? Open in Web Editor NEW
41.0 13.0 13.0 6 KB

This module has moved and is now available at @rollup/plugin-image / https://github.com/rollup/plugins/blob/master/packages/image

JavaScript 100.00%

rollup-plugin-image's Introduction

Moved

This module has moved and is now available at @rollup/plugin-image. Please update your dependencies. This repository is no longer maintained.

rollup-plugin-image

Import JPG, PNG, GIF and SVG files.

Installation

npm install --save-dev rollup-plugin-image

Usage

// rollup.config.js
import image from 'rollup-plugin-image';

export default {
  entry: 'src/index.js',
  dest: 'dist/my-lib.js',
  plugins: [
    image()
  ]
};

You can now use images in your bundle like so:

import logo from './rollup.png';
document.body.appendChild( logo );

Images are encoded using base64, which means they will be 33% larger than the size on disk. You should therefore only use this for small images where the convenience of having them available on startup (e.g. rendering immediately to a canvas without co-ordinating asynchronous loading of several images) outweighs the cost.

License

MIT

rollup-plugin-image's People

Contributors

rich-harris avatar shellscape avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rollup-plugin-image's Issues

Why is .js appended to svg imports?

Hi, with this config

// rollup.config.json
import path from 'path'

import alias from 'rollup-plugin-alias'
import babel from 'rollup-plugin-babel'
import browsersync from 'rollup-plugin-browsersync'
import commonjs from 'rollup-plugin-commonjs'
import css from 'rollup-plugin-css-only'
import htmlTemplate from 'rollup-plugin-generate-html-template'
import nodeResolve from 'rollup-plugin-node-resolve'
import image from 'rollup-plugin-image'

const isDev = process.env.NODE_ENV !== 'production'

export default {
  external: ['jquery'],
  input: 'src/index.js',
  output: {
    file: 'dist/bundle.js',
    format: 'iife',
    globals: {
      jquery: '$',
    },
  },
  plugins: [
    alias({
      '@': path.join(__dirname, 'src'),
    }),
    babel({
      exclude: 'node_modules/**',
    }),
    browsersync({ server: 'dist' }),
    commonjs({
      include: 'node_modules/**',
      ignoreGlobal: false,
      sourceMap: isDev,
      exclude: [
        'node_modules/process-es6/**',
      ],
      namedExports: {
        'node_modules/react/index.js': ['Children', 'Component', 'PropTypes', 'createElement'],
        'node_modules/react-dom/index.js': ['render'],
        'node_modules/uuid/index.js': ['v4'],
        'node_modules/react-is/index.js': ['isValidElementType'],
      },
    }),
    css(),
    htmlTemplate({
      template: 'src/template.html',
      target: 'index.html',
    }),
    image(),
    nodeResolve({
      browser: true,
      jsnext: true,
      main: true,
    }),
  ],
  watch: {
    chokidar: true,
    include: 'src/**',
  },
}

When I write

import DeleteIcon from '@/icons/baseline-delete_forever-24px.svg'

I get Error: Could not load /<irrelevant>/<rollup-project-folder>/src/icons/baseline-delete_forever-24px.svg.js

What am I doing wrong?

Error when importing (iife format)

Hi,

I got an error when i try to use this plugin :
logo.svg does not export default

I must doing something wrong but I do not find.
Here are the plugins I am using :

const plugins = [
    json(),
    image(),
    nodeResolve(),
    commonjs(),
    babel({
        presets: 'es2015-rollup',
        include: [
            '**/*.js'
        ],
        exclude: [
            'node_modules/**',
            'app/media/js/vendors/**'
        ]
    })
];

I follow the example to use it.

Thanks for any help.

Doesn't work with vue.

Use https://github.com/alwaysonlinetxm/rollup-plugin-img does work.

[!] Error: 'default' is not exported by assets/images/verified.png
https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module-
pkgs/vue-components/elements/icon/VerifiedIcon.vue?rollup-plugin-vue=script.js (7:7)
5:
6: import QxImageView from 'qxjs/pkgs/vue-components/elements/image/QxImageView.vue';
7: import asset from '../../../../assets/images/verified.png';
          ^
8:
9: export default {
Error: 'default' is not exported by assets/images/verified.png

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.