简体   繁体   中英

Vue.js + Foundation + Webpack configuration

I am just trying to add the foundation.css file to my Vue webpack app. I've installed foundation via

- npm install foundation-sites .

I then installed extract text plugin

-- npm install extract-text-webpack-plugin 
--save-dev. 

I am not sure how to go about the next step.

APP.vue

<template>
<div id="app">
<img src="./assets/logo.png">
<hello></hello>
</div>
</template>

<script>
import Hello from './components/Hello'

export default {
name: 'app',
components: {
Hello
}
}
</script>

<style>
import '../node_modules/foundation-sites/dist/foundation.css'
#app {
font-family: 'Avenir', Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
 text-align: center;
 color: #2c3e50;
 margin-top: 60px;
 }
 </style>

Webpack.config.js

var path = require('path')
var config = require('../config')
var utils = require('./utils')
var projectRoot = path.resolve(__dirname, '../')
var ExtractTextPlugin = require("extract-text-webpack-plugin");
module.exports = {
entry: {
app: './src/main.js'
 },
 output: {
path: config.build.assetsRoot,
publicPath: process.env.NODE_ENV === 'production' ?      config.build.assetsPublicPath : config.dev.assetsPublicPath,
filename: '[name].js'
 },
 resolve: {
 extensions: ['', '.js', '.vue'],
 fallback: [path.join(__dirname, '../node_modules')],
  alias: {
  'vue$': 'vue/dist/vue',
  'src': path.resolve(__dirname, '../src'),
  'assets': path.resolve(__dirname, '../src/assets'),
  'components': path.resolve(__dirname, '../src/components')
  }
  },
  resolveLoader: {
  fallback: [path.join(__dirname, '../node_modules')]
  },
 module: {
  preLoaders: [
  {
    test: /\.vue$/,
    loader: 'eslint',
    include: projectRoot,
    exclude: /node_modules/
  },
  {
    test: /\.js$/,
    loader: 'eslint',
    include: projectRoot,
    exclude: /node_modules/
  }
   ],
   loaders: [
  {
    test: /\.vue$/,
    loader: 'vue'
  },
  {
    test: /\.js$/,
    loader: 'babel',
    include: projectRoot,
    exclude: /node_modules/
  },
  {
    test: /\.json$/,
    loader: 'json'
  },
  {
    test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
    loader: 'url',
    query: {
      limit: 10000,
      name: utils.assetsPath('img/[name].[hash:7].[ext]')
    }
  },
  {
    test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
    loader: 'url',
    query: {
      limit: 10000,
      name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
    }
  }
  ]
 },
 eslint: {
 formatter: require('eslint-friendly-formatter')
 },
 vue: {
  loaders: utils.cssLoaders(),
 postcss: [
  require('autoprefixer')({
    browsers: ['last 2 versions']
  })
 ]
 },
 vue: {
loaders: {
  css: ExtractTextPlugin.extract("css")
}
},
 plugins: [
new ExtractTextPlugin("style.css")
]
}

Added this to the index.html file:

`<link rel="stylesheet" href="node_modules/foundation- sites/dist/foundation.css"> ` 

Something a noob would do just to see if it would work, nothing appears within the source when the app is live.

UPDATE -- getting this error now in the terminal --

ERROR in ./~/extract-text-webpack-plugin/loader.js?{"remove":true}!./~/css-loader!./~/vue-loader/lib/style-rewriter.js?id=data-v-511fb858!./~/vue-loader/lib/selector.js?type=styles&index=0!./src/App.vue
Module build failed: CssSyntaxError: /Users/uz067252/Documents/Development/Vue/xwebpack/App.vue?40a2fca0:21:0: Unknown word
    at Input.error (/Users/uz067252/Documents/Development/Vue/xwebpack/node_modules/vue-loader/node_modules/postcss/lib/input.js:111:22)
    at Parser.unknownWord (/Users/uz067252/Documents/Development/Vue/xwebpack/node_modules/vue-loader/node_modules/postcss/lib/parser.js:457:26)
    at Parser.other (/Users/uz067252/Documents/Development/Vue/xwebpack/node_modules/vue-loader/node_modules/postcss/lib/parser.js:174:14)
    at Parser.loop (/Users/uz067252/Documents/Development/Vue/xwebpack/node_modules/vue-loader/node_modules/postcss/lib/parser.js:81:26)
    at parse (/Users/uz067252/Documents/Development/Vue/xwebpack/node_modules/vue-loader/node_modules/postcss/lib/parse.js:26:16)
    at new LazyResult (/Users/uz067252/Documents/Development/Vue/xwebpack/node_modules/vue-loader/node_modules/postcss/lib/lazy-result.js:70:24)
    at Processor.process (/Users/uz067252/Documents/Development/Vue/xwebpack/node_modules/vue-loader/node_modules/postcss/lib/processor.js:117:12)
    at Object.module.exports (/Users/uz067252/Documents/Development/Vue/xwebpack/node_modules/vue-loader/lib/style-rewriter.js:96:6)
 @ ./src/App.vue 4:0-193

The foundation CSS is not loaded because there's no CSS loader applied on it

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

Instead you need something like this

require("!style!css!sass!../node_modules/foundation-sites/dist/foundation.css");

@flyingSmurfs :
I saw the project was generated using vue-cli . so the css-loader had been installed.
loaders: utils.cssLoaders() will configure css-loader in webpack.

@userlkjsflkdsvm :
import 'xxx.css' should be put into <script>..</script> or *.js .
I recommend to put the sentence in main.js (the entry js file of your project).
I saw you import css in <style>...</style> section. It is wrong.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM