Babel --out-file in a child folder - compilation

I am trying to compile jsx with babel. I can do it but I want to set --out-file in a child dir. There is I want to do:
website
src
file_will_be_compiled.js
file_was_compiled.js
package.json
The script I am running on the shell :
babel --watch src/file_will_be_compiled.js --out-dir src --plugins #babel/plugin-transform-react-jsx

Ok, I solved. The new shell code:
babel --watch src/file_will_be_compiled.js --out-file src/compiled_file.js --presets preset-react

Related

--watch command is obsolete?

--watch command
no longer works for scss. What's the equivalent
Bought a new pc and can't get newest version of sass to compile
This is going to be marked as duplicate but please point me in right direction
No, I don't think so.
As the official SASS website explained, you can use --watch command like this:
sass --watch <input file or folder>:<output file or folder>
To install sass on your new machine you can use this command:
npm install -g sass

Compile everything in scss folder to style.css via terminal

I have the following folder structure:
theme
scss
hero.scss
header.scss
style.css
I'm trying to compile everything in the scss into style.css. I've followed this tutorial, but I believe this approach will compile several different css files (whereas I only want the one).
Even with the above approach, whenever I run npm run scss, it doesn't compile anything?
This is my package.json file:
{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"scss": "node-sass --watch scss -o css"
},
"author": "",
"license": "ISC"
}
When running npm run watch-css or npm run scss, nothing happens? Where am I going wrong?
Your input directory and output directories are incorrect for the node-sass command. Assuming you've the following directory structure:
theme
scss
hero.scss
header.scss
style.css
package.json
You've created an npm run script called scss which is leveraging the node-sass library to compile your SASS into CSS. If you want to execute this run script you should type the following into your command line: npm run scss
Now when you type this command you're actually running the node-sass library with these parameters:
node-sass --watch scss -o css
In this command, you've specified that your Sass files exist in your scss directory and node-sass should look in this directory to compile your Sass into CSS. Once this is done your newly generated CSS is moved into your css directory.
However, the first issue is you don't have css directory for node-sass to put these compiled Sass files into. You can remedy this by either creating a css folder within your theme directory or modifying your output location parameter appropriately.
The other issue is your input directory location is incorrect for your Sass files. You've specified it as the scss directory however this location is relative to your package.json file and there is theme folder in-between said files. This should probably be changed to the following: theme/scss.
So in order to get it this command to work appropriately you need to change your input and output directories to point to the correct directory structure of your application.
Perhaps you could try changing your run script to the following and seeing if this helps (Assuming you don't want to create a css folder):
"scss": "node-sass --watch theme/scss -o theme"
then re-run your npm script like so:
npm run scss
Hopefully that helps!

SASS watch multiple .scss in sub-dir of directory select?

I start a project where I have this : Site
And I like to do something like this :
: sass --watch Component/*.scss:css/style.css
When a save is done in any .scss in Component/, it run "watch", is that possible ?
Thk for looking;
If you are using the sass gem you have the following options:
update will compile a single file or multiple files in a folder (depending on the parameters). watch will do the same and after the initial compilation is completed it will watch the file or all the files in the specified folder, so everytime a change is detected on any of the target files, sass will compile the changed ones.
Both options have the same command line sintax:
sass --watch input/folder:output/folder
sass --watch input.scss:output.css
So, to compile all the files in a folder:
sass --update path/to/input/folder:path/to/output/folder
And to compile and then watch a folder:
sass --watch path/to/input/folder:path/to/output/folder
Just run sass --help for a complete list of options.
Hope it helps!
Supposing, you use gulp to run the tasks.
var sass = require('gulp-sass'); //after npm i gulp-sass --save-dev in your terminal.
gulp.task('watch', function(){
gulp.watch('./app/sass/*.scss', ['sass']); //place the correct location of your scss folder
});
And include watch in 'build' task
// *** build task *** //
gulp.task('build', function() {
runSequence(
['watch']
);
});
Hope this helps!

How to run sass watch with just gulp

how can I run pure gulp sass? I'd like to have installed just node modules and gulp and run some port of sass using watch. I'd like to avoid ruby version of sass. Is it possible? I run windows but i'd like the solution to be cross-platfom, which shouldn't be problem for node.
Thanks.
if you are looking for the seemlest and lightest solution without the needs of writing any gulp scripts, you can simply use node-sass and npm scripts.
For example in your package.json :
{
"scripts": {
"sass": "node-sass -w ./path/to/entry-point.scss ./path/to/build.css",
},
"devDependencies": {
"node-sass": "^4.5.3"
}
}
The -w is for the watch feature based on your entry parameter.
Then, simply :
$ npm run sass
// or
$ yarn sass
Check the CLI documentation for more informations.
I hope, it will help !

Sass: Watch multiple input-files for one output-file [duplicate]

How could I trace changes in whole directory containing many sass files ? I'm using the following command to watch changes in sass
file:
sass --watch style.scss:style.css
But how to watch changes in whole directory/folder containing many sass files.
Simply use the command sass --watch <input folder>:<output folder>, like this:
$ ls -l
css/ sass/
$ sass --watch sass:css
Where <input folder> contains the Sass files and <output folder> that hosts the generated CSS files.
Expanding the answer by piouPiouM a little:
Output files will be created with the same names as input files except ending with .css.
<input folder> and <output folder> can be the same.
Both folders can be the present working directory, so the following is valid:
$ sass --watch .:.
Go to you terminal and get to you folder then wrote:
sass --watch .
this will watch all sass files and convert to css files with the same name.
also you can do it in this way:
sass --watch ~/user/youUser/workspace/project/styles/
I hope this can help you.
I ended up doing this without using Grunt or Sass-watch:
npm install -g watch
watch "sass assets/app.scss assets/dist/app.css" assets/css
if you are in your current folder then do the following to watch it.
F:\sass tutorial>sass --watch ./:./
Just in case someone faces with this issue in 2018:
sass Website refers to Ruby Sass that is been deprecated.
and as now (May 2018) if you install dart sass via npm , it does not support --watch command
What to do:
you need to install node-sass globaly , like:
npm install node-sass -g
and then restart the command line , then use this code:
node-sass --watch scss/styles.scss css/styles.css
to compile your scass files to css.
basically node-sass supports --watch command and we use that to compile our scss codes to regular css files.
and just in case you get an error like this at the first time that you save your .scss file:
{
"status": 3,
"message": "File to read not found or unreadable: yourdirectory/scss/styles.scss",
"formatted": "Internal Error: File to read not found or unreadable: yourdirectory/scss/styles.scss\n"
}
what you need to do is save it again, it will work correctly!
According to the information, you can use the next command line:
sass --watch .
Source: http://sassbreak.com/watch-your-sass/#what-does---watch-do
You can create one sass file which includes the rest of the files, and then just watch this file.
Alternately, look into Grunt and the very good grunt-contrib-compass plugin
You can set sass to watch all the .scss files(for my case i got several .scss files in src/static folder) to compile, but before install it globally:
npm i -g sass
then go to the project folder and type command below:
sass --watch $(pwd)/src/static
also you can wrap it in npm script in package.json, like
"scripts": {
"sass:watch": "sass --watch $(pwd)/src/static"
}
and run it by this command:
npm run sass:watch

Resources