Sha256: f57eb07ecafb9ff840345545ab10c13657cd93988c895c91f02dd8a4217cdd1e

Contents?: true

Size: 1.11 KB

Versions: 2

Compression:

Stored size: 1.11 KB

Contents

require 'fileutils'
require 'pty'

namespace :webpack_manifest_plugin do
  desc 'Deletes all files in <app root>/public/assets.'
  task clean: :environment do
    app_root = WebpackManifestPlugin.app_root.to_s
    folder = File.join(app_root, 'public/assets')
    if !app_root.empty? && Dir.exist?(folder)
      FileUtils.remove_entry_secure(folder, secure: true)
    else
      puts "Directory #{folder} not found."
    end
  end

  desc "Run webpack. Assumes webpack is installed at node_modules/webpack/bin/webpack.
  Use with or without options. Examples:
     rake webpack_manifest_plugin:build
     rake webpack_manifest_plugin:build['-d --config webpack.config.prod.js']"
  task :build, [:options] => :environment do |_task, args|
    cmd = "#{WebpackManifestPlugin.configuration.webpack_cmd} #{args[:options]}"
    puts "Executing #{cmd}..."

    begin
      PTY.spawn(cmd) do |stdout, _stdin, _pid|
        begin
          stdout.each { |line| print line }
        rescue Errno::EIO
          puts 'The process has finished.'
        end
      end
    rescue PTY::ChildExited
      puts 'webpack exited!'
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
webpack_manifest_plugin-0.1.2 lib/webpack_manifest_plugin/tasks/main.rake
webpack_manifest_plugin-0.1.1 lib/webpack_manifest_plugin/tasks/main.rake