From f5636cedfd5bc4aa4a0795c5920a9efee2dcaedb Mon Sep 17 00:00:00 2001 From: Sam Light Date: Sun, 1 Sep 2024 19:30:35 +0100 Subject: Moved all configs into the webpack config --- index.js | 115 ++++++++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 96 insertions(+), 19 deletions(-) diff --git a/index.js b/index.js index 7b08b36..d9bff22 100644 --- a/index.js +++ b/index.js @@ -7,8 +7,7 @@ import EsLintPlugin from 'eslint-webpack-plugin'; import WebpackbarPlugin from 'webpackbar'; import CleanTerminalPlugin from 'clean-terminal-webpack-plugin'; import {CleanWebpackPlugin} from 'clean-webpack-plugin'; -import SvgChunkWebpackPlugin from 'svg-chunk-webpack-plugin'; - +import Autoprefixer from 'autoprefixer'; export class Paths { #jsSourcePath; @@ -30,6 +29,89 @@ export class Paths { } }; +const babelConfig = { + presets: [ + "@babel/preset-env" + ], + plugins: [ + ["polyfill-corejs3", { method: "usage-global"}] + ], +}; + +const postCssConfig = { + plugins: [ + Autoprefixer + ] +}; + +const esLintConfig = { + 'root': true, + 'extends': [ + 'eslint:recommended' + ], + 'globals': { + 'wp': true, + }, + 'env': { + 'node': true, + 'es6': true, + 'amd': true, + 'browser': true, + 'jquery': true, + }, + 'parser': '@babel/eslint-parser', + 'parserOptions': { + 'ecmaFeatures': { + 'globalReturn': true, + 'generators': false, + 'objectLiteralDuplicateProperties': false, + 'experimentalObjectRestSpread': true, + }, + 'ecmaVersion': 2017, + 'sourceType': 'module', + 'requireConfigFile': false, + }, + 'plugins': [ + + ], + 'settings': { + 'import/core-modules': [], + 'import/ignore': [ + 'node_modules', + '\\.(coffee|scss|css|less|hbs|svg|json)$', + ] + }, + 'rules': { + 'no-console': 0, + 'quotes': ['error', 'single'], + 'semi': ['warn', 'always'], + 'comma-dangle': 0, + }, +}; + +const styleLintConfig = { + 'extends': 'stylelint-config-standard', + 'plugins': ['stylelint-scss'], + 'customSyntax': 'postcss-scss', + 'rules': { + 'no-empty-source': null, + //'selector-id-pattern': null, + 'selector-class-pattern': null, // TODO: remove and fix + 'at-rule-no-unknown': null, + 'function-no-unknown': null, + 'no-invalid-position-at-import-rule': [ + true, + { + ignoreAtRules: ["/^use$/"] + } + ], + 'scss/at-rule-no-unknown': true, + 'import-notation': null, + 'annotation-no-unknown': null, + }, +}; + + export const makeConfig = (env, argv, options) => { const isProd = argv.mode === 'production', isDev = argv.mode === 'development', @@ -55,7 +137,6 @@ export const makeConfig = (env, argv, options) => { customize(entry) { if ( - entry.key.startsWith('svg/') || entry.key.endsWith('.map') ) return false; @@ -78,8 +159,10 @@ export const makeConfig = (env, argv, options) => { }), new StylelintPlugin({ failOnError: !isWatch, + config: styleLintConfig, }), new EsLintPlugin({ + baseConfig: esLintConfig, overrideConfig: { rules: { "no-console": isProd ? 2 : 1, @@ -93,11 +176,6 @@ export const makeConfig = (env, argv, options) => { new NotifierPlugin(), new WebpackbarPlugin(), new CleanTerminalPlugin(), - new SvgChunkWebpackPlugin({ - filename: '[name].[contenthash].svg', - svgstoreConfig: {inline: false}, - }), - ...plugins, ], @@ -109,9 +187,10 @@ export const makeConfig = (env, argv, options) => { { test: /\.js$/i, include: paths.sourcePath, - use: [ - 'babel-loader' - ] + use: { + loader: 'babel-loader', + options: babelConfig, + } }, { test: /\.s[ac]ss$/i, @@ -119,17 +198,15 @@ export const makeConfig = (env, argv, options) => { use: [ MiniCssExtractPlugin.loader, 'css-loader', - 'postcss-loader', + { + loader: 'postcss-loader', + options: { + postcssOptions: postCssConfig + } + }, 'sass-loader', ], }, - { - test: /.svg$/i, - include: paths.sourcePath, - use: [ - {loader: SvgChunkWebpackPlugin.loader} - ] - } ], }, -- cgit v1.2.3