2016-10-27 45 views
0

我正在使用Laravel 5.3。gulp:模块解析失败

安装node-uuid后出现错误。

{ [Error: ./~/diffie-hellman/lib/primes.json Module parse failed: /var/www/html/filecloudprod/node_modules/diffie-hellman/lib/primes.json Unexpected token (2:11) You may need an appropriate loader to handle this file type.

我的package.json文件。 注意JSON-装载机

{ 
    "private": true, 
    "scripts": { 
    "prod": "gulp --production", 
    "dev": "gulp watch" 
    }, 
    "devDependencies": { 
    "gulp": "^3.9.1", 
    "jquery": "^3.1.0", 
    "laravel-elixir": "^6.0.0-9", 
    "laravel-elixir-browsersync-official": "^1.0.0", 
    "laravel-elixir-vue-2": "^0.2.0", 
    "laravel-elixir-webpack-official": "^1.0.2", 
    "lodash": "^4.16.2", 
    "vue": "^2.0.1", 
    "vue-resource": "^1.0.3", 
    "dropzone": "^4.3.0", 
    "animate.css": "^3.5.0", 
    "node-uuid": "^1.4.7", 
    "json-loader": "^0.5.4" 
    } 
} 

然后试图gulpfile合并的WebPack配置是这样的。 我尝试了两种不同的方法,参见TRY1和TRY2,当然不是在同一时间,只是发布了两种方法。

const elixir = require('laravel-elixir'); 

require('laravel-elixir-vue-2'); 

// TRY 1 
elixir.webpack.mergeConfig({ 
    module: { 
     loaders: [{ 
      test: /\.json$/, 
      loader: 'json' 
     }] 
    } 
}); 

// TRY 2 
elixir.ready(() => { 
    elixir.config.js.webpack = { 
     loaders: [{ 
      test: /\.json$/, 
      loader: 'json' 
     }] 
    } 
}); 

elixir(function (mix) { 

    mix.sass('app.scss'); 

    mix.webpack('app.js'); 

    mix.browserSync({ 
     proxy: 'filecloud.dev' 
    });  

    mix.version(['css/app.css', 'js/app.js']); 
}); 

但我仍然得到错误。

完整的错误

enter image description here

回答

6

如果你想使用这需要JSON装载机 NPM模块,这是解决方案。

将以下内容添加到package.json文件中。

"json-loader": "^0.5.4"

用下面的代码创建webpack.config.js:

Elixir.webpack.mergeConfig({ 

    module: { 
     loaders: [{ 
      test: /\.json$/, 
      loader: 'json' 
     }] 
    } 
}); 

现在你可以要求你的bootstrap.js文件包需要的JSON-装载机。

其他注意事项

当你到定义灵药的WebPack方法index.js文件,你看到的JSON装载机的装载机数组中失踪。

module: { 
    loaders: [{ test: /\.js$/, loader: 'buble', exclude: /node_modules/ }] 
},