-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathastro.config.mjs
75 lines (64 loc) · 2.25 KB
/
astro.config.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { defineConfig } from 'astro/config';
// https://zenn.dev/ixkaito/articles/astro-relative-links
import relativeLinks from 'astro-relative-links';
import compress from "astro-compress";
import htmlBeautifier from "astro-html-beautifier";
// https://astro.build/config
export default defineConfig({
// devToolbar: { enabled: false },
//開発時の末尾のスラッシュの挙動を一貫させるため、常に末尾にスラッシュを追加する
trailingSlash: 'always',
server: {port: 3000},
//HTMLの圧縮を無効化
compressHTML: false,
build: {
inlineStylesheets: `never`,
},
integrations: [
//相対リンクを有効化
relativeLinks(),
//
//圧縮設定
(await import("astro-compress")).default({
CSS: true,
HTML: false,
JavaScript: true,
Image:true,
SVG:true,
}),
htmlBeautifier()],
vite: {
build: {
// minify: false,
rollupOptions: {
output: {
//https://cumak.net/blog/astro/ cssのファイル名をわかりやすいものに
assetFileNames: assetInfo => {
if(assetInfo.name === 'index.css') {
return `assets/css/style.css`;
}
return `assets/[ext]/[name][extname]`;
},
entryFileNames: (entryInfo) => {
console.log(entryInfo)
//entryInfo.moduleIdsの中に、srcの文字列を含むものがあったら
if(entryInfo.moduleIds.some(moduleId => moduleId.includes('src'))) {
//entryInfo.moduleIdsの中から、srcとastroを含むものを取得
let filePath = entryInfo.moduleIds.find(moduleId => moduleId.includes('src') && moduleId.includes('.astro'));
console.log(filePath)
if(filePath === undefined) {
return `assets/js/bundle.js`;
}
let parts = filePath.split('/');
let fullName = parts[parts.length - 1].split('?')[0];
let newFileName = fullName.split('.astro')[0];
//取得したファイル名を元に、ファイル名を変更
return `assets/js/${newFileName}.js`;
}
return `assets/js/[name].js`;
},
}
}
}
}
});