@swissquote/crafty-preset-lightningcss 1.22.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. package/README.md +70 -0
  2. package/dist/webpack-packages/api.js +85 -0
  3. package/dist/webpack-packages/bundled.js +9126 -0
  4. package/dist/webpack-packages/getUrl.js +26 -0
  5. package/dist/webpack-packages/noSourceMaps.js +5 -0
  6. package/dist/webpack-packages/runtime/injectStylesIntoLinkTag.js +29 -0
  7. package/dist/webpack-packages/runtime/injectStylesIntoStyleTag.js +104 -0
  8. package/dist/webpack-packages/runtime/insertBySelector.js +39 -0
  9. package/dist/webpack-packages/runtime/insertStyleElement.js +11 -0
  10. package/dist/webpack-packages/runtime/isEqualLocals.js +35 -0
  11. package/dist/webpack-packages/runtime/isOldIE.js +19 -0
  12. package/dist/webpack-packages/runtime/setAttributesWithAttributes.js +16 -0
  13. package/dist/webpack-packages/runtime/setAttributesWithAttributesAndNonce.js +10 -0
  14. package/dist/webpack-packages/runtime/setAttributesWithoutAttributes.js +12 -0
  15. package/dist/webpack-packages/runtime/singletonStyleDomAPI.js +94 -0
  16. package/dist/webpack-packages/runtime/styleDomAPI.js +70 -0
  17. package/dist/webpack-packages/runtime/styleTagTransform.js +16 -0
  18. package/dist/webpack-packages/sourceMaps.js +16 -0
  19. package/dist/webpack-packages/sourcemap-register.js +1 -0
  20. package/dist/webpack-packages/webpack-packages.js.map +1 -0
  21. package/package.json +30 -0
  22. package/packages/css-loader.js +2 -0
  23. package/packages/lightningcss-loader.js +2 -0
  24. package/packages/style-loader.js +2 -0
  25. package/src/ModuleFilenameHelpers.js +39 -0
  26. package/src/index.js +59 -0
  27. package/src/minify.js +1 -0
  28. package/src/webpack-sources.js +1 -0
  29. package/src/webpack-utils.js +166 -0
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@swissquote/crafty-preset-lightningcss",
3
+ "version": "1.22.0-alpha.1",
4
+ "license": "Apache-2.0",
5
+ "repository": "https://github.com/swissquote/crafty.git",
6
+ "publishConfig": {
7
+ "registry": "https://registry.npmjs.org",
8
+ "access": "public"
9
+ },
10
+ "main": "src/index.js",
11
+ "scripts": {
12
+ "lint": "node ../crafty-preset-eslint/src/commands/jsLint.js --preset recommended --preset node src",
13
+ "build": "node ../../utils/build.js"
14
+ },
15
+ "dependencies": {
16
+ "@swissquote/crafty": "1.22.0-alpha.1",
17
+ "@swissquote/crafty-commons": "1.22.0-alpha.1",
18
+ "@swissquote/crafty-preset-stylelint": "1.22.0-alpha.1",
19
+ "lightningcss": "1.18.0",
20
+ "mini-css-extract-plugin": "2.7.2"
21
+ },
22
+ "devDependencies": {
23
+ "css-loader": "6.7.3",
24
+ "lightningcss-loader": "2.1.0",
25
+ "style-loader": "3.3.1"
26
+ },
27
+ "engines": {
28
+ "node": ">=16"
29
+ }
30
+ }
@@ -0,0 +1,2 @@
1
+ //module.exports = require("css-loader");
2
+ module.exports = require("../dist/webpack-packages/bundled.js").cssLoader();
@@ -0,0 +1,2 @@
1
+ //module.exports = require("lightningcss-loader");
2
+ module.exports = require("../dist/webpack-packages/bundled.js").lightningcssLoader();
@@ -0,0 +1,2 @@
1
+ //module.exports = require("style-loader");
2
+ module.exports = require("../dist/webpack-packages/bundled.js").styleLoader();
@@ -0,0 +1,39 @@
1
+ function asRegExp(test) {
2
+ if (typeof test === "string") {
3
+ return new RegExp(`^${test.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&")}`);
4
+ }
5
+ return test;
6
+ }
7
+
8
+ function matchPart(str, testStr) {
9
+ if (!testStr) return true;
10
+ const test = asRegExp(testStr);
11
+ if (Array.isArray(test)) {
12
+ return test.map(asRegExp).some(regExp => regExp.test(str));
13
+ } else {
14
+ return test.test(str);
15
+ }
16
+ }
17
+
18
+ function matchObject(obj, str) {
19
+ if (obj.test) {
20
+ if (!matchPart(str, obj.test)) {
21
+ return false;
22
+ }
23
+ }
24
+ if (obj.include) {
25
+ if (!matchPart(str, obj.include)) {
26
+ return false;
27
+ }
28
+ }
29
+ if (obj.exclude) {
30
+ if (matchPart(str, obj.exclude)) {
31
+ return false;
32
+ }
33
+ }
34
+ return true;
35
+ }
36
+
37
+ module.exports = {
38
+ matchObject
39
+ };
package/src/index.js ADDED
@@ -0,0 +1,59 @@
1
+ const path = require("path");
2
+
3
+ const { createGlobalRule, createModuleRule } = require("./webpack-utils");
4
+
5
+ const MODULES = path.join(__dirname, "..", "node_modules");
6
+ const hasOwnProperty = Object.prototype.hasOwnProperty;
7
+
8
+ module.exports = {
9
+ presets: [require.resolve("@swissquote/crafty-preset-stylelint")],
10
+ defaultConfig() {
11
+ return {
12
+ bundleTypes: { css: "css" }
13
+ };
14
+ },
15
+ config(config) {
16
+ // Add missing informations to CSS configurations
17
+ for (const i in config.css) {
18
+ if (!hasOwnProperty.call(config.css, i)) {
19
+ continue;
20
+ }
21
+
22
+ // Store the taskname inside
23
+ config.css[i].name = i;
24
+
25
+ // use destination and not filename
26
+ if (config.css[i].filename) {
27
+ config.css[i].destination = config.css[i].filename;
28
+ }
29
+
30
+ // Infer default destination if it's not specified
31
+ if (!config.css[i].destination) {
32
+ config.css[i].destination = `${i}.min.css`;
33
+ }
34
+ }
35
+
36
+ return config;
37
+ },
38
+ webpack(crafty, bundle, chain) {
39
+ chain.resolve.extensions.add(".css").add(".scss");
40
+ chain.resolve.modules.add(MODULES);
41
+ chain.resolveLoader.modules.add(MODULES);
42
+
43
+ createGlobalRule(crafty, bundle, chain);
44
+ createModuleRule(crafty, bundle, chain);
45
+
46
+ // ADD Minify plugin
47
+ chain.optimization
48
+ .minimizer("css")
49
+ .use(path.resolve(__dirname, "minify.js"), [
50
+ {
51
+ targets: crafty.config.browsers,
52
+ drafts: {
53
+ customMedia: true
54
+ },
55
+ implementation: require("lightningcss")
56
+ }
57
+ ]);
58
+ }
59
+ };
package/src/minify.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require("../packages/lightningcss-loader.js").LightningCssMinifyPlugin;
@@ -0,0 +1 @@
1
+ module.exports = require("@swissquote/crafty-runner-webpack/packages/webpack").sources;
@@ -0,0 +1,166 @@
1
+ const path = require("path");
2
+
3
+ const regexLikeIndexModule = /index\.module\.s?css$/;
4
+
5
+ function getExtractConfig(bundle) {
6
+ let extractCSSConfig = bundle.extractCSS;
7
+ if (extractCSSConfig === true) {
8
+ extractCSSConfig = {
9
+ filename: "[bundle]-[name].min.css"
10
+ };
11
+ } else if (typeof extractCSSConfig === "string") {
12
+ extractCSSConfig = {
13
+ filename: extractCSSConfig
14
+ };
15
+ }
16
+
17
+ // Allow to template [bundle] with the bundle name
18
+ if (typeof extractCSSConfig.filename === "string") {
19
+ extractCSSConfig.filename = extractCSSConfig.filename.replace(
20
+ "[bundle]",
21
+ bundle.name
22
+ );
23
+ }
24
+
25
+ return extractCSSConfig;
26
+ }
27
+
28
+ function getCssModuleLocalIdent(context, _, exportName, options) {
29
+ const loaderUtils = require("loader-utils");
30
+
31
+ const relativePath = path
32
+ .relative(context.rootContext, context.resourcePath)
33
+ .replace(/\\+/g, "/");
34
+
35
+ // Generate a more meaningful name (parent folder) when the user names the
36
+ // file `index.module.css`.
37
+ const fileNameOrFolder = regexLikeIndexModule.test(relativePath)
38
+ ? "[folder]"
39
+ : "[name]";
40
+
41
+ // Generate a hash to make the class name unique.
42
+ const hash = loaderUtils.getHashDigest(
43
+ Buffer.from(`filePath:${relativePath}#className:${exportName}`),
44
+ "md5",
45
+ "base64",
46
+ 5
47
+ );
48
+
49
+ // Have webpack interpolate the `[folder]` or `[name]` to its real value.
50
+ return (
51
+ loaderUtils
52
+ .interpolateName(
53
+ context,
54
+ `${fileNameOrFolder}_${exportName}__${hash}`,
55
+ options
56
+ )
57
+ .replace(
58
+ // Webpack name interpolation returns `about.module_root__2oFM9` for
59
+ // `.root {}` inside a file named `about.module.css`. Let's simplify
60
+ // this.
61
+ /\.module_/,
62
+ "_"
63
+ )
64
+ // Replace invalid symbols with underscores instead of escaping
65
+ // https://mathiasbynens.be/notes/css-escapes#identifiers-strings
66
+ .replace(/[^a-zA-Z0-9-_]/g, "_")
67
+ // "they cannot start with a digit, two hyphens, or a hyphen followed by a digit [sic]"
68
+ // https://www.w3.org/TR/CSS21/syndata.html#characters
69
+ .replace(/^(\d|--|-\d)/, "__$1")
70
+ );
71
+ }
72
+
73
+ function extractCss(bundle, chain, styleRule) {
74
+ // Add this only once per bundle
75
+ if (bundle.extractCSSConfigured) {
76
+ return;
77
+ }
78
+ bundle.extractCSSConfigured = true;
79
+
80
+ // Initialize extraction plugin
81
+ const MiniCssExtractPlugin = require("mini-css-extract-plugin");
82
+
83
+ // Create a list of loaders that also contains the extraction loader
84
+ styleRule.use("style-loader").loader(MiniCssExtractPlugin.loader);
85
+
86
+ chain
87
+ .plugin("extractCSS")
88
+ .use(MiniCssExtractPlugin, [getExtractConfig(bundle)]);
89
+ }
90
+
91
+ function createRule(crafty, bundle, chain, styleRule, options) {
92
+ // "lightningcss" loader applies autoprefixer to our CSS.
93
+ // "css" loader resolves paths in CSS and adds assets as dependencies.
94
+ // "style" loader turns CSS into JS modules that inject <style> tags.
95
+ // The "style" loader enables hot editing of CSS.
96
+
97
+ if (crafty.getEnvironment() === "production" && bundle.extractCSS) {
98
+ extractCss(bundle, chain, styleRule);
99
+ } else {
100
+ styleRule
101
+ .use("style-loader")
102
+ .loader(require.resolve("../packages/style-loader.js"));
103
+ }
104
+
105
+ styleRule
106
+ .use("css-loader")
107
+ .loader(require.resolve("../packages/css-loader.js"))
108
+ .options({
109
+ importLoaders: 1,
110
+ sourceMap:
111
+ crafty.getEnvironment() === "production" && !!bundle.extractCSS,
112
+ ...(options.cssLoader || {})
113
+ });
114
+
115
+ styleRule
116
+ .use("lightningcss-loader")
117
+ .loader(require.resolve("../packages/lightningcss-loader.js"))
118
+ .options({
119
+ implementation: require("lightningcss"),
120
+ targets: crafty.config.browsers
121
+ });
122
+ }
123
+
124
+ function createGlobalRule(crafty, bundle, chain) {
125
+ createRule(
126
+ crafty,
127
+ bundle,
128
+ chain,
129
+ chain.module
130
+ .rule("styles")
131
+ .test(/(?<!\.module)\.s?css$/i)
132
+ .sideEffects(true),
133
+ {
134
+ cssLoader: {
135
+ modules: false
136
+ }
137
+ }
138
+ );
139
+ }
140
+
141
+ function createModuleRule(crafty, bundle, chain) {
142
+ createRule(
143
+ crafty,
144
+ bundle,
145
+ chain,
146
+ chain.module
147
+ .rule("styles-modules")
148
+ .test(/\.module\.s?css$/i)
149
+ .sideEffects(false),
150
+ {
151
+ cssLoader: {
152
+ modules: {
153
+ exportLocalsConvention: "asIs",
154
+ mode: "pure",
155
+ getLocalIdent: getCssModuleLocalIdent
156
+ }
157
+ }
158
+ }
159
+ );
160
+ }
161
+
162
+ module.exports = {
163
+ getCssModuleLocalIdent,
164
+ createGlobalRule,
165
+ createModuleRule
166
+ };