LoginSignup
10
10

More than 5 years have passed since last update.

grunt-contrib-connectでのルートフォルダ指定

Posted at

全然大したことではないけど一応メモ

自分のprojectファイルの構成は以下みたいな感じにしたい。


├── README.md
├── config
│   └── config.rb
├── docs
│   └── styles
├── gruntfile.js
├── htdocs
│   ├── css
│   │   ├── _dev
│   │   │   ├── _scss
│   │   │   │   ├── mixin
│   │   │   │   │   └── libs
│   │   │   │   ├── style.scss
│   │   │   │   └── vars
│   │   │   └── style.css
│   │   └── style.css
│   ├── img
│   └── index.html
└── package.json

けど、どっかからコピペしてきたgurunt.jsの設定だとgrunt-contrib-connectでローカルサーバーを立ち上げたときにルートがprojectフォルダになってしまっていたのでhtdocsをルートにするためにgrunt-contrib-connectのタスクを以下のように書き換え。

grunt.js
var path = require('path');
var lrSnippet = require('grunt-contrib-livereload/lib/utils').livereloadSnippet;
var folderMount = function(connect, dir) {
    return connect.static(path.resolve(dir));
};
module.exports = function(grunt) {
 grunt.initConfig({
  connect: {
   server: {
    options: {
     port: 9001,
      middleware: function(connect, options) {
       return [
        lrSnippet,
        folderMount(connect, 'htdocs') //ここでルートにしたいフォルダを指定
       ];
      }
     }
   }
  },
 });
};
10
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
10