-
-
Notifications
You must be signed in to change notification settings - Fork 206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error when using new CSS syntax at VS Code #190
Comments
Can you try setting up preprocess following this and see if the svelte error still exist? It should be similar to your build setup, in your case it should be postcss. |
@jasonlyu123 hi! Thanks for reply. This is my 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,
},
}; Correct me please if I wrong, but with If I set |
Just copy the preprocess section into svelte.config.js or move it to svelte.config.js and require it from your build config. The language server use svelte to compile your code internally so it needs to know to preprocess as well. |
@jasonlyu123 thanks! This solve error: // 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],
},
}),
}; But how to syntax highlight to normal CSS, like before? |
If your CSS doesn't have postcss specific syntax. You can remove the lang attribute. |
@jasonlyu123 thx! Additional, I set ) expectedcss(css-rparentexpected) |
Describe the bug
I faced with error, when I use new CSS syntax feature Media Queries Level 4 at VS Code in Svelte component.
I use latest Sapper version:
But Svelte linter always show me this error (also, see screenshot 1):
OK, I see this error at normal
*.css
files, but if I set VS Code CSS validation settingcss.validate
tofalse
this error is gone.I try to set
svelte.plugin.css.diagnostics.enable
tofalse
, but I still seecss-syntax-error
message by Svelte (also, see screenshot 2).To Reproduce
Steps to reproduce the behavior:
<style>...</style>
in*.svelte
componentExpected behavior
No error after add new CSS syntax.
Screenshots
System (please complete the following information):
VS Code and Node versions:
Additional context
Possible solution, maybe, allow to add special value to the
<style lang="...">...</style>
attribute to support all new CSS features, because it's only bad UX/view issue.All new syntax after
npm run build
processed bypostcss-media-minmax
plugin to old CSS syntax, like:The text was updated successfully, but these errors were encountered: