laravel elixir - 多次组合脚本

时间:2015-07-22 08:54:20

标签: laravel laravel-elixir

我想将我的所有脚本合并到一个缩小的javascript文件中,但是我在组合它们时遇到了麻烦。

mix.browserify([
  // ViewModels
  'viewmodels.js'
], 'resources/assets/compiled/js/viewmodels.js')

mix.coffee([
  // WebSocket Client
  'client.coffee'
], 'resources/assets/compiled/js/').scripts([
  // Vendor
  'vendor/jquery.js',
  'vendor/bootstrap.js',
  'vendor/vue.js',
  'vendor/sisyphus.js',
  'vendor/leaflet.js',
  'vendor/moment.min.js'
], 'resources/assets/compiled/js/vendor.js').scripts([
  // Site & Helpers
  'libs/laravel.js',
  'libs/helpers.js'
], 'resources/assets/compiled/js/site.js').scripts([
  // Combine Scripts
  'resources/assets/compiled/js/vendor.js',
  'resources/assets/compiled/js/client.js',
  'resources/assets/compiled/js/site.js',
  'resources/assets/compiled/js/viewmodels.js'
], 'public/js/all.js', './')

文件是在resources/assets/compiled/js中创建的,所以我得到了:

  • client.js
  • site.js
  • vendor.js
  • viewmodels.js

运行的最后一个任务是组合四个文件的scripts任务。 elixir日志声明(我简化了输出):

  • Browserify(ViewModels)
  • CoffeeScript Compiled
  • 合并供应商
  • 合并网站&助手
  • 合并合并脚本

...这些是我收到的错误消息:

File not found: ./resources/assets/compiled/js/vendor.js
File not found: ./resources/assets/compiled/js/site.js

我使用sassstyles做了完全相同的事情,并且效果很好。

mix.sass([
  // Vendor
  'resources/assets/sass/fontawesome/font-awesome.scss',
  // Site
  'resources/assets/sass/site/site.scss'
], 'resources/assets/compiled/css/').styles([
  // Vendor
  'resources/assets/css/bootstrap.min.css',
  'resources/assets/css/hover-min.css',
  'resources/assets/css/leaflet.css',
  'resources/assets/compiled/css/font-awesome.css',
  // Site
  'resources/assets/compiled/css/site.css'
], 'public/css/all.css', './').version(
  'public/css/all.css'
)

1 个答案:

答案 0 :(得分:0)

为什么不一次合并脚本而不是3次?

试试这个

mix.coffee([
  // WebSocket Client
  'client.coffee'
], 'resources/assets/compiled/js/')
  .scripts([
    // Vendor
    'resources/assets/js/vendor/jquery.js',
    'resources/assets/js/vendor/bootstrap.js',
    'resources/assets/js/vendor/vue.js',
    'resources/assets/js/vendor/sisyphus.js',
    'resources/assets/js/vendor/leaflet.js',
    'resources/assets/js/vendor/moment.min.js',
    // Site & Helpers
    'resources/assets/js/libs/laravel.js',
    'resources/assets/js/libs/helpers.js',
    'resources/assets/compiled/js/client.js',
    'resources/assets/compiled/js/viewmodels.js'
  ], 'public/js/all.js', './');