CSS file is not generated when using vue build and tailwindcss - vuejs3

I am building a component library using Vue and TailwindCSS. When I pulled in the dependancy and loaded in the components to my application I noticed non of the styles were present.
I went back to the build and could see that the common, umd and umd.min files were generated but the css file was not.
If I add something like
<style>
.foo {}
</style>
To one of my component vue files and run the build command I can see the /dist/libname.css file is generated with .foo{} inside.
Is there anything I need to do to get the purged css to be included in the build?

I couldn't actually find an answer so I came up with a solution that might be well overcomplicating it.
I have the following scripts in my package.json file;
"build": "npm run build-vue && npm run tailwind && node uibuild",
"build-vue": "vue-cli-service build --target lib --name mypackagename ./src/index.js",
"tailwind": "NODE_ENV=production tailwindcss build -o ./dist/mypackagename-base.css"
And a javascript file;
const fs = require("fs");
const version = require('./package.json').version;
const packageName = 'mypackagename';
fs.readFile("./dist/" + packageName + "-base.css", (err, buff) => {
let contents = "/** \n" +
"* Some Intro Title \n" +
"* Version: v" + version + "\n" +
"* Author: John Doe \n" +
"*/\n\n";
if (err) {
console.error(err);
return;
}
contents += buff.toString() + "\n";
fs.readFile("./dist/" + packageName + ".css", (err, buff) => {
if (! err) contents += buff.toString();
fs.writeFile("./dist/" + packageName + ".prod.css", contents, err => {
if (err) console.error(err);
if (fs.existsSync("./dist/" + packageName + "-base.css")) fs.unlinkSync("./dist/" + packageName + "-base.css");
if (fs.existsSync("./dist/" + packageName + ".css")) fs.unlinkSync("./dist/" + packageName + ".css");
});
});
});
and then simply run npm run build

Related

Gatsby build webpack fail with stylis

When I run gatsby build I get this error:
failed Building static HTML for pages - 10.179s
ERROR #95313
Building static HTML failed
See our docs page for more info on this error: https://gatsby.dev/debug-html
343 | for (c = []; b < a; ++b) {
344 | for (var n = 0; n < m; ++n) {
> 345 | c[v++] = Z(d[n] + ' ', h[b], e).trim();
| ^
346 | }
347 | }
348 |
WebpackError: The module '/node_modules/canvas/build/Release/canvas.node'
- stylis.esm.js:345
node_modules/#emotion/stylis/dist/stylis.esm.js:345:1
- stylis.esm.js:151
node_modules/#emotion/stylis/dist/stylis.esm.js:151:1
- stylis.esm.js:175
node_modules/#emotion/stylis/dist/stylis.esm.js:175:1
- stylis.esm.js:286
node_modules/#emotion/stylis/dist/stylis.esm.js:286:1
- stylis.esm.js:151
node_modules/#emotion/stylis/dist/stylis.esm.js:151:1
- stylis.esm.js:175
node_modules/#emotion/stylis/dist/stylis.esm.js:175:1
- stylis.esm.js:286
node_modules/#emotion/stylis/dist/stylis.esm.js:286:1
- stylis.esm.js:151
How to solve? When run gatsby develop there is no error.
Update gatsby-config.js to contain the plugin gatsby-plugin-emotion:
module.exports = {
plugins: [
`gatsby-plugin-emotion`,
],
}
This needs a restart of the gatsby development process.
Add this snippet in the gatsby-node.js:
exports.onCreateWebpackConfig = ({ stage, loaders, actions }) => {
if (stage === "build-html") {
actions.setWebpackConfig({
module: {
rules: [
{
test: /canvas/,
use: loaders.null(),
},
],
},
})
}
}
There's a package that is trying to access global objects such as window or document in your SSR (Server-Side Rendering) where obviously is not defined (it even exist) because gatsby-build occurs in the Node server while gatsby develop occurs in the browser-side, where the window exists and the compilation time. With the snippet above, you are adding a null loader to the offending module when webpack transpile the code.
The rule test is a regular expression (hence the braces, /) that matches the folder name inside node_modules. The output error shows a canvas issue but you may need to change it to /stylis/

Failed to compile with 0 errors / inconsistent builds

