I have a master.scss with many imports from other .scss files. If I change a * .scss file master.css is generated automatically.
I use only the NPM, no Gulp or Grunt! This should remain so.
My current build script:
"scripts": {
"watch-sass": "sass --watch src/scss/master.scss:dist/css/master.css"
}
That's nice but takes a long time to compile!
Now I'm trying to use node-sass. It should compile very fast.
Unfortunately, I do not understand it completely ...
node-sass is installed, via npm install node-sass
Where do I use the following (from docs)?
var sass = require('node-sass');
sass.render({
file: scss_filename,
[, options..]
}, function(err, result) { /*...*/ });
// OR
var result = sass.renderSync({
data: scss_content
[, options..]
});
This is not so in the package.json, right?
Here's a tutorial, what I've read: Using NPM as a Task Runner
The script is good. How can I use it?
"scripts": {
"sass": "node-sass sass/ -o build/css/"
}
This will compile all of the sass files (that don't start with an underscore) to the build/css/ directory.
I hope for your help!
Maybe this covers your question:
How to compile or convert sass / scss to css with node-sass (no Ruby)?
If it's an option for you I would recommend using grunt, it will make things a lot simpler and faster. This grunt plugin is probably the best option: https://www.npmjs.com/package/grunt-contrib-sass
// UPDATE
I followed the tutorial you sent and it's very straightforward.
You create a file in your root folder called "package.json" containing the following:
{
"watches": {
"sass": "sass/**"
},
"scripts": {
"sass": "node-sass sass/ -o build/css/",
"dev": "rerun-script"
}
}
You then open the command line in the root folder and run the following:
npm install --save-dev node-sass
The above installs node-sass
You then run:
npm install --save-dev rerun-script
The above creates a watch task so you don't have to rerun node-sass everytime you make changes
And last you run
npm run dev
Done!
Documentation.
If you want automatically compile files then you need to put the flag -w
node-sass -w -r assets/src/scss/ -o assets/dist/css/
My package.json
{
"name": "my-project",
"version": "1.0.0",
"scripts": {
"build:js": "watchify assets/src/js/main_1.js -o 'exorcist assets/dist/js/main_1.js.map > assets/dist/js/main_1.js' -d -t [babelify --presets [latest]]",
"build:scss": "node-sass -w -r assets/src/scss/ -o assets/dist/css/",
"build": "npm run build:scss & npm run build:js"
},
"devDependencies": {
"babel-cli": "^6.0.0",
"babel-preset-latest": "^6.16.0",
"babelify": "^7.3.0",
"browserify": "^13.1.1",
"exorcist": "^0.4.0",
"node-sass": "^4.5.0",
"watchify": "^3.7.0"
},
"browserify": {
"transform": [
"babelify"
]
}
}
Actual version of package.json: https://gist.github.com/artamonovdev/5f24aaca504e4d1b299bba0413f0a57d
The watch mode in node-sass doesn't run the first compilation. It supposes that you have already ran node-sass.
Personally, I use something like this:
{
"scripts": {
"sass": "node-sass -o /path/to/dist /path/to/src",
"sass:watch": "npm run sass && npm run sass -- --watch --recursive"
}
}
And you can use it like this: npm run sass:watch
Related
I am on Windows 10 with Node v14.15.4 and npm 6.14.10
I have executed below command successfully
npm install -D tailwindcss#latest postcss#latest autoprefixer#latest postcss-cli cssnano onchange
This has no effect :
"tw:prod": "SET NODE_ENV=production postcss build ./src/css/tailwind.css -o ./public/css/tailwind.css",
If I remove SET NODE_ENV=production it works but public/css/tailwind.css is still 3.2MB.
"tw:prod": "postcss build ./src/css/tailwind.css -o ./public/css/tailwind.css",
Why isn't it purging ?
You probably have to create a configuration file and provide the paths of your templates in the purge option.
npx tailwindcss init
// tailwind.config.js
module.exports = {
purge: [
'./src/**/*.html',
'./src/**/*.vue',
'./src/**/*.jsx',
],
theme: {},
variants: {},
plugins: [],
}
I have been getting this error for days now and I am not sure how to fix it.
When I run the "dev" package in Node Task Runner Explorer it gives this error.
It seems to be something to do with different versions of node and webpack not getting along. the error message, and my packages.json file are below, as is the link to the article I am working through.
setting-up-a-react-environment-for-aspnet-mvc-44la
Error Message
C:\DevFolder\MyApplication> cmd.exe /c npm run dev --color=always
asp.net#1.0.0 dev C:\DevFolder\MyApplication
webpack --mode development --watch C:\DevFolder\MyApplication\node_modules\webpack\bin\webpack.js:90 let
notify = ^^^ SyntaxError: Block-scoped declarations (let, const,
function, class) not yet supported outside strict mode
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:374:25)
at Object.Module._extensions..js (module.js:405:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Function.Module.runMain (module.js:430:10)
at startup (node.js:141:18)
at node.js:980:3 npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! asp.net#1.0.0 dev: `webpack --mode development --watch` npm ERR!
Exit status 1 npm ERR! npm ERR! Failed at the asp.net#1.0.0 dev
script. npm ERR! This is probably not a problem with npm. There is
likely additional logging output above.
package.json
{
"version": "1.0.0",
"name": "asp.net",
"private": true,
"scripts": {
"build": "webpack",
"dev": "webpack --mode development --watch"
},
"devDependencies": {
"#babel/cli": "^7.7.5",
"#babel/core": "^7.7.5",
"#babel/plugin-proposal-class-properties": "^7.7.4",
"#babel/preset-env": "^7.7.6",
"#babel/preset-react": "^7.7.4",
"babel-loader": "^8.0.6",
"browser-sync": "^2.26.7",
"browser-sync-webpack-plugin": "^2.2.2",
"webpack": "^4.41.2",
"webpack-cli": "^3.3.10",
"webpack-notifier": "^1.8.0"
},
"dependencies": {
"react": "^16.12.0",
"react-dom": "^16.12.0",
"npm": "6.12.1",
"node" : "5.3.0"
}
}
Webpack Config
"use strict";
var path = require("path");
var WebpackNotifierPlugin = require("webpack-notifier");
var BrowserSyncPlugin = require("browser-sync-webpack-plugin");
module.exports = {
entry: "./Scripts/ApplicationReact/ApplicationReact.js",
output: {
path: path.resolve(__dirname, "./Scripts/"),
filename: "bundle.js"
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader"
}
}
]
},
devtool: "inline-source-map",
plugins: [new WebpackNotifierPlugin(), new BrowserSyncPlugin()]
};
Summary
Don't install the Node.js nuget package, it breaks your project and it will remain broken after you have removed it. Just let the general installation of node do the work.
Detail
When in any other directory, if I did "node -v" in the command line and it would return version 12.13.1
When in my project folder if I did "node -v" it would return 5.3.0
When I removed the Node.js nuget package I thought it would default to the system version but instead it just said "cannot find the file or command specified" (or something along those lines).
I had copied the whole of our software to another folder for the purposes of this exercise. I just branched to another folder and this time the "node -v" was coming back with 12.13.1
I carried on with the exercise and the error did not appear. I am not sure how to fix it once you get into this state.
Better answers?
This isn't a great answer and I won't mark it as the answer. If anyone can provide a plausible explanation for what is going on here, and a way to cure your project from the nuget node lurgy, I will mark it as the answer.
I have node-sass installed and have set the options as in the bottom response on Using node-sass watch option with npm run-script, however, it just doesn't seem to work for me.
This is my package.json file with my latest attempt:
{
"name": "linkup-paints",
"description": "NPM for Linkup Paint Supplies website for 2019",
"version": "1.0.2",
"main": "index.js",
"scripts": {
"start": "run-script-os",
"start:win32": "browser-sync start --server --files '**/*.css, **/*.html, **/*.js, !node_modules/**/*, !styles/**/*' --directory --port 7777 --browser \"C:\\Program Files\\Firefox Developer Edition\\firefox.exe\"",
"build-sass": "node-sass styles/main.scss css/main.css",
"watch-sass": "node-sass -w styles/main.scss css/main.css"
},
"author": "dpDesignz",
"license": "ISC",
"devDependencies": {
"browser-sync": "^2.26.3",
"run-script-os": "^1.0.3",
"node-sass": "^4.9.4"
}
}
So I've tried:
"build:sass": "node-sass -r --output-style compressed styles/main.scss -o css/main.css",
"watch:sass": "npm run build:sass && npm run build:sass -- -w"
and:
"css": "node-sass styles/main.scss -o css/main.css",
"css:watch": "npm run css && node-sass styles/main.scss -wo css/main.css"
and:
"scss": "node-sass --watch styles/main.scss -o css/main.css"
and (as suggested by sidthesloth):
"build-sass": "node-sass styles/main.scss css/main.css",
"watch-sass": "node-sass -w styles/main.scss css/main.css"
I run npm i, and once that's complete I run npm start. The browser-sync starts, and watches the file changes, but my css/main.css doesn't compile, or update when I change an .scss file.
I've only just started/learnt how to use NPM, so any help would be much appreciated. I've poured over tutorials and answers (including Using node-sass, Watch and Compile Sass in Five Quick Steps, and Using node-sass to compile Sass files in an npm script) for the past 2 hours with no luck.
How can I get my watch and build to work?
Update
So just an update for anyone looking for this in the future, I didn't understand how scripts worked and didn't realise that my scripts weren't being run parallel to each other. I thought npm start trigerred all my scripts to run, I didn't realise that you had to call all of them. My final package.json file is as follows:
{
"name": "linkup-paints",
"version": "1.0.3",
"description": "NPM for Linkup Paint Supplies website for 2019",
"main": "index.js",
"directories": {
"lib": "lib"
},
"scripts": {
"start": "npm-run-all --parallel browser-sync build-sass watch-sass",
"browser-sync": "browser-sync start --server --files '**/*.css, **/*.html, **/*.js, !node_modules/**/*' -w --directory --port 7777 --browser \"C:\\Program Files\\Firefox Developer Edition\\firefox.exe\"",
"build-sass": "node-sass styles/main.scss css/main.css",
"watch-sass": "node-sass -w styles/main.scss css/main.css"
},
"keywords": [
"linkup",
"2019"
],
"repository": {},
"author": "dpDesignz",
"license": "ISC",
"devDependencies": {
"npm-run-all": "^4.1.3",
"browser-sync": "^2.26.3",
"node-sass": "^4.9.4"
},
"bugs": {
"url": "http://support.dpdesignz.co"
},
"homepage": "http://www.dpdesignz.co"
}
I ended up adding the npm-run-all script and changing my start args to npm-run-all --parallel browser-sync build-sass watch-sass as I don't need cross-os compatability with the old run-script-os args I had previously. I also put the -w (--watch) arg in the browser-sync line to cause the created .css files to trigger a sync as the build actually replaces the .css file, not "changes" it as required by browser-sync by default.
These are the two NPM scripts that I use to either build or watch SCSS files using node-sass:
"build-sass": "node-sass src/public/css/main.scss dist/public/css/main.css"
"watch-sass": "node-sass -w src/public/css/main.scss dist/public/css/main.css"
Hope this works for you
Whenever i click submit on the form that should send a notification to my listener, i get a message that says Cannot find module 'paypal-ipn'.
When i track the error, it takes me to a line of code ib the IPN listener var ipn = Meteor.npmRequire('paypal-ipn');
I added papal-ipn in my package.json here
{
"name": "application-name",
"version": "1.0.0",
"paypal-ipn" : "3.0.0",
"redis": "0.8.2",
"github": "0.1.8",
"body-parser": "1.14.1",
"description": "Application description.",
"scripts": {
"start": "meteor --settings settings-development.json",
"staging": "modulus env set METEOR_SETTINGS \"$(cat settings-development.json)\" -p 'Staging' && modulus deploy -f -p 'Staging'",
"production": "modulus env set METEOR_SETTINGS \"$(cat settings-production.json)\" -p 'Production' && modulus deploy -f -p 'Production'"
}
}
What is the mistake am doing? help PLEASE
ok try removing what you added to the package.json Run npm install --save paypal-ipn and that will add the required info to the package.json automatically for you.
My goal is the be able to build my project to two separate build folders, each with its' own Grunt tasks.
I noticed the grunt-cli has the --gruntfile option which allows you to specify another Gruntfile to use. So far, I have a Gruntfile.js working perfectly (near stock from Yeoman). Also, I have another Gruntfile2.js sitting alongside.
Gruntfile.js
var yeomanConfig = {
app: 'app',
dist: '../www_browser'
};
Gruntfile2.js
var yeomanConfig = {
app: 'app',
dist: '../www'
};
grunt build is meant to run Gruntfile.js, and does so perfectly.
grunt build --gruntfile Gruntfile2.js is meant to run Gruntfile2.js, and does so with some hiccups. (supposed to build to ../www folder NOT ../www_browser folder)
The --gruntfile directive builds to the proper folder for almost every task except grunt-usemin and gunt-contrib-htmlmin. I know this because of this output to the console here:
Running "usemin:css" (usemin) task
Processing as CSS - ../www_browser/styles/22f60055.main.css
Running "concurrent:dist" (concurrent) task
Running "htmlmin:dist" (htmlmin) task
File ../www_browser/404.html created.
File ../www_browser/index.html created.
You'll notice the ../www_browser, here in console output. Every other task runs in the expected ../www folder.
Is this a usemin cache thing? Grunt cache thing? Or do some tasks simply run from the default Gruntfile.js regardless of the --gruntfile Gruntfile2.js directive?
I have given up on trying to do multiple targets from a single Gruntfile for now. There are too many dependencies in Yeoman's Gruntfile.js that don't yet support multiple build targets, and I spent 12 hours to no avail with that approach.
Version Info
$: grunt --version
grunt-cli v0.1.9
grunt v0.4.1
$: npm --version
1.2.25
$: yo --version
1.0.3
package.json
{
"name": "myapp",
"version": "0.0.0",
"dependencies": {},
"devDependencies": {
"grunt": "~0.4.1",
"grunt-contrib-copy": "~0.4.1",
"grunt-contrib-concat": "~0.1.3",
"grunt-contrib-coffee": "~0.6.5",
"grunt-contrib-uglify": "~0.2.0",
"grunt-contrib-compass": "~0.2.0",
"grunt-contrib-jshint": "~0.4.1",
"grunt-contrib-cssmin": "~0.6.0",
"grunt-contrib-connect": "~0.2.0",
"grunt-contrib-clean": "~0.4.0",
"grunt-contrib-htmlmin": "~0.1.3",
"grunt-bower-requirejs": "~0.4.1",
"grunt-contrib-requirejs": "~0.4.0",
"grunt-contrib-imagemin": "~0.1.3",
"grunt-contrib-watch": "~0.4.0",
"grunt-rev": "~0.1.0",
"grunt-usemin": "~0.1.10",
"grunt-mocha": "~0.3.0",
"grunt-open": "~0.2.0",
"grunt-svgmin": "~0.1.0",
"grunt-concurrent": "~0.1.0",
"matchdep": "~0.1.1",
"connect-livereload": "~0.2.0"
},
"engines": {
"node": ">=0.8.0"
}
}
It looks like you're using an older version of grunt-concurrent, which doesn't seem to be passing the grunt flags through to the child-processes.
See here: https://github.com/sindresorhus/grunt-concurrent/blob/v0.1.0/tasks/concurrent.js#L11
On the current version of the plugin, the flags are passed, see here: https://github.com/sindresorhus/grunt-concurrent/blob/v0.3.1/tasks/concurrent.js#L22
So, I suggest updating your version of grunt-concurrent:
npm install grunt-concurrent#latest --save-dev