Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
Back to tool/Back to issues
#3935·stylelint

Add support for running in a browser

Author: oskarkrawczykCreated Feb 1, 2019Updated Sep 20, 2026
Labelsstatus: ask to implement

I'm currently trying to replace CSSLint in @jsfiddle with Stylelint. Got it working thanks to a proof-of-concept made here https://github.com/m-allanson/stylelint-browser-demo

Unfortunately turns out this works fine but with a very old version of Stylelint, specifically the 5.x branch. Once updated deps to the newest Stylelint, the whole client-side bundle breaks apart with a slightly cryptic Error: Cannot find module "." error.

I was wondering if anyone around here can help out figure out if it's even possible to run the newest Stylelint on the client-side (this is a requirement for JSFiddle as our env only supports linting that way).


A bit more on what my config looks like:

webpack.config:

javascript
import webpack from "webpack"
import path from "path"

export default {
  entry: "./site/index.js",
  output: {
    path: path.resolve(__dirname, "site"),
    publicPath: "/",
    filename: "bundle.js",
  },
  resolve: {
    root: path.resolve(__dirname),
    alias: {
      "resolve-from": "empty-module",
      cosmiconfig: "empty-module",
      doiuse: "empty-module",
      globby: "empty-module",
      globjoin: "empty-module",
      multimatch: "empty-module",
      path: "empty-module",
    },
    modulesDirectories: [
      "node_modules",
      "site",
    ]
  },
  module: {
    loaders: [
      {
        test: /\.js$/,
        loader: "babel-loader",
        exclude: /node_modules/,
      },
      {
        test: /\.json$/,
        loader: "json-loader",
      },
    ],
  },
  plugins: [
    new webpack.optimize.DedupePlugin(),
    new webpack.ContextReplacementPlugin(/stylelint/, /NEVER_MATCH^/),
  ],
  node: {
    fs: "empty",
    module: "empty",
  },
}

package.json:

json
{
  "name": "stylelint-browser-demo",
  "version": "0.0.1",
  "description": "A proof-of-concept to demo stylelint running in a browser.",
  "main": "site/bundle.js",
  "scripts": {
    "start": "npm run build && http-server ./site",
    "start-dev": "webpack-dev-server --content-base site/ --hot --inline",
    "build": "webpack --progress --colors && stat -f%z site/bundle.js",
    "lint": "eslint . --ignore-path .gitignore",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "m-allanson",
  "license": "MIT",
  "dependencies": {
    "babel-cli": "^6.1.18",
    "babel-loader": "^6.2.4",
    "babel-preset-es2015": "^6.6.0",
    "http-server": "^0.9.0",
    "imports-loader": "^0.6.5",
    "json-loader": "^0.5.4",
    "stylelint": "^9.10.1",
    "stylelint-config-standard": "^18.2.0",
    "webpack": "^1.12.14"
  },
  "devDependencies": {
    "eslint": "^2.4.0",
    "eslint-config-stylelint": "^1.0.0",
    "webpack-dev-server": "^1.14.1"
  },
  "engines": {
    "node": "5.9.1",
    "npm": "3.7.3"
  },
  "eslintConfig": {
    "extends": "stylelint",
    "env": {
      "browser": true
    },
    "rules": {
      "arrow-spacing": 2,
      "no-var": 2,
      "object-shorthand": 2,
      "prefer-const": 2,
      "template-curly-spacing": 2
    }
  },
  "babel": {
    "presets": [
      "babel-preset-es2015"
    ]
  }
}

The build bundle.js is attached - bundle.js.zip

Lint method is exposed as Stylelint.verify()

@ai Any chance you could help out? (we had a brief chat about this on Twitter).

Source: stylelint/stylelint

View original on GitHubView discussion on GitHub