Language-tools: VS Code์—์„œ ์ƒˆ CSS ๊ตฌ๋ฌธ์„ ์‚ฌ์šฉํ•  ๋•Œ ์˜ค๋ฅ˜

์— ๋งŒ๋“  2020๋…„ 06์›” 14์ผ  ยท  6์ฝ”๋ฉ˜ํŠธ  ยท  ์ถœ์ฒ˜: sveltejs/language-tools

๋ฒ„๊ทธ ์„ค๋ช…
Svelte ๊ตฌ์„ฑ ์š”์†Œ์˜ VS Code์—์„œ ์ƒˆ๋กœ์šด CSS ๊ตฌ๋ฌธ ๊ธฐ๋Šฅ Media Queries Level 4 ๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค.

<style>
  <strong i="9">@media</strong> (width >= 768px) { // <--- error line
    .nav {
      padding: 16px 24px;
    }
  }
</style>

์ตœ์‹  Sapper ๋ฒ„์ „์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

    // ...
    "sapper": "^0.27.15",
    "svelte": "^3.23.2"
}

๊ทธ๋Ÿฌ๋‚˜ Svelte linter๋Š” ํ•ญ์ƒ์ด ์˜ค๋ฅ˜๋ฅผ ํ‘œ์‹œํ•ฉ๋‹ˆ๋‹ค (๋˜ํ•œ ์Šคํฌ๋ฆฐ ์ƒท 1 ์ฐธ์กฐ).

Colon is expected. If you expect this syntax to work, here are some suggestions: 
If you use less/SCSS with `svelte-preprocessor`, did you add `lang="scss"`/`lang="less"` 
to you `style` tag? If you use SCSS, it may be necessary to add the path to your NODE 
runtime to the setting `svelte.language-server.runtime`, or use `sass` instead of `node-sass`.
Did you setup a `svelte.config.js`? See https://github.com/sveltejs/language-tools/tree/master/packages/svelte-vscode#using-with-preprocessors 
for more info.svelte(css-syntax-error)

์ข‹์Šต๋‹ˆ๋‹ค. ์ผ๋ฐ˜ *.css ํŒŒ์ผ์—์„œ์ด ์˜ค๋ฅ˜๊ฐ€ ํ‘œ์‹œ๋˜์ง€๋งŒ VS Code CSS ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ ์„ค์ • css.validate ๋ฅผ false ํ•˜๋ฉด์ด ์˜ค๋ฅ˜๊ฐ€ ์‚ฌ๋ผ์ง‘๋‹ˆ๋‹ค.

svelte.plugin.css.diagnostics.enable ๋ฅผ false ๋กœ ์„ค์ •ํ•˜๋ ค๊ณ ํ–ˆ์ง€๋งŒ ์—ฌ์ „ํžˆ Svelte์˜ css-syntax-error ๋ฉ”์‹œ์ง€๊ฐ€ ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค (์Šคํฌ๋ฆฐ ์ƒท 2 ์ฐธ์กฐ).

์žฌํ˜„ํ•˜๋ ค๋ฉด
๋™์ž‘์„ ์žฌํ˜„ํ•˜๋Š” ๋‹จ๊ณ„ :

  1. *.svelte ๊ตฌ์„ฑ ์š”์†Œ์˜ <style>...</style> ์— ์ƒˆ CSS ๊ตฌ๋ฌธ ์ถ”๊ฐ€
  2. ์ €์žฅ
  3. ์˜ค๋ฅ˜ ์ฐธ์กฐ

์˜ˆ์ƒ๋˜๋Š” ํ–‰๋™
์ƒˆ CSS ๊ตฌ๋ฌธ์„ ์ถ”๊ฐ€ ํ•œ ํ›„ ์˜ค๋ฅ˜๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค.

์Šคํฌ๋ฆฐ ์ƒท
Screenshot 2020-06-12 at 13 32 35

Screenshot 2020-06-13 at 13 04 54

์‹œ์Šคํ…œ (๋‹ค์Œ ์ •๋ณด๋ฅผ ์ž‘์„ฑํ•˜์‹ญ์‹œ์˜ค) :

  • ์šด์˜์ฒด์ œ : macOS 10.14.6
  • IDE : VS ์ฝ”๋“œ
  • ํ”Œ๋Ÿฌ๊ทธ์ธ / ํŒจํ‚ค์ง€ : Svelte Beta

VS ์ฝ”๋“œ ๋ฐ ๋…ธ๋“œ ๋ฒ„์ „ :

Version: 1.46.0
Commit: a5d1cc28bb5da32ec67e86cc50f84c67cc690321
Date: 2020-06-10T08:59:06.977Z
Electron: 7.3.1
Chrome: 78.0.3904.130
Node.js: 12.8.1
V8: 7.8.279.23-electron.0
OS: Darwin x64 18.7.0

