Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
a318386
Teste einen Gulp Task, der SCSS mit Webpack kompiliert
polarbirke Sep 19, 2025
bb97a32
Add asset url rebasing via Webpack's resolve-url-loader
polarbirke Sep 25, 2025
e1b6f13
Add postcss-loader for postcss-preset-env
polarbirke Sep 26, 2025
d65115f
Add sourcemap (needed for resolve-url-loader)
polarbirke Sep 26, 2025
2bfa731
Try first iteration of postcss-purgecss
polarbirke Sep 26, 2025
c3dd58c
Enable a separate config per entry file for Webpack plugins
polarbirke Sep 29, 2025
04fea48
Disable resolve-url-loader debug mode; delete unnecessary importers o…
polarbirke Sep 29, 2025
4813d4f
Tighten up PurgeCSS setup; add option to pass in postCssPresetEnvConf…
polarbirke Sep 29, 2025
fd31aae
Merge remote-tracking branch 'origin/master' into webpack-sass-loader
polarbirke Jan 5, 2026
5e3e536
Merge webpack and stylepack configs into a single "weballpacka" task …
polarbirke Jan 5, 2026
2a238df
Fix path matching by resolving webpack loaderContext.resourcePath and…
polarbirke Jan 6, 2026
c0f3c85
Fix package naming collision
polarbirke Jan 6, 2026
075c30b
Use RemoveEmptyScriptsPlugin to delete empty `.js` files left over af…
polarbirke Jan 7, 2026
933c639
Add www/bundles to default SCSS loadPaths
polarbirke Jan 7, 2026
43b4170
Try to repair symlink test
polarbirke Jan 9, 2026
f6c4402
Test symlinked Sass import instead of separate generated file
polarbirke Jan 9, 2026
915b880
Use Node.js-native rm instead of rimraf
polarbirke Jan 16, 2026
90c8682
Add simple watch process for Webpack
polarbirke Jan 23, 2026
b9ca4e6
Clean up names
polarbirke Jan 23, 2026
4caab7b
Adapt tests, make config pseudo private
polarbirke Jan 23, 2026
5591e0a
Add asset handling for web font files
polarbirke Feb 26, 2026
dd9b868
Update Test Snapshots to account for new rule in config
polarbirke Feb 26, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Tests

on:
push:
branches: [ master ]
pull_request:
pull_request_target:

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

jobs:
JSUnit:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [ 20.x ]

steps:
- uses: actions/checkout@v4

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: yarn install --immutable --immutable-cache --check-cache
- run: yarn test
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
yarn-error.log
6 changes: 6 additions & 0 deletions jest.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
testEnvironment: 'node',
snapshotFormat: {
escapeString: false,
},
};
18 changes: 16 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"@fullhuman/postcss-purgecss": "^4.0.3",
"babel-loader": "^10.0.0",
"browser-sync": "^2.26.7",
"browserslist-config-webfactory": "^1.0.0",
"browserslist-config-webfactory": "^2.0.0",
"css-loader": "^7.1.2",
"dotenv": "^10.0.0",
"fancy-log": "^1.3.3",
"gulp": "^4.0.0",
Expand All @@ -23,20 +24,33 @@
"gulp-stylelint": "^13.0.0",
"gulp-svgmin": "^4.1.0",
"gulp-terser": "^2.0.1",
"mini-css-extract-plugin": "^2.9.4",
"minimist": "^1.2.0",
"postcss": "^8.0.9",
"postcss-loader": "^8.2.0",
"postcss-preset-env": "^9.3.0",
"postcss-url": "^10.1.3",
"resolve-url-loader": "^5.0.0",
"sass-loader": "^16.0.5",
"stylelint": "^14.1.0",
"stylelint-config-sass-guidelines": "^9.0.1",
"stylelint-order": "^5.0.0",
"terser": "^5.3.8",
"through2": "^4.0.2",
"ts-loader": "^9.5.4",
"webpack": "^5.103.0",
"webpack-remove-empty-scripts": "^1.1.1",
"webpack-stream": "^7.0.0"
},
"browserslist": [
"extends browserslist-config-webfactory/default"
]
],
"devDependencies": {
"jest": "^30.2.0",
"jquery": "^3.7.1",
"sass-embedded": "^1.97.1"
},
"scripts": {
"test": "jest"
}
}
116 changes: 116 additions & 0 deletions tasks/stylepack.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const postcssPurgecss = require("@fullhuman/postcss-purgecss");
const argv = require('minimist')(process.argv.slice(2));
const webpackStream = require('webpack-stream');
const mergeStream = require('merge-stream');
const path = require('path');

// This custom extractor will also match selectors that contain
// special chars like "_", ".", ":", "\" and "@"
function utilityCssExtractor(content) {
return content.match(/[a-zA-Z0-9-_.:@\/]+/g)
}

function stylepack(gulp, $, config) {

const streams = config.styles.files.map((file) => {
// Set up PurgeCSS with external config
let purgeCssConfig = file.purgeCss ?? config.styles.purgeCss;
let purgeCssDisabled = argv.purgecss === false; // Check for CLI flags/args
let purgeCss = purgeCssConfig && !purgeCssDisabled; // Determine if PurgeCSS should run

// Grab a PostCSS Preset Env config to use;
// always prefers a stylesheet-specific one over a global config for all CSS files
let postCssPresetEnvConfig = file.postCssPresetEnv || config.styles.postCssPresetEnv || '';

const webpackConfig = {
entry: `/${config.webdir}/${file.files}`,
output: {
// path: path.resolve(__dirname, 'webpack-tmp', file.destDir || ''),
filename: `webpack-tmp/${file.name}`,
},
resolve: {
mainFields: ['browser', 'module', 'main'],
},
module: {
rules: [
{
test: /\.(png|jpe?g|gif|svg|webp|avif)$/i,
type: 'asset/resource',
generator: {
filename: 'img/[name].[hash][ext]'
}
},
{
test: /\.s[ac]ss$/i,
use: [
{
loader: MiniCssExtractPlugin.loader,
},
{
loader: 'css-loader',
options: {
sourceMap: true,
}
},
{
loader: 'resolve-url-loader',
},
{
loader: "postcss-loader",
options: {
sourceMap: true,
postcssOptions: {
plugins: [
["postcss-preset-env", postCssPresetEnvConfig],
purgeCss ? postcssPurgecss({
content: purgeCssConfig.content,
extractors: [
{
extractor: utilityCssExtractor,
extensions: ['php', 'twig', 'js', 'svg']
}
],
safelist: purgeCssConfig.safelist,
}) : false,
].filter(Boolean),
},
},
},
{
loader: 'sass-loader',
options: {
implementation: 'sass-embedded',
api: 'modern',
sourceMap: true,
sassOptions: {
loadPaths: config.styles.includePaths ? config.styles.includePaths : [config.npmdir]
},
},
},
],
},
],
},
plugins: [
new MiniCssExtractPlugin({
filename: `${file.destDir}/${file.name}`,
}),
],
mode: config.development && $.argv.prod !== true ? 'development' : 'production',
devtool: $.argv.debug === true ? 'source-map' : false,
stats: {
preset: 'normal',
timings: true
},
};

return webpackStream(webpackConfig)
.pipe(gulp.dest(path.join(config.webdir)));
});

return mergeStream(...streams)
.pipe($.browserSync.reload({ stream: true }));
}

exports.stylepack = stylepack;
Loading