Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

cache: false and ImageBase64Plugin will not work #1034

Closed
misantronic opened this issue Jan 14, 2018 · 1 comment
Closed

cache: false and ImageBase64Plugin will not work #1034

misantronic opened this issue Jan 14, 2018 · 1 comment
Labels

Comments

@misantronic
Copy link
Contributor

When setting cache: false in connection with using the ImageBase64Plugin the whole build will not work and result in

TypeError: Cannot read property 'getStaticCache' of undefined
    at ImageBase64PluginClass.transform (/node_modules/fuse-box/plugins/images/ImageBase64Plugin.js:20:38)
    at tasks.push (/node_modules/fuse-box/core/File.js:169:59)
    at realm_utils_1.each.promise (/node_modules/fuse-box/core/File.js:173:66)
    at iterate (/node_modules/realm-utils/dist/commonjs/each.js:79:34)
    at /node_modules/realm-utils/dist/commonjs/each.js:92:16
    at new Promise (<anonymous>)
    at Object.exports.Each [as each] (/node_modules/realm-utils/dist/commonjs/each.js:9:12)
    at File.tryPlugins (/node_modules/fuse-box/core/File.js:173:43)
    at File.consume (/node_modules/fuse-box/core/File.js:293:21)
    at ModuleCollection.resolve (/node_modules/fuse-box/core/ModuleCollection.js:186:24)

My config:

const path = require('path');
const ncp = require('ncp');
const {
    Sparky,
    FuseBox,
    WebIndexPlugin,
    CSSPlugin,
    EnvPlugin,
    ImageBase64Plugin
} = require('fuse-box');
const TypeHelper = require('fuse-box-typechecker').TypeHelper;

let production = false;

function envData() {
    return {
        PORT: process.env.PORT || 4445,
        NODE_ENV: production ? 'production' : 'development',
        BASE_URL: production ? '' : `http://localhost:5000`
    };
}

Sparky.task('build', () => {
    const fuse = FuseBox.init({
        homeDir: 'src',
        output: 'dist/$name.js',
        target: 'browser',
        experimentalFeatures: true,
        cache: !production,
        sourceMaps: !production,
        hash: production,
        plugins: [
            EnvPlugin(envData()),
            WebIndexPlugin({
                title: '...',
                target: 'index.html',
                template: 'src/index.html',
                path: '/'
            }),
            CSSPlugin(),
            ImageBase64Plugin({
                useDefault: true
            })
        ]
    });

    if (!production) {
        fuse.dev(
            {
                port: envData().PORT,
                httpServer: true
            },
            server => {
                const dist = path.resolve('./dist');
                const { app } = server.httpServer;

                app.get('/project/:id/:type', function(req, res) {
                    res.sendFile(path.join(dist, 'index.html'));
                });
            }
        );
    }

    // vendor
    const vendor = fuse
        .bundle('vendor')
        .instructions(`~ **/**.{js,ts,tsx} +tslib - [**/**.d.ts]`);

    // app
    const app = fuse
        .bundle('app')
        .splitConfig({
            browser: '/',
            dest: '/'
        })
        .split(
            'containers/projects/**',
            'projects > containers/projects/index.tsx'
        )
        .instructions(`> [index.tsx] + [containers/**/**.{ts, tsx}]`);

    if (!production) {
        vendor.watch();
        app.watch();
    }

    const testWatch = TypeHelper({
        tsConfig: './tsconfig.json',
        basePath: './',
        name: 'Watch Async'
    });

    if (!production) {
        testWatch.runWatch('./src');
    }

    fuse.run();
});

Sparky.task('copy-assets', () => {
    ncp('./src/assets', './dist/assets');
});

Sparky.task('clean', () => Sparky.src('dist/*').clean('dist/'));
Sparky.task('default', ['clean', 'copy-assets', 'build'], () => {});
Sparky.task('set-production-env', () => (production = true));
Sparky.task(
    'dist',
    ['clean', 'copy-assets', 'set-production-env', 'build'],
    () => {}
);
@nchanged
Copy link
Contributor

Thank you for submitting the issue! It has been fixed and will be available in the next @next version very soon.

@devmondo devmondo added the bug label Jan 15, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants