1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Vue.jsでScssをつかう

Last updated at Posted at 2019-12-08

##Vue.jsでScssを使いたい
src/assets配下にscssフォルダを作成
スクリーンショット 2019-12-01 15.27.45.png

common.scssの中身はこんな感じ

common.scss
// vender
@import "vender/normalize";

// foundation
@import "foundation/variables";
@import "foundation/functions";
@import "foundation/mixins";

// components
@import "object/_main";
_main.scss
p {
  color: blue;
}

下記コマンドでcssが生成される

npm run build

生成されたcssを読み込むには

プロジェクト配下にvue.config.jsを作成

vue.config.js

const isProduction = process.env.NODE_ENV === "production";
module.exports = {
  chainWebpack: config => {
    config.module.rules.delete("eslint");
  },
  css: {
    loaderOptions: {
      scss: {
        prependData: `@import "~@/assets/scss/common.scss";`
      }
    }
  },
  productionSourceMap: !isProduction
};

import-resolver.jsも設置

import-resolver.js
System.config({
  paths: {
    '@/*': 'src/*',
  },
});

確認する

css生成して

npm run build

立ち上げる

npm run serve

結果

反映されました
スクリーンショット 2019-12-01 16.02.07.png

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?