Vue CLI 3:使用Foundation 6构建生产

时间:2018-11-16 22:55:49

标签: javascript webpack zurb-foundation zurb-foundation-6 vue-cli-3

我有一个Vue CLI 3项目,其内容如下所示:./src/main.js:

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()

在带有“纱线投放”的生产模式下运行时,所有内容均可很好地编译。

但是,当我运行'yarn build'时,基础CSS和JS都不存在于生产版本中。 ./assets/scss/styles.scss可以正常工作,但是我没有Foundation样式,并且还出现错误:

  

TypeError:z(...)(...)。foundation不是函数

我想Webpack或我的Vue配置一般都缺少一些东西,所以这里是供参考的文件:

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 个答案:

答案 0 :(得分:0)

首先,更改

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

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

然后添加:

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

或者,您可以代替Vue.use()执行此操作:

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

答案来自here。请参阅rafaeldiaz21的评论。