@muonic/muon 0.0.2-experimental-166-296abd5.0 → 0.0.2-experimental-167-6557c80.0

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@muonic/muon",
3
- "version": "0.0.2-experimental-166-296abd5.0",
3
+ "version": "0.0.2-experimental-167-6557c80.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -3,6 +3,7 @@ import stylesPlugin from 'rollup-plugin-styles';
3
3
  import replacePlugin from '@rollup/plugin-replace';
4
4
  import aliasPlugin from '@rollup/plugin-alias';
5
5
  import autoprefixer from 'autoprefixer';
6
+ import postcss from 'postcss';
6
7
  import postcssPreset from 'postcss-preset-env';
7
8
  import postcssImport from 'postcss-import';
8
9
  import postcssVariables from 'postcss-simple-vars';
@@ -18,19 +19,6 @@ const __dirname = path.dirname(__filename);
18
19
 
19
20
  const config = getConfig();
20
21
 
21
- const muonPlugin = () => {
22
- return {
23
- name: 'muon',
24
- async buildStart() {
25
- const destination = getDestination();
26
- cleanup(destination, true).then(async () => {
27
- const cejson = await sourceFilesAnalyzer();
28
- fs.writeFileSync(path.join(destination, 'custom-elements.json'), cejson);
29
- });
30
- }
31
- };
32
- };
33
-
34
22
  const tokenPath = path.join(__dirname, '..', 'build', 'tokens', 'es6', 'muon-tokens.mjs');
35
23
  let designTokens = {};
36
24
 
@@ -44,17 +32,6 @@ const buildTokensPlugin = () => {
44
32
  };
45
33
  };
46
34
 
47
- const styles = fromRollup(stylesPlugin);
48
- const replace = fromRollup(replacePlugin);
49
- const litcss = fromRollup(litcssPlugin);
50
- const alias = fromRollup(aliasPlugin);
51
- const muon = fromRollup(muonPlugin);
52
- const buildTokens = fromRollup(buildTokensPlugin);
53
-
54
- const aliasConfig = {
55
- entries: getAliasPaths('regex')
56
- };
57
-
58
35
  const postcssPlugins = [
59
36
  postcssVariables({
60
37
  variables() {
@@ -74,15 +51,68 @@ const postcssPlugins = [
74
51
  autoprefixer({ grid: true })
75
52
  ];
76
53
 
77
- // @TODO: bring back when global css is used
78
- // const createGlobalCSS = async (destination) => {
79
- // const globalCSSUrl = path.join(__filename, '..', '..', '..', 'css', 'global.css');
80
- // const globalCSSDest = path.join(destination, 'muon.min.css');
81
- // const globalCSS = fs.readFileSync(globalCSSUrl);
82
- // const processedCSS = await postcss(postcssPlugins).process(globalCSS, { from: globalCSSUrl, to: globalCSSDest });
54
+ const createGlobalCSS = async () => {
55
+ const globalCSSUrl = path.join(process.cwd(), 'css', 'global.css');
56
+
57
+ if (fs.existsSync(globalCSSUrl)) {
58
+ const globalCSS = fs.readFileSync(globalCSSUrl);
59
+ const processedCSS = await postcss(postcssPlugins).process(globalCSS, { from: globalCSSUrl });
60
+ return processedCSS.css;
61
+ }
62
+
63
+ return undefined;
64
+ };
83
65
 
84
- // fs.writeFileSync(globalCSSDest, processedCSS.css, 'utf8');
85
- // };
66
+ const muonPlugin = () => {
67
+ return {
68
+ name: 'muon',
69
+ async buildStart() {
70
+ const destination = getDestination();
71
+ cleanup(destination, true).then(async () => {
72
+ const cejson = await sourceFilesAnalyzer();
73
+ fs.writeFileSync(path.join(destination, 'custom-elements.json'), cejson);
74
+ });
75
+ },
76
+ async transform(code, id) {
77
+ if (id.includes(path.join('muon', 'index.js'))) {
78
+ const globalCSS = await createGlobalCSS();
79
+
80
+ if (!globalCSS) {
81
+ return null;
82
+ }
83
+
84
+ if (!code?.includes('globalCSS')) {
85
+ return {
86
+ code: `
87
+ const globalCSS = document.createElement('style');
88
+ globalCSS.innerHTML = \`${globalCSS}\`;
89
+ document.head.appendChild(globalCSS);
90
+ ${code}
91
+ `,
92
+ map: null
93
+ };
94
+ } else {
95
+ return {
96
+ code
97
+ };
98
+ }
99
+ }
100
+
101
+ return null;
102
+ }
103
+ };
104
+ };
105
+
106
+ const styles = fromRollup(stylesPlugin);
107
+ const replace = fromRollup(replacePlugin);
108
+ const litcss = fromRollup(litcssPlugin);
109
+ const alias = fromRollup(aliasPlugin);
110
+ const muon = fromRollup(muonPlugin);
111
+ const buildTokens = fromRollup(buildTokensPlugin);
112
+
113
+ const aliasConfig = {
114
+ entries: getAliasPaths('regex')
115
+ };
86
116
 
87
117
  const styleConfig = {
88
118
  mode: 'emit',
@@ -9,6 +9,9 @@ export default {
9
9
  nodeResolve: true,
10
10
  mimeTypes: {
11
11
  '**/*.json': 'js',
12
+ '**/css/*.css': 'text/css',
13
+ '**/dist/*.css': 'text/css',
14
+ 'muon.min.css': 'text/css',
12
15
  '**/*.css': 'js'
13
16
  },
14
17
  plugins: [