I'm trying to move from Assetic to Webpack but it seems quite tricky.
I have 6 different JS entries, containing different files.
I'm running "yarn encore dev":
Problem 1: I get "ERROR Failed to compile with 0 errors" - BUT it does seem to compile.
Problem 2: All compiled entries are almost identical (same size) except the first one. All that change is the filename written inside the file.
Maybe it's not really compiling in fact, then how could I fix the "Failed to compile with 0 errors" error?
My webpack.config.js:
let Encore = require('#symfony/webpack-encore');
Encore
.setOutputPath('web/build/')
.setPublicPath('/build')
.setManifestKeyPrefix('build/')
//-- this one is well-compiled (I think)
.addEntry('app-vendors', './assets/app-vendors.js')
//-- those ones are all identical
.addEntry('app-classes', './assets/app-classes.js')
.addEntry('markable-maps-classes', './assets/markable-maps-classes.js')
.addEntry('markable-maps-vendors', './assets/markable-maps-vendors.js')
.addEntry('calendar-vendors', './assets/calendar-vendors.js')
.addEntry('calendar-classes', './assets/calendar-classes.js')
.enableSingleRuntimeChunk()
;
var config = Encore.getWebpackConfig();
config.node = { fs: 'empty' };
module.exports = config;
app-classes.js
let files = [
'classes/Foldable.js',
'classes/HorizontalPlanning.js',
'classes/PlanningWorkTimes.js',
'classes/AttachmentsList.js',
'classes/CameraModal.js',
'classes/Affair.js',
'classes/AffairStepsFinancialInfos.js',
'classes/Forms.js',
'classes/NewEventContextMenu.js',
'classes/GroupAction.js',
'classes/AuthRights.js',
'functions.js',
'init.js'
];
for (let file of files)
require('../web/js/Business/' + file);
calendar-classes.js
let files = [
'classes/Calendars/BaseCalendar.js',
'classes/Calendars/SingleCalendar.js',
'classes/Calendars/SyncCalendars.js',
'classes/Calendars/EmployeesSyncCalendars.js',
'classes/Calendars/Planning.js',
'classes/Calendars/RoomsSyncCalendars.js',
];
for (let file of files)
require('../web/js/Business/' + file);
calendar-vendors.js
let files = [
'fullcalendar/fullcalendar.js',
'fullcalendar/locale/fr.js',
];
for (let file of files)
require('../web/js/Business/' + file);
Command output:
$ yarn encore dev
yarn run v1.16.0
$ '/Volumes/Macintosh HD Data/Users/theredled/Sites/qualispace/deploy/node_modules/.bin/encore' dev
Running webpack ...
ERROR Failed to compile with 0 errors 17:11:12
Entrypoint app-vendors [big] = app-vendors.css app-vendors.js
Entrypoint app-classes [big] = app-classes.js
Entrypoint markable-maps-classes [big] = markable-maps-classes.js
Entrypoint markable-maps-vendors [big] = markable-maps-vendors.js
Entrypoint calendar-vendors [big] = calendar-vendors.js
Entrypoint calendar-classes [big] = calendar-classes.js
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

unable to exclude node_modules from the folder_project

I have 2 folders named as rsync & folder_project one at path D://rsync and other at path D://project/project1/folder_project.
folder_project contains the .ignore file which contains the path for node_modules present in folder_project.
I am syncing my local files to remote machine, so I have created the rsync command in the rsync folder with a config file.The files in rsync are as follows:
rsync --> config.js node_modules ltor.ts
config.js
module.exports = {
Inputs: {
source : '../project/project1/folder_project',
destination:'ec2-user#xx.xx.xx.xx:/home/ec2-user/',
ignore: '../project/project1/folder_project/.ignore'
}
}
ltor.ts
//all imports are done.
function puts(error, stdout, stderr) { console.log(stdout) }
var onChangeFn = function (watch_directory, destination_directory, ignoreFile) {
var command = 'rsync -avzH -e "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" --progress --delete --exclude-from=' + ignoreFile + ' ' + watch_directory + ' ' + destination_directory;
exec(command, puts);
}
Question: My rsync command is ignoring node_modules from the present or current directory, I want to exclude the node modules from the folder_project directory.
How can I achieve this?

Error in using gulp + foundation (sass version)

