Revert "feat: add writeToFile option"
This reverts commit 07545133649c7ec93e18da9960080b318ec222da.
This feature used convert css files to js (mostly because it esbuild internally was using js loader because of export statement 🤷♂️)
This commit is contained in:
parent
07aa0b6d3a
commit
0a417a0368
@ -1,4 +1,5 @@
|
||||
# Looking for a maintainer!
|
||||
|
||||
Unfortunately I don't have time for this plugin. Please contact me if you'd like to take on this project.
|
||||
|
||||
# esbuild-plugin-postcss2
|
||||
|
||||
16
package.json
16
package.json
@ -1,8 +1,11 @@
|
||||
{
|
||||
"name": "esbuild-plugin-postcss2",
|
||||
"version": "0.1.2",
|
||||
"name": "@frappe/esbuild-plugin-postcss2",
|
||||
"version": "0.1.3",
|
||||
"description": "Use postcss with esbuild",
|
||||
"repository": "https://github.com/martonlederer/esbuild-plugin-postcss2",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/frappe/esbuild-plugin-postcss2.git"
|
||||
},
|
||||
"author": "Marton Lederer <marton@lederer.hu>",
|
||||
"license": "MIT",
|
||||
"private": false,
|
||||
@ -30,7 +33,6 @@
|
||||
"autoprefixer": "^10.2.5",
|
||||
"fs-extra": "^9.1.0",
|
||||
"less": "^4.x",
|
||||
"postcss": "8.x",
|
||||
"postcss-modules": "^4.0.0",
|
||||
"resolve-file": "^0.3.0",
|
||||
"sass": "^1.x",
|
||||
@ -61,5 +63,9 @@
|
||||
"postcss": "8.x",
|
||||
"sass": "^1.x",
|
||||
"stylus": "^0.x"
|
||||
}
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/frappe/esbuild-plugin-postcss2/issues"
|
||||
},
|
||||
"homepage": "https://github.com/frappe/esbuild-plugin-postcss2#readme"
|
||||
}
|
||||
|
||||
53
src/index.ts
53
src/index.ts
@ -30,7 +30,6 @@ interface PostCSSPluginOptions {
|
||||
sassOptions?: SassOptions;
|
||||
lessOptions?: Less.Options;
|
||||
stylusOptions?: StylusRenderOptions;
|
||||
writeToFile?: boolean;
|
||||
fileIsModule?: (filename: string) => boolean;
|
||||
}
|
||||
|
||||
@ -48,18 +47,16 @@ export const defaultOptions: PostCSSPluginOptions = {
|
||||
sassOptions: {},
|
||||
lessOptions: {},
|
||||
stylusOptions: {},
|
||||
writeToFile: true,
|
||||
fileIsModule: null
|
||||
};
|
||||
|
||||
const postCSSPlugin = ({
|
||||
plugins,
|
||||
modules,
|
||||
rootDir,
|
||||
sassOptions,
|
||||
lessOptions,
|
||||
stylusOptions,
|
||||
writeToFile,
|
||||
plugins = [],
|
||||
modules = true,
|
||||
rootDir = process.cwd(),
|
||||
sassOptions = {},
|
||||
lessOptions = {},
|
||||
stylusOptions = {},
|
||||
fileIsModule
|
||||
}: PostCSSPluginOptions = defaultOptions): Plugin => ({
|
||||
name: "postcss2",
|
||||
@ -144,7 +141,10 @@ const postCSSPlugin = ({
|
||||
|
||||
// parse files with preprocessors
|
||||
if (sourceExt === ".sass" || sourceExt === ".scss") {
|
||||
const sassResult = await renderSass({...sassOptions, file: sourceFullPath})
|
||||
const sassResult = await renderSass({
|
||||
...sassOptions,
|
||||
file: sourceFullPath
|
||||
});
|
||||
css = sassResult.css.toString();
|
||||
watchFiles.push(...sassResult.stats.includedFiles);
|
||||
}
|
||||
@ -172,21 +172,14 @@ const postCSSPlugin = ({
|
||||
watchFiles.push(...getPostCssDependencies(result.messages));
|
||||
|
||||
// Write result CSS
|
||||
if (writeToFile) {
|
||||
await writeFile(tmpFilePath, result.css);
|
||||
}
|
||||
|
||||
return {
|
||||
namespace: isModule
|
||||
? "postcss-module"
|
||||
: writeToFile
|
||||
? "file"
|
||||
: "postcss-text",
|
||||
namespace: isModule ? "postcss-module" : "file",
|
||||
path: tmpFilePath,
|
||||
watchFiles,
|
||||
pluginData: {
|
||||
originalPath: sourceFullPath,
|
||||
css: result.css
|
||||
originalPath: sourceFullPath
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -199,30 +192,16 @@ const postCSSPlugin = ({
|
||||
const mod = modulesMap.find(
|
||||
({ path }) => path === args?.pluginData?.originalPath
|
||||
),
|
||||
resolveDir = path.dirname(args.path),
|
||||
css = args?.pluginData?.css || "";
|
||||
resolveDir = path.dirname(args.path);
|
||||
|
||||
return {
|
||||
resolveDir,
|
||||
contents: [
|
||||
writeToFile ? `import ${JSON.stringify(args.path)};` : null,
|
||||
`export default ${JSON.stringify(mod && mod.map ? mod.map : {})};`,
|
||||
writeToFile
|
||||
? null
|
||||
: `export const stylesheet=${JSON.stringify(css)};`
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join("\n")
|
||||
contents: `import ${JSON.stringify(
|
||||
args.path
|
||||
)};\nexport default ${JSON.stringify(mod && mod.map ? mod.map : {})};`
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
build.onLoad({ filter: /.*/, namespace: "postcss-text" }, async (args) => {
|
||||
const css = args?.pluginData?.css || "";
|
||||
return {
|
||||
contents: `export default ${JSON.stringify(css)};`
|
||||
};
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user