gpt4 book ai didi

javascript - Vue.js + 基础 + Webpack 配置

转载 作者:行者123 更新时间:2023-12-02 14:05:02 29 4
gpt4 key购买 nike

我只是想将 foundation.css 文件添加到我的 Vue webpack 应用程序中。我已经通过

安装了基础

- npm install Foundation-sites

然后我安装了提取文本插件

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

我不知道下一步该如何进行。

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")
]
}

将此添加到 index.html 文件中:

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

菜鸟会做一些事情只是为了看看它是否能工作,当应用程序运行时,源代码中什么也没有出现。

更新 - 现在在终端中出现此错误 -

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

最佳答案

基础 CSS 未加载,因为没有应用 CSS 加载器

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

相反,你需要这样的东西

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

关于javascript - Vue.js + 基础 + Webpack 配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40122384/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com