【问题标题】:Laravel Elixir: How to minify files?Laravel Elixir:如何缩小文件?
【发布时间】:2015-07-26 00:21:44
【问题描述】:

我想使用 Laravel Elixir 来缩小我的 css/files 文件。但我不想使用混合方法并合并它们。我想要的只是从我原来的“custom.js”生成一个“custom.min.js”文件。有没有办法用 Elexir 做到这一点?

编辑: 为了更清楚一点:我最大的问题是我在“资源/资产”中有两个文件夹:js 和 css。所以我基本上想缩小那里的所有文件,并在“public/js”和“public/css”中缩小它们。

【问题讨论】:

    标签: laravel laravel-5 gulp laravel-elixir


    【解决方案1】:

    引用自Laravel documentation

    注意:所有任务都将假定一个开发环境,并且不包括缩小。对于生产,请使用gulp --production

    这意味着如果您想要缩小文件,请运行 gulp --production 而不仅仅是 gulp。这比直接在 gulp 文件中启用压缩更好,并确保您可以在开发应用程序时调试已编译的文件。

    如果您希望将它们放在public/assets/css 中,请使用路径作为第二个参数:

    mix.less('app.less', 'public/assets/css');
    

    【讨论】:

    • 我更喜欢同时运行 gulp,这样您就可以同时获得开发文件和生产文件。然后在我的应用程序中,根据环境,我只需加载适当的应用程序。这比每次都必须记住运行缩小要好得多。
    【解决方案2】:

    gulp --生产。

    Jeffrey Way 在这里回复了这个问题:https://laracasts.com/discuss/channels/elixir/elixir-doesnt-minify

    或者您可以在文档中找到它。享受编码!

    【讨论】:

      【解决方案3】:

      如果您只想复制.css 文件,而不使用LESS 或SASS,并且不想合并文件(即您想要具有缩小能力的copy() 方法),您可以使用合并方法, styles(),通过为每个 .css 文件调用它并传递不带数组的文件名字符串,例如:

      mix.styles('some.css');
      mix.styles('node_modules/bootstrap/dist/css/bootstrap.css', null, './');
      

      使用scripts() 方法对.js 文件也可以这样做:

      mix.scripts('some.js');
      mix.scripts('node_modules/bootstrap/dist/js/bootstrap.js', null, './');
      

      然后你可以使用上面帖子中提到的gulp(不缩小,创建.map文件)或gulp --production(创建缩小文件)。

      【讨论】:

        【解决方案4】:

        直接来自 Laravel/Elixir 文档:

        Elixir is built on top of Gulp, so to run your Elixir tasks you only need to run the gulp command in your terminal. Adding the --production flag to the command will instruct Elixir to minify your CSS and JavaScript files:
        
        Run all tasks... gulp
        
        Run all tasks and minify all CSS and JavaScript... gulp --production
        

        文档:https://laravel.com/docs/5.3/elixir#running-elixir

        【讨论】:

          猜你喜欢
          • 2018-01-16
          • 1970-01-01
          • 2016-10-02
          • 1970-01-01
          • 2018-08-01
          • 2020-01-19
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多