Json gulp:模块解析失败

Json gulp:模块解析失败,json,npm,gulp,webpack,laravel-elixir,Json,Npm,Gulp,Webpack,Laravel Elixir,我和拉威尔5.3一起工作 安装节点uuid后出现的错误 {[错误:./~/diffie-hellman/lib/primes.json 模块解析失败:/var/www/html/filecloudprod/node_modules/diffie-hellman/lib/primes.json意外令牌(2:11) 您可能需要适当的加载程序来处理此文件类型 My package.json文件。注意json加载程序 { "private": true, "scripts": { "pr

我和拉威尔5.3一起工作

安装节点uuid后出现的错误

{[错误:./~/diffie-hellman/lib/primes.json 模块解析失败:/var/www/html/filecloudprod/node_modules/diffie-hellman/lib/primes.json意外令牌(2:11) 您可能需要适当的加载程序来处理此文件类型

My 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']);
});
但我仍然得到了错误

完全错误

{
  "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"
  }
}

如果您想使用需要json加载程序的npm模块,这就是解决方案

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

“json加载程序”:“^0.5.4”

使用以下代码创建webpack.config.js:

Elixir.webpack.mergeConfig({

    module: {
        loaders: [{
            test: /\.json$/,
            loader: 'json'
        }]
    }
});
现在,您可以在bootstrap.js文件中要求使用需要json加载程序的包

附加注释

当您查看定义elixir的webpack方法的index.js文件时,您会发现加载程序数组中缺少json加载程序

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

如果您想使用需要json加载程序的npm模块,这就是解决方案

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

“json加载程序”:“^0.5.4”

使用以下代码创建webpack.config.js:

Elixir.webpack.mergeConfig({

    module: {
        loaders: [{
            test: /\.json$/,
            loader: 'json'
        }]
    }
});
现在,您可以在bootstrap.js文件中要求使用需要json加载程序的包

附加注释

当您查看定义elixir的webpack方法的index.js文件时,您会发现加载程序数组中缺少json加载程序

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