我正在使用laravel 5.4,我想设置elixir来编译sass文件。我试图通过运行$ npm install
来安装elixir,然后我尝试运行$ gulp
,但它给了我以下错误:
/home/vagrant/Code/Laravel/gulpfile.js:1
(function (exports, require, module, __filename, __dirname) { elixir(mix => {
^
ReferenceError: elixir is not defined
at Object.<anonymous> (/home/vagrant/Code/Laravel/gulpfile.js:1:63)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at execute (/usr/lib/node_modules/gulp-cli/lib/versioned/^3.7.0/index.js:24:18)
at Liftoff.handleArguments (/usr/lib/node_modules/gulp-cli/index.js:149:63)
添加const elixir = require('laravel-elixir');
后,我收到此错误:
[02:28:30] Starting 'webpack'...
{ [Error: ./resources/assets/js/components/Example.vue
Module parse failed: /home/vagrant/Code/Laravel/resources/assets/js/components/Example.vue Unexpected token (1:0)
You may need an appropriate loader to handle this file type.
| <template>
| <div class="container">
| <div class="row">
@ ./resources/assets/js/app.js 16:25-60]
message: './resources/assets/js/components/Example.vue\nModule parse failed: /home/vagrant/Code/Laravel/resources/assets/js/components/Example.vue Unexpected token (1:0)\nYou may need an appropriate loader to handle this file type.\n| <template>\n| <div class="container">\n| <div class="row">\n @ ./resources/assets/js/app.js 16:25-60',
showStack: false,
showProperties: true,
plugin: 'webpack-stream',
__safety: { toString: [Function: bound ] } }
答案 0 :(得分:3)
安装新的laravel app 5.4时遇到同样的问题。当我尝试运行gulp webpack
时,它在我的控制台中显示相同的错误。所以我做了,因为laravel 5.4附带了新的vue版本vue 2
。您需要require('laravel-elixir-vue-2');
请参阅以下示例:
gulpfile.js
var elixir = require('laravel-elixir');
require('laravel-elixir-vue-2'); // recommended for vue 2
elixir(function(mix) {
// some mixes here..
mix.webpack('app.js');
});
如果你遇到像elixir相关的错误,只需要安装它们。还请查看此页here