VueJS webpack构建错误SCSS相关

时间:2018-05-24 23:12:06

标签: symfony webpack vue.js vuejs2 yarnpkg

当我尝试使用样式表构建VueJS项目时,我遇到了错误。

我跑步的错误"纱线跑步 - 观察"产生这些错误:

c:\wamp\www\DBViewer2>yarn run dev --watch
yarn run v1.6.0
warning package.json: No license field
$ encore dev --progress=true --watch
Running webpack ...

  0% compiling
Webpack is watching the files…
                                                                                                                                   95% emitting ERROR  Failed to compile with 1 errors                                                                                                 16:00:56

This dependency was not found:

* !!vue-style-loader!css-loader?sourceMap!../node_modules/vue-loader/lib/style-compiler/index?{"optionsId":"0","vue":true,"scoped":false,"sourceMap":true}!scss-loader!../node_modules/vue-loader/lib/selector?type=styles&index=0!./App.vue in ./assets/App.vue

To install it, you can run: npm install --save !!vue-style-loader!css-loader?sourceMap!../node_modules/vue-loader/lib/style-compiler/index?{"optionsId":"0","vue":true,"scoped":false,"sourceMap":true}!scss-loader!../node_modules/vue-loader/lib/selector?type=styles&index=0!./A

我不确定是什么原因造成的。它似乎正在寻找错误位置的文件?

这是我的App.vue文件:

<template>
  <router-view></router-view>
</template>

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

<style lang="scss-loader">
  /* Import Font Awesome Icons Set */
  $fa-font-path: 'font-awesome/fonts/';
  @import 'font-awesome/scss/font-awesome.scss';
  /* Import Simple Line Icons Set */
  $simple-line-font-path: 'simple-line-icons/fonts/';
  @import 'simple-line-icons/scss/simple-line-icons.scss';
  /* Import Bootstrap Vue Styles */
  @import 'bootstrap-vue/dist/bootstrap-vue.css';
  /*// Import Main styles for this application*/
  @import './assets/scss/style';
</style>

这是我的webpack.config.js:

var Encore = require('@symfony/webpack-encore');

Encore
    // the project directory where all compiled assets will be stored
    .setOutputPath('public_html/build/')

    // the public path used by the web server to access the previous directory
    .setPublicPath('/build')

    // will create public/build/app.js and public/build/app.css
    .addEntry('main', './assets/main.js')
    .addEntry('vendor', './assets/js/vendor.js')

    // allow legacy applications to use $/jQuery as a global variable
    .autoProvidejQuery()

    // enable source maps during development
    .enableSourceMaps(!Encore.isProduction())

    // empty the outputPath dir before each build
    .cleanupOutputBeforeBuild()

    // show OS notifications when builds finish/fail
    .enableBuildNotifications()

    // create hashed filenames (e.g. app.abc123.css)
    // .enableVersioning()
    .enableVueLoader()
    // allow sass/scss files to be processed
    .enableSassLoader()
;

// export the final configuration
module.exports = Encore.getWebpackConfig();

非常感谢任何建议。花了2天时间尝试不同的东西并研究谷歌。我对symfony / encore不够熟悉,这是我的第一个vuejs项目。

1 个答案:

答案 0 :(得分:0)

为了能够在Vue模板中使用SCSS,您需要在单个文件组件中声明以下style块:

<!-- Those styles are not scoped to that particular component -->
<style lang="scss">...</style>
<!-- Or those styles are scoped to that particular component -->
<style lang="scss" scoped>...</style>

如果需要,您甚至可以在同一个文件中使用它们。

您还需要运行以下命令来安装正确的节点依赖项:

npm install --dev node-sass sass-loader

当在使用vue-cli初始化的项目中使用时,这应该是开箱即用的。

但是你在{web}'test'配置中添加了这个could need,以便在使用vue-loader的注入选项时使lang="scss"在测试中工作:

resolveLoader: {
    alias: {
        'scss-loader': 'sass-loader',
    },
},