lemmabit / rollup-stream

a wrapper around Rollup that returns a stream instead of a Promise
MIT License
68 stars 14 forks source link

Cannot work with specifying a rollup.config.file. #24

Open LvChengbin opened 6 years ago

LvChengbin commented 6 years ago

this is my code in rollup.config.js:

import resolve from 'rollup-plugin-node-resolve';

export default [ {
    input : 'src/znxy.js',
    plugins : [
        resolve( {
            module : true,
            jsnext : true
        } )
    ],
    output : [
        { file : 'dist/znxy.', format : 'umd', name : 'ZNXY' }
    ]
} ];

It is working well if I run rollup with rollup -c.

But if I run it in gulp with rollup-stream I would get this error message:

Error: Unexpected key '0' found, expected one of: acorn, amd, banner, cache, context, entry, exports, extend, external, file, footer, format, globals, indent, input, interop, intro, legacy, moduleContext, name, noConflict, onwarn, output, outro, paths, plugins, preferConst, pureExternalModules, sourcemap, sourcemapFile, strict, targets, treeshake, watch
lemmabit commented 6 years ago

Interesting. I didn't know Rollup supported arrays as configs now. I wonder how long it's been doing that.

For now, since you have just one item, you can just remove the square brackets:

import resolve from 'rollup-plugin-node-resolve';

export default {
    input : 'src/znxy.js',
    plugins : [
        resolve( {
            module : true,
            jsnext : true
        } )
    ],
    output : [
        { file : 'dist/znxy.', format : 'umd', name : 'ZNXY' }
    ]
};

But I may want to look into supporting arrays. Thanks for bringing this to my attention.

LvChengbin commented 6 years ago

@Permutatrix https://github.com/rollup/rollup/issues/1877#issuecomment-357831560

LvChengbin commented 6 years ago

Unfortunately, I encountered another problem after removing the square brackets. The rollup plugin cannot work if it is running under rollup-stream, I got TypeError: dest.write is not a function, do I need more config items?

lemmabit commented 6 years ago

@LvChengbin Can I see your gulpfile?

LvChengbin commented 6 years ago

This the code in gulpfile, it was working well before with gulp-rollup, but it doesn't support specifying a config file for rollup.

gulp.task( 'default', () => {
    gulp.src( 'src/**/*.js' )
        .pipe( createBuildDirectiveHandler( 'web' ) )
        .pipe( rollup( 'rollup.config.js' ).on( 'error', errorhandler ) )
        //.pipe( babel().on( 'error', errorhandler ) )
        .pipe( replace( '@@API_HOST', settings.uri.api_host ) )
        //.pipe( replace( '@@version', settings.version ) )
        .pipe( replace( /@@template::([^\s<>'"]+)/ig, function( m, n ) {
            const path = settings.src + '/templates/' + n;

            if( !fs.existsSync( path ) ) {
                console.log( `Template file ${path} is not existing` );
                return m;
            }

            return fs.readFileSync( path ).toString().replace( /\s+/g, ' ' ).replace( /'/g, '\\\'' );
        } ) )
        .pipe( replace( /@@c\.([^\-\s<>'"]+)/ig, ( m, n ) => {
            return settings.selectorPrefix[ n.toLowerCase() ];
        } ) )
        .pipe( replace( /@@images::/ig, settings.uri.images ) )
        .pipe( gulp.dest( './sdk' ) );
} );
lemmabit commented 6 years ago

@LvChengbin rollup-stream isn't a drop-in replacement for gulp-rollup. Its API is different.

You should read the README. If you still have questions after that, you can ask here.