gpt4 book ai didi

gulp - 无法使用 Gulp 编译 Assets

转载 作者:行者123 更新时间:2023-12-04 17:37:41 27 4
gpt4 key购买 nike

我找到的每个教程或文档都说我应该做这样的事情:

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');
});

但是当我运行 gulp从命令行我得到:
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)

我的 package.json文件包括:
"dependencies": {
"gulp": "^4.0.2",
"laravel-elixir": "^6.0.0-18"
}

...我有 gulp-cli安装全局。

我错过了什么?

最佳答案

出现此问题是因为版本问题 gulp 4 task 有不同的签名和 laravel-elixir使用 gulp 3 的旧签名所以它会导致错误。

最好的情况是搬家 https://laravel-mix.com因为它基于 webpack所以它支持更多的功能。还有laravel-mix语法是相似的,所以它的加分点。

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.



如果您有任何疑问,请发表评论。

关于gulp - 无法使用 Gulp 编译 Assets ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56030750/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com