Skip to content

Commit

Permalink
[#71] install rollup build
Browse files Browse the repository at this point in the history
  • Loading branch information
Kreezag committed Jan 18, 2024
1 parent f463b08 commit 1544ad4
Show file tree
Hide file tree
Showing 8 changed files with 2,383 additions and 1,546 deletions.
10 changes: 7 additions & 3 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
"browser": true,
"es2021": true
},
"extends": ["airbnb-base", "airbnb", "prettier"],
"extends": ["airbnb-base", "prettier"],
"parserOptions": {
"ecmaVersion": 12,
"sourceType": "module"
},
"plugins": ["prettier"],
"rules": {
"prettier/prettier": "error",
"max-len": ["error", { "code": 80 }],
"max-len": ["error", { "code": 80, "ignorePattern": "^import .*" }],
"newline-after-var": ["error", "always"],
"no-console": ["error", { "allow": ["warn", "error"] }],
"no-use-before-define": [
Expand All @@ -20,5 +20,9 @@
],
"import/prefer-default-export": "off"
},
"ignorePatterns": ["generator/templates", "src/scripts/domPolyfills", "theme/"]
"ignorePatterns": [
"generator/templates",
"src/scripts/domPolyfills",
"theme/"
]
}
15 changes: 11 additions & 4 deletions .husky/_/husky.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#!/bin/sh
#!/usr/bin/env sh
if [ -z "$husky_skip_init" ]; then
debug () {
[ "$HUSKY_DEBUG" = "1" ] && echo "husky (debug) - $1"
if [ "$HUSKY_DEBUG" = "1" ]; then
echo "husky (debug) - $1"
fi
}

readonly hook_name="$(basename "$0")"
readonly hook_name="$(basename -- "$0")"
debug "starting $hook_name..."

if [ "$HUSKY" = "0" ]; then
Expand All @@ -17,13 +19,18 @@ if [ -z "$husky_skip_init" ]; then
. ~/.huskyrc
fi

export readonly husky_skip_init=1
readonly husky_skip_init=1
export husky_skip_init
sh -e "$0" "$@"
exitCode="$?"

if [ $exitCode != 0 ]; then
echo "husky - $hook_name hook exited with code $exitCode (error)"
fi

if [ $exitCode = 127 ]; then
echo "husky - command not found in PATH=$PATH"
fi

exit $exitCode
fi
3,737 changes: 2,208 additions & 1,529 deletions package-lock.json

Large diffs are not rendered by default.

