@mlut/plugins 1.0.0 → 1.0.2

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/README.md CHANGED
@@ -87,8 +87,8 @@ interface Options {
87
87
 
88
88
  - `output` - output CSS file
89
89
  - `input` - input Sass file when you import mlut, configure it and write other CSS
90
- - `minify` - generate minified CSS. For this option to work, you need 1 of the following minifiers: [csso](https://github.com/css/csso), [lightningcss](https://github.com/parcel-bundler/lightningcss), [clean-css](https://github.com/clean-css/clean-css), [cssnano](https://github.com/cssnano/cssnano) or [esbuild](https://github.com/evanw/esbuild). You may already have it installed
91
- - `autoprefixer` - whether to add vendor prefixes to CSS properties. You need the [autoprefixer](https://github.com/postcss/autoprefixer) package or lightningcss for this option to work
90
+ - `minify` - generate minified CSS. For this option to work, you need 1 of the following minifiers: [csso](https://github.com/css/csso), [lightningcss](https://github.com/parcel-bundler/lightningcss), [clean-css](https://github.com/clean-css/clean-css), [cssnano](https://github.com/cssnano/cssnano) or [esbuild](https://github.com/evanw/esbuild). You may already have it installed. When using `lightningcss`, you will also need to install [browserslist](https://github.com/browserslist/browserslist)
91
+ - `autoprefixer` - whether to add vendor prefixes to CSS properties. You need the [autoprefixer](https://github.com/postcss/autoprefixer) package or [lightningcss](https://github.com/parcel-bundler/lightningcss) for this option to work
92
92
  - `noMergeMq` - prevent merging of CSS media queries during minification. Relevant only when using the csso minifier
93
93
 
94
94
  You can add the options in your input Sass file too. Options must be a **valid JSON**, but single quotes is allowed. Paths will be resolved relative to the JIT engine working directory
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import path from 'node:path';
1
2
  import { jitEngine, logger } from '@mlut/core';
2
3
  import { createUnplugin } from 'unplugin';
3
4
  import fs from 'fs-extra';
@@ -10,9 +11,11 @@ function debounce(fn, timeout) {
10
11
  };
11
12
  }
12
13
  export const unplugin = createUnplugin((options, meta) => {
14
+ const cwd = process.cwd();
13
15
  const pluginName = 'unplugin-mlut';
14
16
  const finalOptions = { output: '' };
15
- const inputPath = options.input;
17
+ const inputPath = options.input && path.resolve(cwd, options.input);
18
+ let outputPath = '';
16
19
  let lastCompiledCss = '';
17
20
  const isWebpack = meta.framework === 'webpack';
18
21
  let isVite = false;
@@ -21,11 +24,14 @@ export const unplugin = createUnplugin((options, meta) => {
21
24
  const css = await jitEngine.generateCss();
22
25
  if (lastCompiledCss !== css) {
23
26
  lastCompiledCss = css;
24
- await fs.outputFile(finalOptions.output, await transformCss(css, finalOptions)).catch((e) => logger.error('Failed to write the output file.', e));
27
+ await fs.outputFile(outputPath, await transformCss(css, finalOptions)).catch((e) => logger.error('Failed to write the output file.', e));
25
28
  }
26
29
  };
27
30
  const debouncedWriteCssFile = debounce(writeCssFile, 500);
28
31
  const initPlugin = async () => {
32
+ if (outputPath) {
33
+ return;
34
+ }
29
35
  let inputContent = '';
30
36
  if (inputPath) {
31
37
  inputContent = await fs.promises.readFile(inputPath)
@@ -49,6 +55,10 @@ export const unplugin = createUnplugin((options, meta) => {
49
55
  throw new Error('Output path not specified!');
50
56
  }
51
57
  await jitEngine.init([inputPath, inputContent]);
58
+ outputPath = path.resolve(cwd, finalOptions.output);
59
+ if (isViteWatch) {
60
+ await fs.outputFile(outputPath, '').catch(() => undefined);
61
+ }
52
62
  };
53
63
  return {
54
64
  name: pluginName,
@@ -61,13 +71,13 @@ export const unplugin = createUnplugin((options, meta) => {
61
71
  return {
62
72
  server: {
63
73
  watch: {
64
- ignored: ['!' + finalOptions.output]
74
+ ignored: ['!' + outputPath]
65
75
  }
66
76
  },
67
77
  };
68
78
  },
69
79
  configureServer(server) {
70
- server.watcher.add(finalOptions.output);
80
+ server.watcher.add(outputPath);
71
81
  },
72
82
  webpack(compiler) {
73
83
  compiler.hooks.beforeCompile.tapPromise(pluginName, initPlugin);
@@ -101,14 +111,12 @@ export const unplugin = createUnplugin((options, meta) => {
101
111
  tags: [
102
112
  {
103
113
  tag: 'link',
104
- attrs: { rel: 'stylesheet', href: finalOptions.output },
114
+ attrs: { rel: 'stylesheet', href: outputPath },
105
115
  },
106
116
  ],
107
117
  };
108
118
  }
109
- else if (isVite) {
110
- await writeCssFile();
111
- }
119
+ await writeCssFile();
112
120
  return html;
113
121
  },
114
122
  async watchChange(id, change) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mlut/plugins",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "mlut plugins for Rollup, Vite and Webpack",
5
5
  "author": "mr150",
6
6
  "type": "module",
@@ -51,7 +51,7 @@
51
51
  "typescript": "^4.8.0"
52
52
  },
53
53
  "dependencies": {
54
- "@mlut/core": "^2.0.0",
54
+ "@mlut/core": "^2.1.0",
55
55
  "fs-extra": "^11.2.0",
56
56
  "unplugin": "^1.10.1"
57
57
  }