pugkit 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -55,7 +55,7 @@ project-root/
55
55
 
56
56
  ### File Naming Rules
57
57
 
58
- `_`(アンダースコア)で始まるファイル・ディレクトリはビルド対象外です。それ以外のファイルは `src/` 配下のディレクトリ構成を維持したまま `dist/` に出力されます。
58
+ `_`(アンダースコア)で始まるファイル・ディレクトリはビルド対象外です。それ以外のファイルは `src/` 配下のディレクトリ構成を維持したまま `outDir`(デフォルト: `dist/`)に出力されます。
59
59
 
60
60
  ```
61
61
  src/foo/style.scss → dist/foo/style.css
@@ -73,6 +73,7 @@ import { defineConfig } from 'pugkit'
73
73
  export default defineConfig({
74
74
  siteUrl: 'https://example.com/',
75
75
  subdir: '',
76
+ outDir: 'dist',
76
77
  debug: false,
77
78
  server: {
78
79
  port: 5555,
@@ -85,19 +86,20 @@ export default defineConfig({
85
86
  })
86
87
  ```
87
88
 
88
- | Option | Description | Type / Values | Default |
89
- | ------------------------- | ------------------------------------------------------------------------------------------- | ----------------------------------- | ------------- |
90
- | `siteUrl` | サイトのベースURL(`Builder.url` に使用) | `string` | `''` |
91
- | `subdir` | サブディレクトリのパス | `string` | `''` |
92
- | `debug` | デバッグモード(開発時のみ有効) | `boolean` | `false` |
93
- | `server.port` | 開発サーバーのポート番号 | `number` | `5555` |
94
- | `server.host` | 開発サーバーのホスト | `string` | `'localhost'` |
95
- | `server.startPath` | サーバー起動時に開くパス | `string` | `'/'` |
96
- | `build.clean` | ビルド前に `dist/` をクリーンするか(`false` にすると他リソースと共存可能) | `boolean` | `true` |
97
- | `build.imageOptimization` | 画像最適化の方式 | `'webp'` \| `'compress'` \| `false` | `'webp'` |
98
- | `build.imageOptions.webp` | WebP変換オプション([Sharp WebP options](https://sharp.pixelplumbing.com/api-output#webp)) | `object` | - |
99
- | `build.imageOptions.jpeg` | JPEG圧縮オプション([Sharp JPEG options](https://sharp.pixelplumbing.com/api-output#jpeg)) | `object` | - |
100
- | `build.imageOptions.png` | PNG圧縮オプション([Sharp PNG options](https://sharp.pixelplumbing.com/api-output#png)) | `object` | - |
89
+ | Option | Description | Type / Values | Default |
90
+ | ------------------------- | -------------------------------------------------------------------------------------------- | ----------------------------------- | ------------- |
91
+ | `siteUrl` | サイトのベースURL(`Builder.url` に使用) | `string` | `''` |
92
+ | `subdir` | サブディレクトリのパス | `string` | `''` |
93
+ | `outDir` | ビルド出力先ディレクトリ。相対・絶対パス・ネスト(`htdocs/v2`)・上位(`../htdocs`)も指定可 | `string` | `'dist'` |
94
+ | `debug` | デバッグモード(開発時のみ有効) | `boolean` | `false` |
95
+ | `server.port` | 開発サーバーのポート番号 | `number` | `5555` |
96
+ | `server.host` | 開発サーバーのホスト | `string` | `'localhost'` |
97
+ | `server.startPath` | サーバー起動時に開くパス | `string` | `'/'` |
98
+ | `build.clean` | ビルド前に `outDir` をクリーンするか(`false` にすると他リソースと共存可能) | `boolean` | `true` |
99
+ | `build.imageOptimization` | 画像最適化の方式 | `'webp'` \| `'compress'` \| `false` | `'webp'` |
100
+ | `build.imageOptions.webp` | WebP変換オプション([Sharp WebP options](https://sharp.pixelplumbing.com/api-output#webp)) | `object` | - |
101
+ | `build.imageOptions.jpeg` | JPEG圧縮オプション([Sharp JPEG options](https://sharp.pixelplumbing.com/api-output#jpeg)) | `object` | - |
102
+ | `build.imageOptions.png` | PNG圧縮オプション([Sharp PNG options](https://sharp.pixelplumbing.com/api-output#png)) | `object` | - |
101
103
 
102
104
  ## Features
103
105
 
@@ -208,7 +210,7 @@ npm install --save-dev typescript
208
210
  `src/`配下の`icons/`ディレクトリに配置したSVGを1つのスプライトファイルにまとめます。
209
211
 
210
212
  ```
211
- src/assets/icons/arrow.svg → dist/assets/icons.svg#arrow
213
+ `src/assets/icons/arrow.svg → <outDir>/assets/icons.svg#arrow`
212
214
  ```
213
215
 
214
216
  ```html
@@ -220,7 +222,7 @@ src/assets/icons/arrow.svg → dist/assets/icons.svg#arrow
220
222
 
221
223
  ### Public Directory
222
224
 
223
- `public/` に置いたファイルはそのまま `dist/` のルートにコピーされます。faviconやOGP画像など最適化不要なファイルの置き場として使用します。
225
+ `public/` に置いたファイルはそのまま `outDir` のルートにコピーされます。faviconやOGP画像など最適化不要なファイルの置き場として使用します。
224
226
 
225
227
  ### Debug Mode
226
228
 
@@ -1,6 +1,7 @@
1
1
  export const defaultConfig = {
2
2
  siteUrl: '',
3
3
  subdir: '',
4
+ outDir: 'dist',
4
5
  debug: false,
5
6
  server: {
6
7
  port: 5555,
package/config/main.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { resolve } from 'node:path'
1
+ import { resolve, isAbsolute, relative } from 'node:path'
2
2
  import { existsSync } from 'node:fs'
3
3
  import { defaultConfig } from './defaults.mjs'
4
4
 
@@ -20,6 +20,7 @@ function mergeConfig(defaults, user) {
20
20
  return {
21
21
  siteUrl: user.siteUrl || defaults.siteUrl,
22
22
  subdir: user.subdir || defaults.subdir,
23
+ outDir: user.outDir !== undefined ? user.outDir : defaults.outDir,
23
24
  debug: user.debug !== undefined ? user.debug : defaults.debug,
24
25
  server: { ...defaults.server, ...(user.server || {}) },
25
26
  build: {
@@ -35,10 +36,32 @@ function mergeConfig(defaults, user) {
35
36
  }
36
37
  }
37
38
 
39
+ function validateConfig(config) {
40
+ const root = config.root
41
+ const outDir = config.outDir
42
+ const resolvedOutDir = isAbsolute(outDir) ? outDir : resolve(root, outDir)
43
+
44
+ // Vite同様、outDirがrootと同一またはrootの親ディレクトリの場合に警告
45
+ // relative() を使うことでWindows(バックスラッシュ)でも正しく動作する
46
+ const isSameAsRoot = resolvedOutDir === root
47
+ const relToRoot = relative(resolvedOutDir, root)
48
+ const isParentOfRoot = relToRoot !== '' && !relToRoot.startsWith('..')
49
+
50
+ if (isSameAsRoot || isParentOfRoot) {
51
+ console.warn(
52
+ `[pugkit] outDir "${outDir}" はプロジェクトルートと同じか親ディレクトリです。` +
53
+ `ソースファイルが上書きされる可能性があるため、別のディレクトリを指定してください。`
54
+ )
55
+ }
56
+
57
+ return config
58
+ }
59
+
38
60
  export async function loadConfig(root = process.cwd()) {
39
61
  const userConfig = await loadUserConfig(root)
40
62
  const config = mergeConfig(defaultConfig, userConfig)
41
63
  config.root = root
64
+ validateConfig(config)
42
65
  return config
43
66
  }
44
67
 
package/core/context.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { resolve } from 'node:path'
1
+ import { resolve, isAbsolute } from 'node:path'
2
2
  import { CacheManager } from './cache.mjs'
3
3
  import { DependencyGraph } from './graph.mjs'
4
4
  import { createGlobPatterns } from '../config/index.mjs'
@@ -12,10 +12,14 @@ export class BuildContext {
12
12
  this.sassGraph = new DependencyGraph()
13
13
  this.scriptGraph = new DependencyGraph()
14
14
 
15
+ const outDir = config.outDir ?? 'dist'
16
+ const resolvedOutDir = isAbsolute(outDir) ? outDir : resolve(config.root, outDir)
17
+
15
18
  this.paths = {
16
19
  root: config.root,
17
20
  src: resolve(config.root, 'src'),
18
- dist: resolve(config.root, 'dist', config.subdir || ''),
21
+ outDir: resolvedOutDir,
22
+ dist: config.subdir ? resolve(resolvedOutDir, config.subdir) : resolvedOutDir,
19
23
  public: resolve(config.root, 'public')
20
24
  }
21
25
 
package/core/server.mjs CHANGED
@@ -50,7 +50,7 @@ export async function serverTask(context, options = {}) {
50
50
  const startPath = (config.server?.startPath || '/').replace(/^\//, '')
51
51
  const fullStartPath = subdir ? `${subdir}/${startPath}` : `/${startPath}`
52
52
 
53
- const serveRoot = path.resolve(config.root, 'dist')
53
+ const serveRoot = paths.outDir
54
54
 
55
55
  const clients = new Set()
56
56
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pugkit",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "A build tool for Pug-based projects",
5
5
  "type": "module",
6
6
  "license": "MIT",