16 changes: 11 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
"version": "1.0.0",
"description": "Starter theme and environment for the largest Shopify stores.",
"main": "webpack.config.js",
"type": "module",
"scripts": {
"build": "webpack --progress",
"build:prod": "webpack --progress --mode='production'",
"build": "rollup --config",
"build:prod": "rollup --config --mode='production'",
"analyze": "webpack --profile --json > .stats-dev.json && webpack-bundle-analyzer .stats-dev.json",
"analyze:prod": "webpack --mode='production' --profile --json > .stats-prod.json && webpack-bundle-analyzer .stats-prod.json",
"watch": "webpack --watch",
Expand Down Expand Up @@ -55,19 +56,18 @@
"devDependencies": {
"@babel/core": "^7.19.6",
"@babel/preset-env": "^7.19.4",
"@rollup/plugin-node-resolve": "^15.0.1",
"autoprefixer": "^10.4.12",
"babel-loader": "^8.2.5",
"concurrently": "^7.4.0",
"copy-webpack-plugin": "^11.0.0",
"css-loader": "^6.7.1",
"eslint": "^8.25.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jsx-a11y": "^6.6.1",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-react": "^7.31.10",
"gulp-rename": "^2.0.0",
"husky": "^8.0.1",
"imagemin-webpack-plugin": "^2.4.2",
Expand All @@ -81,6 +81,9 @@
"prettier": "^2.7.1",
"pretty-quick": "^3.1.3",
"remove-files-webpack-plugin": "^1.5.0",
"rollup": "^3.12.0",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-sass": "^1.12.17",
"sass": "^1.55.0",
"sass-loader": "^13.1.0",
"stylelint": "^15.10.1",
Expand All @@ -96,6 +99,8 @@
"yo": "^4.3.0"
},
"dependencies": {
"@rollup/plugin-multi-entry": "^6.0.0",
"@rollup/plugin-terser": "^0.4.0",
"@shopify/prettier-plugin-liquid": "^0.4.0",
"@shopify/theme-a11y": "^4.1.1",
"@shopify/theme-addresses": "^4.1.1",
Expand All @@ -107,7 +112,8 @@
"lazysizes": "^5.3.2",
"lodash": "^4.17.21",
"normalize.css": "^8.0.1",
"qrcode": "^1.5.1"
"qrcode": "^1.5.1",
"rollup-plugin-postcss": "^4.0.2"
},
"lint-staged": {
"*.{js,ts}": "eslint --fix",
Expand Down
3 changes: 3 additions & 0 deletions postcss.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
plugins: [require('autoprefixer')],
};
5 changes: 0 additions & 5 deletions postcss.config.js

This file was deleted.

75 changes: 75 additions & 0 deletions rollup-helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import path from 'path';
import fs from 'fs';
import { fileURLToPath } from 'url';

// eslint-disable-next-line no-underscore-dangle
const __filename = fileURLToPath(import.meta.url);

// eslint-disable-next-line no-underscore-dangle
const __dirname = path.dirname(__filename);

export const getDirNames = (_path) =>
!fs.existsSync(_path)
? []
: fs
.readdirSync(_path, { withFileTypes: true })
.filter(Boolean)
.filter((dirent) => dirent.isDirectory())
.map((dirent) => dirent.name);

const getFilesNames = (_path) =>
!fs.existsSync(_path)
? []
: fs
.readdirSync(_path, { withFileTypes: true })
.filter(Boolean)
.filter((dirent) => dirent.isFile())
.map((dirent) => dirent.name);

export const makeInputsBySource = (source, extList = [], filterCb = null) => {
if (!fs.existsSync(source)) {
return {};
}

return getFilesNames(source)
.filter((name) => {
const isRelatedFile = extList.includes(path.parse(name).ext);
const isFilteredFile = filterCb ? filterCb(name) : true;

return isRelatedFile && isFilteredFile;
})
.map((name) => path.resolve(__dirname, source, name));
};

export const makeJsInputs = (source) => makeInputsBySource(source, ['.js']);

export const makeTemplatesInputs = (templatesSource) => {
if (!fs.existsSync(templatesSource)) {
return {};
}

return getDirNames(templatesSource)
.filter((name) => name !== 'common')
.reduce(
(res, dirName) => {
(
makeInputsBySource(
path.resolve(templatesSource, dirName),
['.js', '.scss'],
(name) => name.includes(dirName)
) || []
).forEach((file) => {
if (file.includes('.js')) {
res.js.push(file);
}

if (file.includes('.scss')) {
res.scss.push(file);
}
});

return res;
},
{ js: [], scss: [] }
);
};
68 changes: 68 additions & 0 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// import multiEntry from '@rollup/plugin-multi-entry';
import sass from 'rollup-plugin-sass';
import postcss from 'rollup-plugin-postcss';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from "rollup-plugin-commonjs";
import {
makeJsInputs,
makeTemplatesInputs
} from "./rollup-helpers.js";
import path from "path";


const postcssPluginsSet = makeTemplatesInputs('src/templates').scss.map((file) => {
const extractName = `${path.parse(file).name}.css`;

console.log('___', file, extractName)

return postcss({
include: file,
extract: extractName,
use: ['sass']
});
})

export default {
input: [
...makeTemplatesInputs('src/templates').js,
...makeJsInputs('src/scripts')
],
output: {
dir: 'dist/assets',
},
plugins: [
// postcss({
// include: "src/templates/article/article.scss",
// extract: 'article.css',
// use: ['sass']
// }),
...postcssPluginsSet,
sass(),
commonjs({
include: "node_modules/**",
namedExports: {
// "./node_modules/react/index.js": [
// "cloneElement",
// "createElement",
// "PropTypes",
// "Children",
// "Component",
// "createFactory",
// "PureComponent",
// "lazy",
// "Suspense",
// "useState",
// "useEffect",
// ],
// "./node_modules/react-dom/index.js": ["findDOMNode"],
// "./node_modules/babel-runtime/node_modules/core-js/library/modules/es6.object.to-string.js": [
// "default",
// ],
// "./node_modules/process/browser.js": ["nextTick"],
// "./node_modules/events/events.js": ["EventEmitter"],
// "./node_modules/react-is/index.js": ["isValidElementType"],
},
}),
resolve()
],
};

0 comments on commit 1544ad4

Please sign in to comment.