Tue Jul 31 2018
Copied to clipboard! Copy reply
  • 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
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
const fs = require('fs')
const _ = require('lodash') 
const axios = require('axios')

// Underscore is only needed for intersect fn
// Once flatMap is supported, remove it.


module.exports = {

  /*
  render: {
    bundleRenderer: {
      shouldPreload: (file, type) => {
        if (type === 'font') return /.woff2/.test(file)
        return ['script', 'style'].includes(type)
      }
    }
  },
  */

  
  // Config for `nuxt generate`
  generate: {
    dir: 'dist/lp/',
    interval: 500,
    async routes ()
    {
      /*
       * `models[]` must be an array of `template/page` elements.
       * we get templates by scanning the local `pages/lp/` directory,
       * and each model (sitewide, rmsitewide, sale, etc) will
       * come from Airtable. The final array should look like
       * [sbsr/sitewide, sbsr/sale, foo/sitewide, foo/sale, etc]
       */
      const templates = fs.readdirSync(__dirname + '/pages/')

      // Get a list of pages to generate. Instead of using Airtable,
      // fetch it from a pages.json file.
      // TODO we could fetch this from local if we run 'generate-marketing-data' first
      let models = await axios.get('http://www.rosettastone.com/lp/static/data/us/pages.json')      
      
      // ['sitewide', 'rmsitewide', 'sale', etc]
      models = models.data.map(o => o.name)

      models = _.flatMapDeep(templates.map(t => models.map(m => `${t}/${m}`)))      
      return models
    }  
  },
  
  router: {
    // Let Nuxt know our app resides in rs.com/lp/, and /lp/ is the base.
    // This will let Nuxt know to look for js files in /lp/_nuxt/foo.js
    // instead of /_nuxt/foo.js when generating the static pages.
    base: '/lp/' 
  },


  loading: false,
  
  /*
  ** Build configuration
  */ 
  build: {
    extractCSS: true,
    // Uncomment this if you want to analyze your build size
    //analyze: true, 
    
    // The default is _nuxt. We change it to _nuxt_lp
    // so we can have multiple Nuxt projects inside /lp/
    // ie, _nuxt_lp, _nuxt_catalogs, etc
    publicPath: '/_nuxt_lp/',
    
    // Run ESLint on save
    extend (config, { isDev, isClient }) {
      if (isDev && isClient) {
        
        config.module.rules.push(
          {
            enforce: 'pre',
            test: /\.(js|vue)$/,
            loader: 'eslint-loader',
            exclude: /(node_modules)/
          },
          { test: /\.css$/, use: [ 'vue-style-loader','css-loader'],
        })
      }
    }
  }
}