Add per-env webpack configuration files

This commit is contained in:
0x1eef 2024-02-18 09:24:54 -03:00
parent 3277fbd399
commit 1f6f039ba3
11 changed files with 105 additions and 111 deletions

View file

@ -14,11 +14,11 @@ gem "rainpress", "~> 1.0"
gem "sass", "~> 3.7"
##
# Ruby web server
# Web server
gem "server.rb", path: "./packages/ruby/server"
##
# Everything else
# Other
gem "ryo.rb"
gem "test-cmd.rb"
gem "lockf.rb"

View file

@ -2,12 +2,8 @@ PATH
remote: packages/ruby/server
specs:
server.rb (0.1.0)
json (= 2.6.1)
puma (~> 6.3)
racc (= 1.6.0)
rack (~> 3.0)
set (= 1.0.2)
stringio (= 3.0.1)
GEM
remote: https://rubygems.org/
@ -26,7 +22,7 @@ GEM
immutable-ruby (0.1.0)
concurrent-ruby (~> 1.1)
sorted_set (~> 1.0)
json (2.6.1)
json (2.7.1)
json_schema (0.21.0)
language_server-protocol (3.17.0.3)
lint_roller (1.1.0)
@ -69,14 +65,10 @@ GEM
nanoc-checking (~> 1.0)
nanoc-cli (~> 4.11, >= 4.11.15)
nanoc-core (~> 4.11, >= 4.11.15)
nanoc-gzip.rb (0.2.2)
json (= 2.6.1)
nanoc-gzip.rb (0.2.3)
nanoc (~> 4.12)
racc (= 1.6.0)
set (= 1.0.2)
stringio (= 3.0.1)
nanoc-tidy.rb (0.2.2)
nanoc-webpack.rb (0.5.5)
nanoc-webpack.rb (0.5.6)
ryo.rb (~> 0.4)
nio4r (2.7.0)
paint (2.3.0)
@ -91,7 +83,7 @@ GEM
public_suffix (5.0.4)
puma (6.4.2)
nio4r (~> 2.0)
racc (1.6.0)
racc (1.7.3)
rack (3.0.9)
rainbow (3.1.1)
rainpress (1.0.1)
@ -102,11 +94,11 @@ GEM
rbtree (0.4.6)
regexp_parser (2.9.0)
rexml (3.2.6)
rubocop (1.59.0)
rubocop (1.60.2)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.2.2.4)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
@ -125,15 +117,15 @@ GEM
sass-listen (4.0.0)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
set (1.0.2)
set (1.1.0)
slow_enumerator_tools (1.1.0)
sorted_set (1.0.3)
rbtree
set (~> 1.0)
standard (1.33.0)
standard (1.34.0)
language_server-protocol (~> 3.17.0.2)
lint_roller (~> 1.0)
rubocop (~> 1.59.0)
rubocop (~> 1.60)
standard-custom (~> 1.0.0)
standard-performance (~> 1.3)
standard-custom (1.0.2)
@ -142,7 +134,7 @@ GEM
standard-performance (1.3.1)
lint_roller (~> 1.1)
rubocop-performance (~> 1.20.2)
stringio (3.0.1)
stringio (3.1.0)
test-cmd.rb (0.5.2)
tty-color (0.6.0)
tty-command (0.10.1)
@ -150,10 +142,11 @@ GEM
tty-platform (0.3.0)
tty-which (0.5.0)
unicode-display_width (2.5.0)
zeitwerk (2.6.12)
zeitwerk (2.6.13)
PLATFORMS
x86_64-openbsd
amd64-freebsd-14
ruby
DEPENDENCIES
dotenv (~> 2.8)
@ -174,4 +167,4 @@ DEPENDENCIES
test-cmd.rb
BUNDLED WITH
2.4.19
2.5.3

5
Rules
View file

@ -18,6 +18,11 @@ i18n = Ryo.from(
)
)
buildenv = ENV["buildenv"] || "development"
Nanoc::Webpack.default_options.merge!(
"--config" => "webpack.#{buildenv}.js"
)
def require_rules(rules, locals = {}, target = binding)
locals.each { target.local_variable_set(_1, _2) }
path = File.join(Dir.getwd, rules)

