2017-10-05 50 views
1

我试图使用RollupGulp汇总:(定义|求购模块)没有定义

以下是我的Gulpfile:

const gulp = require("gulp"); 
const rollup = require("rollup-stream"); 
const vue = require("rollup-plugin-vue"); 
const resolve = require("rollup-plugin-node-resolve"); 
const commonjs = require("rollup-plugin-commonjs"); 
const json = require("rollup-plugin-json"); 
const babel = require("rollup-plugin-babel"); 
const globals = require("rollup-plugin-node-globals"); 
const source = require("vinyl-source-stream"); 
const buffer = require("vinyl-buffer"); 
const uglify = require("gulp-uglify"); 

// ... CSS tasks and the like 

gulp.task("js", function scriptTask() 
{ 
    rollup({ 
     input: "js/app.js", 
     plugins: [ 
      vue(), 
      resolve({ 
       jsnext: true, 
       browser: true 
      }), 
      json(), 
      commonjs(), 
      babel({ 
       exclude: ["node_modules/**"], 
       presets: [["env", {modules: false}]], 
       plugins: ["external-helpers"] 
      }), 
      globals() 
     ], 
     format: "iife", 
    }) 
     .pipe(source("bundle.js")) 
     .pipe(buffer()) 
     .pipe(uglify()) 
     .pipe(gulp.dest("../dist")); 
}); 

// ... default tasks and the like 

这似乎成功地把所有的依赖和执行树震动,但输出文件不运行。根据传递到汇总“格式”选项的值,我收到以下错误之一尝试时:

Uncaught ReferenceError: require is not defined 
    at bundle.js:1 
    at bundle.js:1 
    at bundle.js:1 

Uncaught ReferenceError: define is not defined 
    at bundle.js:1 
    at bundle.js:1 
    at bundle.js:1 

Uncaught ReferenceError: module is not defined 
    at bundle.js:1 
    at bundle.js:1 
    at bundle.js:1 

没有什么工作!

+0

我想我解决了你在我的答案 – 2017-10-16 14:37:06

+0

需要模块看我还在试图解决你的其他2个错误 – 2017-10-16 14:43:47

回答

-1

您应该将其附加到脚本的末尾。

gulp.task('default', ['js']); 
gulp.task('build', ['js']); 
+0

问题不运行脚本之一。问题是运行脚本后输出不正确 – stevendesu