์ถ”๊ฐ€ ์ปจํ…์ŠคํŠธ
๊ฐ€๋Šฅํ•œ ํ•ด๊ฒฐ์ฑ…์€ <style lang="...">...</style> ์†์„ฑ์— ํŠน๋ณ„ํ•œ ๊ฐ’์„ ์ถ”๊ฐ€ํ•˜์—ฌ ๋ชจ๋“  ์ƒˆ๋กœ์šด CSS ๊ธฐ๋Šฅ์„ ์ง€์›ํ•˜๋„๋ก ํ—ˆ์šฉํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. _ ๋‚˜์œ UX /๋ณด๊ธฐ ๋ฌธ์ œ _ ์ผ ๋ฟ์ด ๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค.

npm run build ์ดํ›„์˜ ๋ชจ๋“  ์ƒˆ ๊ตฌ๋ฌธ์€ postcss-media-minmax ํ”Œ๋Ÿฌ๊ทธ์ธ์—์„œ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ด์ „ CSS ๊ตฌ๋ฌธ์œผ๋กœ ์ฒ˜๋ฆฌ๋ฉ๋‹ˆ๋‹ค.

<strong i="61">@media</strong> (width >= 768px) ---> <strong i="62">@media</strong> (min-width: 786px)

๊ฐ€์žฅ ์œ ์šฉํ•œ ๋Œ“๊ธ€

ํŠธ์œ— ๋‹ด์•„ ๊ฐ€๊ธฐ

์ถ”๊ฐ€๋กœ์ด CSS ์˜ค๋ฅ˜๋ฅผ ์‚ญ์ œํ•˜๊ธฐ ์œ„ํ•ด svelte.plugin.css.diagnostics.enable ๋ฅผ false ํ–ˆ์Šต๋‹ˆ๋‹ค.

) expectedcss(css-rparentexpected)

Screenshot 2020-06-14 at 15 42 10

๋ชจ๋“  6 ๋Œ“๊ธ€

์ด๊ฒƒ์— ๋”ฐ๋ผ ์ „์ฒ˜๋ฆฌ๋ฅผ ์„ค์ •ํ•˜๊ณ  svelte ์˜ค๋ฅ˜๊ฐ€ ์—ฌ์ „ํžˆ ์กด์žฌํ•˜๋Š”์ง€ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๊นŒ? ๋นŒ๋“œ ์„ค์ •๊ณผ ๋น„์Šทํ•ด์•ผํ•˜๋ฉฐ, ๊ฒฝ์šฐ์—๋Š” postcss ์—ฌ์•ผํ•ฉ๋‹ˆ๋‹ค.
css ์˜ค๋ฅ˜๋Š” vscode์˜ css ์–ธ์–ด ์„œ๋น„์Šค๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ์œผ๋ฏ€๋กœ์ด ๊ตฌ๋ฌธ์„ ์ง€์›ํ•  ๋•Œ๊นŒ์ง€ ํ•  ์ˆ˜์žˆ๋Š” ์ผ์ด ๋งŽ์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

ํŠธ์œ— ๋‹ด์•„ ๊ฐ€๊ธฐ ๋‹ต๋ณ€ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.

์ด๊ฒƒ์€ Sapper์˜ rollup.config.js ์ž…๋‹ˆ๋‹ค.

import resolve from "@rollup/plugin-node-resolve";
import replace from "@rollup/plugin-replace";
import commonjs from "@rollup/plugin-commonjs";
import svelte from "rollup-plugin-svelte";
import babel from "@rollup/plugin-babel";
import { terser } from "rollup-plugin-terser";

// Import svelte-preprocess
import sveltePreprocess from "svelte-preprocess";

// Import PostCSS plugins
import autoprefixer from "autoprefixer";
import pimport from "postcss-import";
import minmax from "postcss-media-minmax";
import csso from "postcss-csso";

import config from "sapper/config/rollup.js";
import pkg from "./package.json";

const mode = process.env.NODE_ENV;
const dev = mode === "development";
const legacy = !!process.env.SAPPER_LEGACY_BUILD;

const onwarn = (warning, onwarn) =>
  (warning.code === "CIRCULAR_DEPENDENCY" &&
    /[/\\]@sapper[/\\]/.test(warning.message)) ||
  onwarn(warning);

// Define svelte-preprocess
const preprocess = sveltePreprocess({
  postcss: {
    plugins: [pimport, minmax, autoprefixer, csso], // --> add PostCSS plugins
  },
});