33
package-lock.json generated
View file

@ -28,7 +28,8 @@
"typescript": "^4.8.2",
"url": "^0.11.3",
"webpack": "^5.74.0",
"webpack-cli": "^4.10.0"
"webpack-cli": "^4.10.0",
"webpack-merge": "^5.10.0"
}
},
"../../packages/typescript/packet": {
@ -1985,6 +1986,15 @@
"node": ">=8"
}
},
"node_modules/flat": {
"version": "5.0.2",
"resolved": "https://registry.npmjs.org/flat/-/flat-5.0.2.tgz",
"integrity": "sha512-b6suED+5/3rTpUBdG1gupIl8MPFCAMA0QXwmljLhvCUKcUvdE4gWky9zpuGCcXHOsz4J9wPGNWq6OKpmIzz3hQ==",
"dev": true,
"bin": {
"flat": "cli.js"
}
},
"node_modules/flat-cache": {
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-3.0.4.tgz",
@ -4316,13 +4326,13 @@
}
},
"node_modules/webpack-merge": {
"version": "5.8.0",
"resolved": "https://registry.npmjs.org/webpack-merge/-/webpack-merge-5.8.0.tgz",
"integrity": "sha512-/SaI7xY0831XwP6kzuwhKWVKDP9t1QY1h65lAFLbZqMPIuYcD9QAW4u9STIbU9kaJbPBB/geU/gLr1wDjOhQ+Q==",
"version": "5.10.0",
"resolved": "https://registry.npmjs.org/webpack-merge/-/webpack-merge-5.10.0.tgz",
"integrity": "sha512-+4zXKdx7UnO+1jaN4l2lHVD+mFvnlZQP/6ljaJVb4SZiwIKeUnrT5l0gkT8z+n4hKpC+jpOv6O9R+gLtag7pSA==",
"dev": true,
"license": "MIT",
"dependencies": {
"clone-deep": "^4.0.1",
"flat": "^5.0.2",
"wildcard": "^2.0.0"
},
"engines": {
@ -5856,6 +5866,12 @@
"path-exists": "^4.0.0"
}
},
"flat": {
"version": "5.0.2",
"resolved": "https://registry.npmjs.org/flat/-/flat-5.0.2.tgz",
"integrity": "sha512-b6suED+5/3rTpUBdG1gupIl8MPFCAMA0QXwmljLhvCUKcUvdE4gWky9zpuGCcXHOsz4J9wPGNWq6OKpmIzz3hQ==",
"dev": true
},
"flat-cache": {
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-3.0.4.tgz",
@ -7443,12 +7459,13 @@
}
},
"webpack-merge": {
"version": "5.8.0",
"resolved": "https://registry.npmjs.org/webpack-merge/-/webpack-merge-5.8.0.tgz",
"integrity": "sha512-/SaI7xY0831XwP6kzuwhKWVKDP9t1QY1h65lAFLbZqMPIuYcD9QAW4u9STIbU9kaJbPBB/geU/gLr1wDjOhQ+Q==",
"version": "5.10.0",
"resolved": "https://registry.npmjs.org/webpack-merge/-/webpack-merge-5.10.0.tgz",
"integrity": "sha512-+4zXKdx7UnO+1jaN4l2lHVD+mFvnlZQP/6ljaJVb4SZiwIKeUnrT5l0gkT8z+n4hKpC+jpOv6O9R+gLtag7pSA==",
"dev": true,
"requires": {
"clone-deep": "^4.0.1",
"flat": "^5.0.2",
"wildcard": "^2.0.0"
}
},

View file

@ -28,6 +28,7 @@
"typescript": "^4.8.2",
"url": "^0.11.3",
"webpack": "^5.74.0",
"webpack-cli": "^4.10.0"
"webpack-cli": "^4.10.0",
"webpack-merge": "^5.10.0"
}
}

View file

