Upgrade to Stylelint 16 and css-loader 6
Edit on GitHubThis document describes how to upgrade Styleling to v16 and css-loader to v6.
Estimated migration time: 30m
To upgrade Styleling to v16 and css-loader to v6, update configuration files:
- In
package.json
, do the following:- Update or add dependencies and engines.
- Adjust the commands.
{
"scripts": {
"yves:stylelint": "node ./frontend/libs/stylelint.mjs",
"yves:stylelint:fix": "node ./frontend/libs/stylelint.mjs --fix",
},
"devDependencies": {
"css-loader": "~6.10.0",
"css-minimizer-webpack-plugin": "~6.0.0",
"@spryker/oryx-for-zed": "~3.4.2",
"stylelint": "~16.2.1",
"stylelint-config-standard-less": "~3.0.1",
"stylelint-config-standard-scss": "^13.0.0",
}
}
Update and install package dependencies:
rm -rf node_modules
npm install
- In
package.json
, remove the dependency:
"optimize-css-assets-webpack-plugin": "x.x.x"
- In
frontend/configs/development.js
, update the webpack config: add the URLfalse
option forcss-loader
:
....
{
loader: 'css-loader',
options: {
url: false,
importLoaders: 1,
},
},
....
- In
frontend/configs/production.js
, update the webpack config by replacingOptimizeCSSAssetsPlugin
withCssMinimizerPlugin
:
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
{
....
minimizer: [
new CssMinimizerPlugin({
minimizerOptions: {
preset: [
'default',
{
discardComments: { removeAll: true },
},
],
},
}),
],
....
}
- In the
frontend/merchant-portal
folder, do the following:- Rename
stylelint.js
tostylelint.mjs
. - In the file, change
commonjs require's
toES imports
. - Drop the
syntax
option.
- Rename
import commandLineParser from 'commander';
import stylelint from 'stylelint';
import { ROOT_DIR, ROOT_SPRYKER_PROJECT_DIR } from './mp-paths.js';
stylelint
.lint({
...,
/* syntax: 'less', */ <= Delete it
...,
})
- In the
frontend/libs
folder, do the following:- Rename
stylelint.js
tostylelint.mjs
. - In the file, change
commonjs require's
toES imports
. - Drop the
adjust lint options
option.
- Rename
import commandLineParser from 'commander';
import stylelint from 'stylelint';
import { globalSettings } from '../settings.js';
stylelint
.lint({
...,
configFile: `${globalSettings.context}/.stylelintrc.js`,
/* syntax: 'scss', */ <= Delete it
...,
})
- Add the
.stylelintrc.js
file with the following content to the root of the project:
module.exports = {
extends: ['stylelint-config-standard-scss', '@spryker/frontend-config.stylelint/.stylelintrc.json'],
rules: {
'scss/at-mixin-argumentless-call-parentheses': null,
'scss/no-global-function-names': null,
'declaration-block-no-redundant-longhand-properties': null,
'scss/at-if-no-null': null,
'scss/dollar-variable-pattern': null,
'color-hex-length': null,
'scss/dollar-variable-empty-line-before': null,
'scss/at-import-partial-extension': null,
'selector-class-pattern': null,
'scss/at-rule-conditional-no-parentheses': null,
'scss/double-slash-comment-empty-line-before': null,
'scss/operator-no-unspaced': null,
},
};
- In
.stylelintrc.mp.js
, add additional config to theextends
option and disable multiple rules:
module.exports = {
....,
extends: ['stylelint-config-standard-less', ....],
rules: {
....,
'selector-class-pattern': null,
'less/no-duplicate-variables': null,
'less/color-no-invalid-hex': null,
}
}
Thank you!
For submitting the form