export default {
  client: {
    input: config.client.input(),
    output: config.client.output(),
    plugins: [
      replace({
        "process.browser": true,
        "process.env.NODE_ENV": JSON.stringify(mode),
      }),
      svelte({
        dev,
        preprocess, // --> add sveltePreprocess
        hydratable: true,
        emitCss: true,
      }),
      resolve({
        browser: true,
        dedupe: ["svelte"],
      }),
      commonjs(),

      legacy &&
        babel({
          extensions: [".js", ".mjs", ".html", ".svelte"],
          babelHelpers: "runtime",
          exclude: ["node_modules/@babel/**"],
          presets: [
            [
              "@babel/preset-env",
              {
                targets: "> 0.25%, not dead",
              },
            ],
          ],
          plugins: [
            "@babel/plugin-syntax-dynamic-import",
            [
              "@babel/plugin-transform-runtime",
              {
                useESModules: true,
              },
            ],
          ],
        }),

      !dev &&
        terser({
          module: true,
        }),
    ],

    preserveEntrySignatures: false,
    onwarn,
  },

  server: {
    input: config.server.input(),
    output: config.server.output(),
    plugins: [
      replace({
        "process.browser": false,
        "process.env.NODE_ENV": JSON.stringify(mode),
      }),
      svelte({
        generate: "ssr",
        preprocess, // --> add sveltePreprocess
        dev,
      }),
      resolve({
        dedupe: ["svelte"],
      }),
      commonjs(),
    ],
    external: Object.keys(pkg.dependencies).concat(
      require("module").builtinModules ||
        Object.keys(process.binding("natives"))
    ),

    preserveEntrySignatures: "strict",
    onwarn,
  },

  serviceworker: {
    input: config.serviceworker.input(),
    output: config.serviceworker.output(),
    plugins: [
      resolve(),
      replace({
        "process.browser": true,
        "process.env.NODE_ENV": JSON.stringify(mode),
      }),
      commonjs(),
      !dev && terser(),
    ],

    preserveEntrySignatures: false,
    onwarn,
  },
};

๋‚ด๊ฐ€ ํ‹€๋ ธ๋‹ค๋ฉด ์ •์ • ํ•ด์ฃผ์„ธ์š”.ํ•˜์ง€๋งŒ rollup.config.js ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด sveltePreprocess({...}) ์„ค์ •๋งŒ์œผ๋กœ ๋ณ„๋„์˜ svelte.config.js ํŒŒ์ผ์„ ๋งŒ๋“ค ํ•„์š”๊ฐ€ ์—†์Šต๋‹ˆ๊นŒ? ๐Ÿค”

I๋ฅผ ์„ค์ •ํ•˜๋ฉด lang (๋˜๋Š” type ์œ„ํ•œ) ์†์„ฑ <style> ์— postcss (๋˜๋Š” text/postcss ) I ๋งค์šฐ ๋™์ผํ•œ ์˜ค์ฐจ๋ฅผ ์ฐธ์กฐ ๋ชจ๋“  CSS ์ฝ”๋“œ์— ์ด์ƒํ•œ ๊ตฌ๋ฌธ ๊ฐ•์กฐ ํ‘œ์‹œ :

Screenshot 2020-06-14 at 13 32 23

์ „์ฒ˜๋ฆฌ ์„น์…˜์„ svelte.config.js๋กœ ๋ณต์‚ฌํ•˜๊ฑฐ๋‚˜ svelte.config.js๋กœ ์ด๋™ํ•˜๊ณ  ๋นŒ๋“œ ๊ตฌ์„ฑ์—์„œ ์š”๊ตฌํ•˜์‹ญ์‹œ์˜ค. ์–ธ์–ด ์„œ๋ฒ„๋Š” svelte๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋‚ด๋ถ€์ ์œผ๋กœ ์ฝ”๋“œ๋ฅผ ์ปดํŒŒ์ผํ•˜๋ฏ€๋กœ ์‚ฌ์ „ ์ฒ˜๋ฆฌ๋„ ์•Œ์•„์•ผํ•ฉ๋‹ˆ๋‹ค.

@ jasonlyu123 ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค! ์ด๊ฒƒ์€ ์˜ค๋ฅ˜๋ฅผ ํ•ด๊ฒฐํ•ฉ๋‹ˆ๋‹ค.

// svelte.config.js

const sveltePreprocess = require("svelte-preprocess");
const autoprefixer = require("autoprefixer");
const pimport = require("postcss-import");
const minmax = require("postcss-media-minmax");
const csso = require("postcss-csso");

module.exports = {
  preprocess: sveltePreprocess({
    postcss: {
      plugins: [pimport, minmax, autoprefixer, csso],
    },
  }),
};

๊ทธ๋Ÿฌ๋‚˜ ์ด์ „๊ณผ ๊ฐ™์ด ์ผ๋ฐ˜ CSS๋กœ ๊ตฌ๋ฌธ์„ ๊ฐ•์กฐํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ๋ฌด์—‡์ž…๋‹ˆ๊นŒ?

Screenshot 2020-06-14 at 14 33 23

CSS์— postcss ํŠน์ • ๊ตฌ๋ฌธ์ด์—†๋Š” ๊ฒฝ์šฐ. lang ์†์„ฑ์„ ์ œ๊ฑฐ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

ํŠธ์œ— ๋‹ด์•„ ๊ฐ€๊ธฐ

์ถ”๊ฐ€๋กœ์ด CSS ์˜ค๋ฅ˜๋ฅผ ์‚ญ์ œํ•˜๊ธฐ ์œ„ํ•ด svelte.plugin.css.diagnostics.enable ๋ฅผ false ํ–ˆ์Šต๋‹ˆ๋‹ค.

) expectedcss(css-rparentexpected)

Screenshot 2020-06-14 at 15 42 10

์ด ํŽ˜์ด์ง€๊ฐ€ ๋„์›€์ด ๋˜์—ˆ๋‚˜์š”?
0 / 5 - 0 ๋“ฑ๊ธ‰