我是这个堆栈的新手,仍然在学习使用vue和webpack的复杂性,所以我下载了一个引导示例应用程序作为入门指南。我的第一个需求是应用sass,因为本例中没有sass,但我感到困惑。
首先,对于webpack的配置内容是相当混乱的。而不是通常的webpack配置文件,它似乎有一个配置目录和一个构建目录,似乎处理所有这些。
我猜,在将sass添加到堆栈中时,唯一真正适用于演练的文件似乎是webpack.base.conf.js:
'use strict'
const path = require('path')
const utils = require('./utils')
const config = require('../config')
const vueLoaderConfig = require('./vue-loader.conf')
function resolve (dir) {
return path.join(__dirname, '..', dir)
}
const createLintingRule = () => ({
test: /\.(js|vue)$/,
loader: 'eslint-loader',
enforce: 'pre',
include: [resolve('test')],
options: {
formatter: require('eslint-friendly-formatter'),
emitWarning: !config.dev.showEslintErrorsInOverlay
}
})
module.exports = {
context: path.resolve(__dirname, '../'),
entry: {
app: './src/main.js'
},
output: {
path: config.build.assetsRoot,
filename: '[name].js',
publicPath: process.env.NODE_ENV === 'production'
? config.build.assetsPublicPath
: config.dev.assetsPublicPath
},
resolve: {
extensions: ['.js', '.vue', '.json'],
alias: {
'vue$': 'vue/dist/vue.esm.js',
'@': resolve('src'),
}
},
module: {
rules: [
...(config.dev.useEslint ? [createLintingRule()] : []),
{
test: /\.vue$/,
loader: 'vue-loader',
options: vueLoaderConfig
},
{
test: /\.js$/,
loader: 'babel-loader',
include: [resolve('src'), resolve('test')]
},
{
test: /\.scss$/,
use: [
'vue-style-loader',
'css-loader',
{
loader: 'sass-loader',
options: {
indentedSyntax: true
}
}
]
},
{
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 10000,
name: utils.assetsPath('img/[name].[hash:7].[ext]')
}
},
{
test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 10000,
name: utils.assetsPath('media/[name].[hash:7].[ext]')
}
},
{
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 10000,
name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
}
}
]
},
node: {
// prevent webpack from injecting useless setImmediate polyfill
because Vue
// source contains it (although only uses it if it's native).
setImmediate: false,
// prevent webpack from injecting mocks to Node native modules
// that does not make sense for the client
dgram: 'empty',
fs: 'empty',
net: 'empty',
tls: 'empty',
child_process: 'empty'
}
}正如您在规则中看到的那样,我尝试添加演练所说的内容,然后在App.vue文件上调用导入:
<style lang="scss" scoped>
@import 'assets/sass/main.scss'
</style>该网站加载没有,似乎能够找到sass文件,但我看不到加载的样式,也没有任何迹象表明它正在编译时,我编辑,甚至做一个重建。
请帮帮忙,webpack和vue加载器架构看起来真的很混乱。
发布于 2018-07-01 06:54:48
原来我的目标是sass文件中的body,因为vue-loader是在div上实例化的,所以不能以这种方式从sass中定位父元素。通过以#app为目标,样式起作用了!
https://stackoverflow.com/questions/51119057
复制相似问题