Ad

Can't Compile Assets With Gulp

- 1 answer

Every tutorial or doc I find says that I should do something like this:

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

elixir.config.assetsPath = 'themes/ei/assets/src';
elixir.config.publicPath = 'themes/ei/assets/'

elixir(function(mix) {
    mix.sass('style.scss');
    mix.scripts('main.js');
});

But when I run gulp from the command line I get:

AssertionError [ERR_ASSERTION]: Task function must be specified
at Gulp.set [as _setTask] (/home/andrew/Development/eiweb/node_modules/undertaker/lib/set-task.js:10:3)
at Gulp.task (/home/andrew/Development/eiweb/node_modules/undertaker/lib/task.js:13:8)
at Object.<anonymous> (/home/andrew/Development/eiweb/node_modules/laravel-elixir/dist/tasks/recipes/default.js:30:6)
at Module._compile (internal/modules/cjs/loader.js:816:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:827:10)
at Module.load (internal/modules/cjs/loader.js:685:32)
at Function.Module._load (internal/modules/cjs/loader.js:620:12)
at Module.require (internal/modules/cjs/loader.js:723:19)
at require (internal/modules/cjs/helpers.js:14:16)
at requireDir (/home/andrew/Development/eiweb/node_modules/require-dir/index.js:123:33)

My package.json file includes:

"dependencies": {
    "gulp": "^4.0.2",
    "laravel-elixir": "^6.0.0-18"
}

...and I have gulp-cli installed global.

What am I missing?

Ad

Answer

This issue occurs because of version issue gulp 4 has different signature for the task and laravel-elixir uses old signature of gulp 3 so it will cause error.

Best case would be to movehttps://laravel-mix.com as its based on webpack so it support more functionalities. also laravel-mix syntax is similar so its plus point.

For laravel-mix create this pacjage package.json file in root. or user latest from [ https://github.com/laravel/laravel ] public repo.

{
    "private": true,
    "scripts": {
        "dev": "npm run development",
        "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
        "watch": "npm run development -- --watch",
        "watch-poll": "npm run watch -- --watch-poll",
        "hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
        "prod": "npm run production",
        "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
    },
    "devDependencies": {
        "axios": "^0.18",
        "bootstrap": "^4.1.0",
        "cross-env": "^5.1",
        "jquery": "^3.2",
        "laravel-mix": "^4.0.7",
        "lodash": "^4.17.5",
        "popper.js": "^1.12",
        "resolve-url-loader": "^2.3.1",
        "sass": "^1.15.2",
        "sass-loader": "^7.1.0",
        "vue": "^2.5.17",
        "vue-template-compiler": "^2.6.10"
    }
}

Create webpack.mix.js in your root

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

// change theme path according to your need.    
const themePath = 'themes/rainlab-bonjour'; 

mix.options({
  publicPath: themePath + '/assets/compiled/'
})

// change script name and path according to your need.
mix.js(themePath + '/assets/src/main.js', 'main.js')
   .sass(themePath + '/assets/src/main.scss', 'main.css');

Commands [ you can use this command with yarn or npm (I am using yarn)], you can read more info here. [ https://laravel-mix.com/docs/4.0/workflow ]

yarn watch -> it will watch files and compile files then generate compiled out-put in publicPath directory. in our case files will be.

themes/rainlab-bonjour/assets/compiled/main.js
themes/rainlab-bonjour/assets/compiled/main.css

Now you can just include them in theme using 'assets/compiled/main.js'|theme OctoberCms filter.

if you have any doubts please comment.

Ad
source: stackoverflow.com
Ad