SASS가 포함된 Webpack-simple + vue-cli - 컴파일할 수 없는가?
기본 CLI 설정을 사용하여 vue-cli 및 webpack-simple로 간단한 프로젝트를 설정하고 SASS 사용 여부를 묻는 질문에 'Y'가 선택되었는지 확인하십시오.
첫째, 폴더 구조 사진:
나는 에 파일을 만들었다.
./src/scss
디렉터리를 만들고 파일에 다음과 같은 간단한 scss 구문을 추가했다.
$primary-color: rgb(173, 16, 16);
그리고 나서, 내 App.vue 템플릿에는 다음과 같은 내용이 있다.
<style lang="scss" scoped>
h1, h2 {
font-weight: normal;
color: $primary-color;
}
</style>
main.js 파일에서 main.scss 파일을 다음과 같이 가져오도록 했다.
import './scss/main.scss'
실행할 때npm run dev
, 다음과 같은 컴파일 오류를 얻는다.
컴파일 실패.
./node_modules/css-loader!./node_modules/vue-loader/lib/style-compiler?{"vue":true,"id":"data-v-04c2046b","scoped":true,"hasInlineConfig":false}!./node_modules/sass-loader/lib/loader.js!./node_modules/vue-loader/lib/selector.js?type=styles&index=0!./src/App.vue
Module build failed:
undefined
^
Undefined variable: "$primary-color".
in D:\Users\medranns\Desktop\sasswebpack\src\App.vue (line 46, column 10)
@ ./node_modules/vue-style-loader!./node_modules/css-loader!./node_modules/vue-loader/lib/style-compiler?{"vue":true,"id":"data-v-04c2046b","scoped":true,"hasInlineConfig":false}!./node_modules/sass-loader/lib/loader.js!./node_modules/vue-loader/lib/selector.js?type=styles&index=0!./src/App.vue 4:14-316 13:3-17:5 14:22-324
@ ./src/App.vue
@ ./src/main.js
@ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server ./src/main.js
내 webpack.config.js 파일은 다음과 같다.
var path = require('path')
var webpack = require('webpack')
module.exports = {
entry: './src/main.js',
output: {
path: path.resolve(__dirname, './dist'),
publicPath: '/dist/',
filename: 'build.js'
},
module: {
rules: [
{
test: /\.css$/,
use: [
'vue-style-loader',
'css-loader'
],
},
{
test: /\.scss$/,
use: [
'vue-style-loader',
'css-loader',
'sass-loader'
],
},
{
test: /\.sass$/,
use: [
'vue-style-loader',
'css-loader',
'sass-loader?indentedSyntax'
],
},
{
test: /\.vue$/,
loader: 'vue-loader',
options: {
loaders: {
// Since sass-loader (weirdly) has SCSS as its default parse mode, we map
// the "scss" and "sass" values for the lang attribute to the right configs here.
// other preprocessors should work out of the box, no loader config like this necessary.
'scss': [
'vue-style-loader',
'css-loader',
'sass-loader'
],
'sass': [
'vue-style-loader',
'css-loader',
'sass-loader?indentedSyntax'
]
}
// other vue-loader options go here
}
},
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/
},
{
test: /\.(png|jpg|gif|svg)$/,
loader: 'file-loader',
options: {
name: '[name].[ext]?[hash]'
}
}
]
},
resolve: {
alias: {
'vue$': 'vue/dist/vue.esm.js'
},
extensions: ['*', '.js', '.vue', '.json']
},
devServer: {
historyApiFallback: true,
noInfo: true,
overlay: true
},
performance: {
hints: false
},
devtool: '#eval-source-map'
}
if (process.env.NODE_ENV === 'production') {
module.exports.devtool = '#source-map'
// http://vue-loader.vuejs.org/en/workflow/production.html
module.exports.plugins = (module.exports.plugins || []).concat([
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"production"'
}
}),
new webpack.optimize.UglifyJsPlugin({
sourceMap: true,
compress: {
warnings: false
}
}),
new webpack.LoaderOptionsPlugin({
minimize: true
})
])
}
그리고 포장도.json 코드 조각:
"devDependencies": {
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-preset-env": "^1.6.0",
"babel-preset-stage-3": "^6.24.1",
"cross-env": "^5.0.5",
"css-loader": "^0.28.7",
"file-loader": "^1.1.4",
"node-sass": "^4.7.2",
"sass-loader": "^6.0.6",
"vue-loader": "^13.0.5",
"vue-template-compiler": "^2.4.4",
"webpack": "^3.6.0",
"webpack-dev-server": "^2.9.1"
}
나는 문서들을 따라다니며 여전히 주위를 좀 뒤졌지만, 어떻게 고쳐야 할지 여전히 확실하지 않다.단서라도 줘서 고마워!
나는 scs를 bue 프로젝트에서 사용한다.webpack-simple
보일러 판
vue-init webpack-simple test-scss
아래 단계를 수행하여 vue 프로젝트에서 scs를 설정하십시오.
위의 명령을 사용하여 기본 설정을 설치한 후 아래 npm 패키지를 설치하십시오.
npm install sass-loader node-sass style-loader --save-dev
인webpack.config.js
규칙 배열 아래 로더 포함
rules:[
...,
...,
{
test: /\.scss$/,
use: [{
loader: "style-loader" // creates style nodes from JS strings
},
{
loader: "css-loader" // translates CSS into CommonJS
},
{
loader: "sass-loader" // compiles Sass to CSS
}]
}
]
여기까지 무슨 일이 있었는가?컴파일러가 scs를 css로 변환할 수 있는 구성이 완료된다.
지금 가져오기.scss
로main.js
import Vue from 'vue';
import App from './App.vue';
import './style.scss';
new Vue({
el: '#app',
render: h => h(App)
});
이것은 나의 폴더 구조다.
이제 객체 지향 css 코드를 style.scss에서 CSS로 컴파일할 준비가 되셨습니다.
구성 요소 수준 범위에서 sscs를 사용하려면 다음과 같이 하십시오. lang="scss"
에 명시되어야 한다.<style>
꼬리표를 달다
App.vue
<style lang="scss">
$override-color : green;
div {
color: $override-color;
}
</style>
이 항목에 대한 자세한 내용은 이 매뉴얼을 참조하십시오. 피드백을 기다리십시오.
나도 같은 문제가 있었어.'vue-loader'에서 ?indentedSyntax를 제거해 보십시오.
test: /\.vue$/,
loader: 'vue-loader',
options: {
loaders: {
'scss': [
'vue-style-loader',
'css-loader',
'sass-loader'
],
'sass': [
'vue-style-loader',
'css-loader',
'sass-loader?indentedSyntax'
]
}
// other vue-loader options go here
}
결과적으로 다음과 같이 보여야 한다.
test: /\.vue$/,
loader: 'vue-loader',
options: {
loaders: {
// Since sass-loader (weirdly) has SCSS as its default parse mode, we map
// the "scss" and "sass" values for the lang attribute to the right configs here.
// other preprocessors should work out of the box, no loader config like this necessary.
'scss': [
'vue-style-loader',
'css-loader',
'sass-loader'
],
'sass': [
'vue-style-loader',
'css-loader',
'sass-loader'
]
}
// other vue-loader options go here
참조URL: https://stackoverflow.com/questions/48490969/webpack-simple-vue-cli-with-sass-cant-compile
'Programing' 카테고리의 다른 글
vuex mapState 내의 vue 메서드에 액세스 (0) | 2022.04.11 |
---|---|
Vuex 및 FIrebase를 사용하여 여러 이미지를 저장하십시오.(이미지가 업로드될 때까지 대기) (0) | 2022.04.11 |
vue 클래스 구성 요소에서 $bvToast에 액세스하는 방법 (0) | 2022.04.11 |
VueJ를 사용하여 숫자 입력을 방지하는 방법s (0) | 2022.04.11 |
Vue, firestore: 컬렉션을 병합한 후 라이브 데이터를 표시하는 방법 (0) | 2022.04.11 |