I want to use gulp + Foundation 6 + browserify.
when run gulp in cli i have this error in terminal
write ./scss.css/foundation.css
path.js:7
throw new TypeError('Path must be a string. Received ' + inspect(path));
^
TypeError: Path must be a string. Received undefined
at assertPath (path.js:7:11)
at Object.join (path.js:1211:7)
at exports.replaceLocation (/Applications/MAMP/htdocs/Jober/node_modules/gulp-ruby-sass/lib/utils.js:32:14)
at /Applications/MAMP/htdocs/Jober/node_modules/gulp-ruby-sass/index.js:179:13
at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:416:3)
my gulpfile.js is:
var gulp = require ('gulp'),
logger = require ('gulp-util'),
concat = require ('gulp-concat'),
minifyCSS = require ('gulp-minify-css'),
compileSass = require ('gulp-ruby-sass');
var scss_sources,
input_address,
output_address;
// Input and Output Address
input_address = 'asstes/src/';
output_address = 'asstes/dist/';
// Style Sources
scss_sources = [
'node_modules/foundation-sites/scss',
input_address + 'style/style.scss'];
gulp.task('styles', function(){
return compileSass(scss_sources, { style: 'expanded' })
.pipe(autoprefixer({
browsers: ['last 2 versions', 'ie >= 9', 'and_chr >= 2.3'],
cascade: false
}))
.pipe(minifyCSS())
.on('error', logger.log)
.pipe(gulp.dest(output_address + 'style'));
});
gulp.task('watch', function(){
gulp.watch(input_address + 'style/pages/*.scss', ['styles']),
});
gulp.task('default', ['styles' , 'watch']);
my style.scss is:
//Modules
#import 'foundation';
//Pages
#import 'pages/index';
and my folders structure is:
PROJECT FOLDER
|
|_assets
| |_dist
| | |_img
| | |_js
| | |_style
| |
| |_src
| |_img
| |_js
| |_style
|
|_node_modules
| |_foundation-site
|
|_gulpfile.js
I'd used gulp-compass before gulp-ruby-sass but, had popular error: Individual stylesheets must be in the sass directory, therefore change plugin to gulp-ruby-sass.
How can I fix it?
It might be that the string concatenation is not working correctly in the scss_sources.
Try changing scss_sources to:
scss_sources = [
'node_modules/foundation-sites/scss',
'asstes/src/style/style.scss'
];
And see does that work, if so it's the concatenation.

Producing two separate jars for sources and resources with package in SBT?

Because of the large size of some resource files, I'd like sbt package to create 2 jar files at the same time, e.g. project-0.0.1.jar for the classes and project-0.0.1-res.jar for the resources.
Is this doable?
[SOLUTION] based on the answer below thanks to #gilad-hoch
1) unmanagedResources in Compile := Seq()
Now it's just classes in the default jar.
2)
val packageRes = taskKey[File]("Produces a jar containing only the resources folder")
packageRes := {
val jarFile = new File("target/scala-2.10/" + name.value + "_" + "2.10" + "-" + version.value + "-res.jar")
sbt.IO.jar(files2TupleRec("", file("src/main/resources")), jarFile, new java.util.jar.Manifest)
jarFile
}
def files2TupleRec(pathPrefix: String, dir: File): Seq[Tuple2[File, String]] = {
sbt.IO.listFiles(dir) flatMap {
f => {
if (f.isFile) Seq((f, s"${pathPrefix}${f.getName}"))
else files2TupleRec(s"${pathPrefix}${f.getName}/", f)
}
}
}
(packageBin in Compile) <<= (packageBin in Compile) dependsOn (packageRes)
Now when I do "sbt package", both the default jar and a resource jar are produced at the same time.
to not include the resources in the main jar, you could simply add the following line:
unmanagedResources in Compile := Seq()
to add another jar, you could define a new task. it would generally be something like that:
use sbt.IO jar method to create the jar.
you could use something like:
def files2TupleRec(pathPrefix: String, dir: File): Seq[Tuple2[File,String]] = {
sbt.IO.listFiles(dir) flatMap {
f => {
if(f.isFile) Seq((f,s"${pathPrefix}${f.getName}"))
else files2TupleRec(s"${pathPrefix}${f.getName}/",f)
}
}
}
files2TupleRec("",file("path/to/resources/dir")) //usually src/main/resources
or use the built-in methods from Path to create the sources: Traversable[(File, String)] required by the jar method.
that's basically the whole deal...

Resources