@ -11,14 +11,6 @@ Gem::Specification.new do |gem|
gem.summary = "A static file web server"
gem.description = gem.summary
##
# Default gems
# Pinned to specific versions for OpenBSD support
gem.add_runtime_dependency "json", "= 2.6.1"
gem.add_runtime_dependency "racc", "= 1.6.0"
gem.add_runtime_dependency "stringio", "= 3.0.1"
gem.add_runtime_dependency "set", "= 1.0.2"
gem.add_runtime_dependency "puma", "~> 6.3"
gem.add_runtime_dependency "rack", "~> 3.0"
gem.add_development_dependency "standard", "~> 1.24"

View file

@ -1,63 +1,38 @@
# frozen_string_literal: true
require "fileutils"
require "lockf"
build_dir = Ryo.from(YAML.load_file("./nanoc.yaml")).output_dir
lockp = File.join Dir.getwd, "tmp", "build.lock"
FileUtils.mkdir_p File.dirname(lockp)
FileUtils.touch(lockp)
lockf = LockFile.new(lockp)
namespace :nanoc do
task compile: %w[clean:css] do
warn "[build] Acquire lock..."
lockf.lock
ENV["SASS_PATH"] = "./src/css/"
sh "bundle exec nanoc co"
rescue Interrupt
warn "SIGINT: exit"
exit
ensure
warn "[build] Release lock..."
lockf.release
end
require "bundler/setup"
cwd = File.realpath File.join(__dir__, "..")
desc "Clean the build/ directory"
task :clean do
warn "[build] Acquire lock..."
lockf.lock
sh "rm -rf #{build_dir}"
ensure
warn "[build] Release lock..."
lockf.release
Dir.chdir(cwd) do
sh "rm -rf node_modules/.cache/"
sh "rm -rf build"
end
end
task "clean:css" do
warn "[build] Acquire lock..."
lockf.lock
cssdir = File.join(build_dir, "css")
sh "rm -rf #{cssdir}" if Dir.exist?(cssdir)
ensure
warn "[build] Release lock..."
lockf.release
desc "Produce the build/ directory"
task :build, [:buildenv] do |t, args|
Dir.chdir(cwd) do
buildenv = args.buildenv || ENV["buildenv"] || "development"
sh "rm -rf build/css/"
Bundler.with_unbundled_env {
sh "buildenv=#{buildenv} bundle exec nanoc co"
}
end
end
task watch: %w[build] do
require "listen"
Listen.to File.join(Dir.getwd, "src"), force_polling: true do
sh "rake build"
end.start
sleep
desc "Produce the build/ directory on-demand"
task watch: ['nanoc:build'] do
Dir.chdir(cwd) do
require "listen"
path = File.join(Dir.getwd, "src")
Listen.to(path) do
Bundler.with_unbundled_env { sh "rake nanoc:build" }
end.start
sleep
end
rescue Interrupt
warn "SIGINT: exit"
exit
end
end
desc "Build the website"
task build: %w[nanoc:compile]
desc "Trigger a build when src/ is modified"
task "build:watch" => "nanoc:watch"
desc "Clean the build directory"
task clean: "nanoc:clean"

19
webpack.common.js Normal file
View file

@ -0,0 +1,19 @@
const path = require("path");
const process = require("process");
module.exports = {
resolve: {
roots: [path.resolve("src/js"), path.resolve("node_modules")],
modules: [path.resolve("src/js"), path.resolve("node_modules")],
extensions: [".js", ".ts", ".tsx"],
},
module: {
rules: [
{
test: /\.tsx?$/,
use: "ts-loader",
exclude: /node_modules/,
},
],
},
};

View file

@ -1,20 +0,0 @@
const path = require('path');
const process = require('process');
module.exports = {
mode: process.env.NODE_ENV || "development",
resolve: {
roots: [path.resolve('src/js'), path.resolve('node_modules')],
modules: [path.resolve('src/js'), path.resolve('node_modules')],
extensions: ['.js', '.ts', '.tsx']
},
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
],
},
}

6
webpack.development.js Normal file
View file

@ -0,0 +1,6 @@
const { merge } = require('webpack-merge');
const common = require('./webpack.common.js');
module.exports = merge(
common,
{mode: "development"}
)

6
webpack.production.js Normal file
View file

@ -0,0 +1,6 @@
const { merge } = require('webpack-merge');
const common = require('./webpack.common.js');
module.exports = merge(
common,
{mode: "production"}
)