MikeKovarik / gulp-better-rollup

📦 Better Gulp plugin for Rollup ES6 module bundler
MIT License
49 stars 16 forks source link

How to import from node modules? #10

Closed Craeckerffm closed 7 years ago

Craeckerffm commented 7 years ago

i have

var rollup = require('gulp-better-rollup') var babel = require('rollup-plugin-babel') var resolve = require('rollup-plugin-node-resolve')

gulp.task('js', () => { gulp.src(config.src.js) .pipe(sourcemaps.init()) .pipe(rollup({ plugins: [resolve(), babel({ exclude: 'node_modules/**' })] }, { format: 'cjs', })) .pipe(sourcemaps.write()) .pipe(gulp.dest(config.dest.js))

But with every try im getting:

node_modules/*/.js The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten .... Non-existent export 'default' is imported from node_modules/*/.js

Finesse commented 7 years ago

Does bundling with your options work with a pure rollup?

BennieCopeland commented 7 years ago

Getting the same issue.

rollup-config.js

import noderesolve from 'rollup-plugin-node-resolve'
import commonjs from 'rollup-plugin-commonjs'
import uglify from 'rollup-plugin-uglify'

export default {
    entry: 'src/main.js',
    dest: 'build/js/app.js',
    sourceMap: false,
    format: 'iife',
    onwarn: function (warning) {
        if (warning.code === 'THIS_IS_UNDEFINED') { return; }
        console.warn(warning.message);
    },
    plugins: [
        noderesolve({ jsnext: true, module: true }),
        commonjs({
            include: 'node_modules/rxjs/**'
        }),
        uglify()
    ]
}

gulp task

    var rollupOptions = {
        format: 'iife',
        onwarn: function (warning) {
            if (warning.code === 'THIS_IS_UNDEFINED') { return; }
            console.warn(warning.message);
        },
        plugins: [
            noderesolve({ jsnext: true, module: true }),
            commonjs({
                include: 'node_modules/rxjs/**'
            }),
            uglify()
        ]
    }

    return gulp.src( 'src/main.js' )
        .pipe( rollup( rollupOptions ) )
        .pipe( rename( 'app.js' ) )
        .pipe( gulp.dest( buildDirectory + '/js' ) );

I receive a whole bunch of '@angular/platform-browser' is imported by src\main.js, but could not be resolved – treating it as an external dependency errors.

matthewblewitt commented 6 years ago

Getting the same issue

bewards commented 5 years ago

Was there ever a solution to this?