npx nuxi init app-filenameでインストール。
■ホスト(IP)指定の方法
package.json にhost指定するパターン。
"config": {
"nuxt": {
"host": "0.0.0.0",
"port": "3000"
}
},
nuxt.config.js に記載する方法
export default {
server: {
port: 8000, // デフォルト: 3000
host: '0.0.0.0' // デフォルト: localhost
}
// ~ 省略 ~
}
■Buildの高速化
nuxt.config.jsに下記3行を追加。
export default { build: { parallel: true, //<-追加 cache: true, //<-追加 hardSource: true, //<-追加 2回目移行のbuildを行うと、キャッシュ問題でエラーを起こす可能性がある。 その場合、キャッシュを削除する
rm -rf node_modules/.cache/hard-source/
また、キャッシュを設定しないというもの有効。
hardSource: true
■開発の効率化
コマンドを作成して起動と停止を手軽にする
#!/bin/bash
if [ $1 = start ]; then
echo "Starting nuxtjs..."
nohup yarn start &
fi
if [ $1 = stop ]; then
echo "Stoping nuxtjs..."
kill -9 $(lsof -t -i:3000)
fi
if [ $1 = reboot ]; then
echo "Stoping nuxtjs..."
kill -9 $(lsof -t -i:3000)
echo "Starting nuxtjs..."
nohup yarn start &
fi
■CSSを追加
nuxt.config.jsに共通のCSSを追加する。
追加する際、assetsフォルダがない場合、直下にフォルダを設置する
module.exports = {
css: [ '~/assets/css/style.css', ]
}