diff --git a/Gemfile b/Gemfile index d896f751a..00c2fb408 100644 --- a/Gemfile +++ b/Gemfile @@ -4,6 +4,7 @@ source "https://rubygems.org" gem "nanoc", "~> 4.12" gem "nanoc-live", "~> 1.0" gem "nanoc-gunzip.rb", "~> 0.1" +gem "nanoc-webpack.rb", "~> 0.1", git: "https://github.com/0x1eef/nanoc-webpack.rb" gem "rainpress", "~> 1.0" gem "sass" gem "standardrb" diff --git a/Gemfile.lock b/Gemfile.lock index 2f1ca1f5e..2b5224566 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,3 +1,9 @@ +GIT + remote: https://github.com/0x1eef/nanoc-webpack.rb + revision: 8d821be4f7d45abaaf79aa9d7656590d158f6d3f + specs: + nanoc-webpack.rb (0.1.0) + GEM remote: https://rubygems.org/ specs: @@ -141,6 +147,7 @@ DEPENDENCIES nanoc (~> 4.12) nanoc-gunzip.rb (~> 0.1) nanoc-live (~> 1.0) + nanoc-webpack.rb (~> 0.1)! paint puma rainpress (~> 1.0) diff --git a/Rules b/Rules index 4745116f5..c9fe6b11d 100644 --- a/Rules +++ b/Rules @@ -2,6 +2,7 @@ # frozen_string_literal: true require "ryo" require "nanoc-gunzip" +require "nanoc-webpack" LOCALES = %w[ar en] SURAH_ID_TO_SLUG = Ryo.from( diff --git a/lib/filters/webpack.rb b/lib/filters/webpack.rb deleted file mode 100644 index 254245baf..000000000 --- a/lib/filters/webpack.rb +++ /dev/null @@ -1,39 +0,0 @@ -# frozen_string_literal: true - -## -# Compiles a JavaScript / TypeScript asset with webpack. -class Nanoc::Filter::Webpack < Nanoc::Filter - include FileUtils - - identifier :webpack - type :text - always_outdated - - def run(content, options = {}) - webpack(temp_file(content)) - end - - private - - def webpack(file) - system "node", - "./node_modules/webpack/bin/webpack.js", - "--entry", File.join("./src", item.identifier.to_s), - "--output-path", File.dirname(file.path), - "--output-filename", File.basename(file.path) - if $?.success? - File.read(file.path).tap { file.tap(&:unlink).close } - else - file.tap(&:unlink).close - exit!($?.exitstatus) - end - end - - def temp_file(content) - dir = File.join(Dir.getwd, "tmp", "webpack") - mkdir_p(dir) unless Dir.exist?(dir) - file = Tempfile.new(File.basename(item.identifier.to_s), dir) - file.write(content) - file.tap(&:flush) - end -end