Vue CLI 3: production build with Foundation 6

1.5k Views Asked by At

I have a Vue CLI 3 project with a ./src/main.js that looks like this:

import Vue from 'vue'
import App from './App.vue'
import router from './router'
import jQuery from 'jquery'
import 'foundation-sites/dist/css/foundation.min.css'
import './assets/scss/styles.scss'
import 'foundation-sites'

Vue.config.productionTip = false

new Vue({
  router,
  render: h => h(App)
}).$mount('#app')

jQuery(document).foundation()

When running in production mode with 'yarn serve', everything compiles nicely.

However, when I run 'yarn build', neither the Foundation CSS nor the JS are present in the production build. The ./assets/scss/styles.scss works fine, but I get no Foundation styling, and am also presented with the error:

TypeError: z(...)(...).foundation is not a function

I'm guessing something is missing either with Webpack or my Vue config in general, so here's that file for reference:

const path = require('path');

module.exports = {
  baseUrl: process.env.NODE_ENV === 'production'
    ? '/coe_petition/' // asset url prefix in production mode
    : '/', // asset url prefix in development mode
  outputDir: '../../coe_petition', // running 'yarn build' will send production code here
  pluginOptions: {
    "style-resources-loader": {
      preProcessor: "scss",
      patterns: [path.resolve(__dirname, "./src/styles/scss/styles.scss")]
    }
  },
  configureWebpack: {
    resolve:{
      alias: {
        '^': path.resolve(__dirname, '/usr/local/vueapps/shared/src'),
        't^': path.resolve(__dirname, '/usr/local/lib/layouts')
      }
    }
  }
}
1

There are 1 best solutions below

0
On

First, change

import 'foundation-sites/dist/css/foundation.min.css'
import 'foundation-sites'

to

import FoundationCss from 'foundation-sites/dist/css/foundation.min.css'
import FoundationJs from 'foundation-sites'

Then, add:

Vue.use(FoundationCss)
Vue.use(FoundationJs)

Alternatively, you can do this instead of Vue.use():

new Vue({
  FoundationCss,
  FoundationJs,
  router,
  render: h => h(App)
}).$mount('#app')

The answer came from here. See rafaeldiaz21's comment.