Giter Club home page Giter Club logo

Comments (10)

cascornelissen avatar cascornelissen commented on June 9, 2024

I can't seem to reproduce this issue. It looks like it's trying to parse the SVG as JS which throws the error you've provided.

Could you provide a minimal test case?

from svg-spritemap-webpack-plugin.

cwirz avatar cwirz commented on June 9, 2024

I've just included the plugin in the webpack config file like this and ran the command webpack -p

module.exports.plugins = (module.exports.plugins || []).concat([
    new SVGSpritemapPlugin({
        src: './assets/**/*.svg',
        prefix: 'icon-',
    }),
])

When i do the webpack --watch command it creates the spritemap.svg file.

from svg-spritemap-webpack-plugin.

cascornelissen avatar cascornelissen commented on June 9, 2024

Could you provide the entire webpack configuration in this issue or (even better) a link to the project so I can test this? I suspect something goes wrong with production-specific loader configuration but I'm not sure as I don't know anything about your setup.

from svg-spritemap-webpack-plugin.

cwirz avatar cwirz commented on June 9, 2024

I'm using now a workaroud to build the spritemap file first in the development process and exclude later the plugin in the production build but this feels wrong...

const path = require('path')
const webpack = require('webpack')
const SVGSpritemapPlugin = require('svg-spritemap-webpack-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const UglifyEsPlugin = require('uglify-es-webpack-plugin')

process.env.BABEL_ENV = 'app'

module.exports = {
    entry: {
        renderer: path.join(__dirname, 'app/main.js')
    },
    output: {
        path: path.resolve(__dirname, './app-dist'),
        libraryTarget: 'commonjs2',
        filename: 'build.js'
    },
    resolve: {
        extensions: ['.js', '.vue', '.scss'],
        alias: {
            vue: 'vue/dist/vue.js'
        }
    },
    target: 'electron-renderer',
    module: {
        rules: [
            {
                test: /\.vue$/,
                loader:  'vue-loader',
                options: {
                    loaders: {
                        'scss': 'vue-style-loader!css-loader!sass-loader',
                        'sass': 'vue-style-loader!css-loader!sass-loader?indentedSyntax',
                        'js': 'babel-loader!eslint-loader'
                    },
                },
                include: [
                    path.resolve(__dirname, "app/"),
                ],
            },
            {
                test: /\.js$/,
                loaders: [
                    'babel-loader',
                    'eslint-loader',
                ],
                include: [
                    path.resolve(__dirname, "app/"),
                ],
            },
        ]
    },
    plugins: [
        new webpack.NoEmitOnErrorsPlugin(),
        new webpack.DefinePlugin({
            'process.env.LATER_COV': false,
        }),
        new CopyWebpackPlugin([
            {from: 'app/index.html'},
            {from: 'node_modules/terminal-notifier/terminal-notifier.app/Contents/MacOS/terminal-notifier'},
        ], {}),
    ],
    node: {
        __filename: true,
        __dirname: true
    }
}


if (process.env.NODE_ENV === 'developemnt') {
    module.exports.plugins = (module.exports.plugins || []).concat([
        new SVGSpritemapPlugin({
            src: './assets/**/*.svg',
            prefix: 'icon-',
        }),
    ])
}
if (process.env.NODE_ENV === 'production') {
    module.exports.devtool = 'source-map'
    module.exports.plugins = (module.exports.plugins || []).concat([
        new UglifyEsPlugin(),
    ])
}

from svg-spritemap-webpack-plugin.

cascornelissen avatar cascornelissen commented on June 9, 2024

Does excluding the spritemap.svg using the exclude option from uglifyjs-webpack-plugin not work?

from svg-spritemap-webpack-plugin.

cwirz avatar cwirz commented on June 9, 2024

Not tried it yet but shouldn't that be a problem because the uglifyjs tries to uglify only js files? (default test option)

from svg-spritemap-webpack-plugin.

cascornelissen avatar cascornelissen commented on June 9, 2024

Yeah, I noticed the test option too. I'm willing to look into the issue regarding the fact that it tries to minify a file that doesn't pass the test but I'm short on time for the upcoming weeks so I'm looking for a solution to your problem in the meantime.

from svg-spritemap-webpack-plugin.

cwirz avatar cwirz commented on June 9, 2024

Cool thanks. Helps me a lot and thanks also for the great plugin!

from svg-spritemap-webpack-plugin.

cascornelissen avatar cascornelissen commented on June 9, 2024

You're more than welcome! I'll keep the issue open so I don't forget to look into this when I have the time.

from svg-spritemap-webpack-plugin.

cascornelissen avatar cascornelissen commented on June 9, 2024

I've been looking into this for the last hour but can't really replicate the issue. When someone runs into this problem and can submit a working test case I'd be happy to look into it once more.

from svg-spritemap-webpack-plugin.

Related Issues (20)

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.