Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2 Questions: 1) JSON.parse error on spritesheets, 2) Loading assets from subfolders? #10

Open
SHG42 opened this issue Feb 11, 2021 · 0 comments

Comments

@SHG42
Copy link

SHG42 commented Feb 11, 2021

To start with the second question: is it possible to load assets from a nested folder structure? I have a variety of static image assets for my game and I had them categorized by type in subfolders. For instance: "./assets/images/loot/crystal_dagger.png" and so on. I've been trying various different ways of structuring the images array to reach the subfolders, with no luck. Looking at the src for the plugin, it seems to expect a single images folder. Is there a way to do this, or do I need to ditch my subfolders?

As for the error: when loading my spritesheets, which are in a single "./assets/spritesheets" folder, I get a JSON.parse error. I removed everything from the manifest except the spritesheets to be sure. In Chrome it gives me this:
loader_error
I'm new to webpack, so I'm wondering if it could be my config. I'm using this template, which incorporates your plugin. Here's my webpack.config and a sample of my manifest with just the spritesheets, and a sample json file:

const AssetManifest = {
    "spritesheets": [
        "caveportal",
        "compiled-hero",
        "objects",
        "portal",
        "sorceress"
    ]
};
const CONFIG = require('./config');
const path = require('path');
const webpack = require('webpack');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
    entry: {
        game: CONFIG.MAIN_FILE,
        vendor: ['pixi', 'p2', 'phaser', 'phaser-arcade-slopes', 'webfontloader']
    },
    plugins: [
        new CleanWebpackPlugin([CONFIG.BUILD_PATH]),
        new HtmlWebpackPlugin({
            title: CONFIG.GAME_TITLE,
            template: CONFIG.INDEX_TEMPLATE_FILE
        }),
        new webpack.optimize.CommonsChunkPlugin({ 
            name: 'vendor'
        }),
    ],
    output: {
        filename: '[name].js',
        path: path.resolve(__dirname, CONFIG.BUILD_PATH)
    },
    node: {
        fs: 'empty',
        net: 'empty',
        tls: 'empty'
    },
    module: {
        rules: [
            {
                test: /\.js$/,
                exclude: /node_modules/,
                use: {
                    loader: 'babel-loader',
                    options: {
                        presets: ['env'],
                        compact: false
                    }
                }
            },
            { 
                test: /pixi\.js/, 
                use: ['expose-loader?PIXI'] 
            },
            { 
                test: /phaser-split\.js$/, 
                use: ['expose-loader?Phaser'] 
            },
            { 
                test: /p2\.js/, 
                use: ['expose-loader?p2'] 
            },
            { 
                test: /phaser-arcade-slopes\.js/, 
                use: ['expose-loader?phaser-arcade-slopes'] 
            },
            {
                test: /\.(png|jpg|gif|svg|pvr|pkm)$/,
                loader: 'file-loader',
                options: {
                    name: 'assets/[path][name].[ext]?[hash]',
                    context: 'src/assets'
                }
            },
            {
                test: /\.json$/,
                use: 'file-loader'
            },
        ]
    },
    resolve: {
        alias: {
            'phaser': 'phaser-ce/build/custom/phaser-split.js',
            'pixi': 'phaser-ce/build/custom/pixi.js',
            'p2': 'phaser-ce/build/custom/p2.js',
            'phaser-arcade-slopes': 'phaser-arcade-slopes',
            'assets': path.join(__dirname, '/src/assets'),
        },
        modules: [
            path.resolve('./node_modules')
        ]
    }
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant