mrsum / webpack-svgstore-plugin

Simple svg-sprite creating with webpack
https://www.npmjs.com/package/webpack-svgstore-plugin
200 stars 92 forks source link

Breaks on webpack 1.13.1 #95

Closed dmitriid closed 8 years ago

dmitriid commented 8 years ago

tl;dr Having plugin enabled breaks webpack builds somwhere in webpack-core/lib/ConcatSource.js

> npm install --save-dev webpack

This installs webpack 1.13.1

Given the following webpack.config:


var SvgStore = require('webpack-svgstore-plugin');

var config = {
    entry:   {
        app: [
            '/soma-file.js'
        ],
        lib: [
            'lodash'
        ]
    },
    output:  {
        path:              '/path',
        filename:          filename
    },
    module:  {
        loaders: [
            {
                test:   /\.js$/,
                loader: 'babel',
                query:  {
                    presets: ['es2015', 'stage-0', 'react'],
                    compact: false
                }
            },
            {
                test:   /\.json$/,
                loader: 'json'
            }
        ]
    },
    plugins: [
        new SvgStore(path.join('./img/svg', '', '**!/!*.svg'), path.join('./', ''), {
            name:        '[hash].sprite.svg',
            chunk:       'app',
            prefix:      'pref-',
            baseUrl:     '/my-url',
            svgoOptions: {}
        }),
        new webpack.optimize.CommonsChunkPlugin("lib", "lib.js", Infinity)
    ],
    bail:    false,
    target:  'web'
};

Trying to run this results in:

/node_modules/webpack-core/lib/ConcatSource.js:24
        return typeof item === "string" ? item : item.source();
                                                     ^

TypeError: Cannot read property 'source' of undefined
    at /node_modules/webpack-core/lib/ConcatSource.js:24:48
    at Array.map (native)
    at ConcatSource.source (/node_modules/webpack-core/lib/ConcatSource.js:23:23)
    at Compiler.writeOut (/node_modules/webpack/lib/Compiler.js:256:26)
    at Compiler.<anonymous> (/node_modules/webpack/lib/Compiler.js:246:20)
    at /node_modules/async/lib/async.js:181:20
    at Object.async.forEachOf.async.eachOf (/node_modules/async/lib/async.js:233:13)
    at Object.async.forEach.async.each (/node_modules/async/lib/async.js:209:22)
    at Compiler.emitFiles (/node_modules/webpack/lib/Compiler.js:235:20)
    at /node_modules/mkdirp/index.js:48:26
    at FSReqWrap.oncomplete (fs.js:82:15)

Will report this to webpack as well, could be a problem on their side: see webpack/core#24

soluml commented 8 years ago

Ok.. man.. I've been banging my head on this issue thinking it was something in my setup. I'm definitely experiencing this as well on 1.13.1.

The issue only occurs when I set the chunk value. If I leave the chunk value blank, the error doesn't occur, but the SVG does not build.

I'm also using the CommonsChunkPlugin as in the example above.

mrsum commented 8 years ago

Hi! Can you look, this version 3.0.0-alpha.1? code here https://github.com/mrsum/webpack-svgstore-plugin/tree/feature/refactor

I rebuild main idea.

dmitriid commented 8 years ago

Same problem, sadly :(

mrsum commented 8 years ago

@dmitriid do you red readme for this version?

dmitriid commented 8 years ago

@mrsum What are the differences?

The only difference I see is

put function mark at your chunk

which, honestly, I have no idea what it means :)

mrsum commented 8 years ago

@dmitriid try 3.0.0-alpha.2 version documentation here https://github.com/mrsum/webpack-svgstore-plugin/blob/feature/refactor/README.md