19 javascript node.js npm
我有以下目录结构:
我package.json看起来像这样:
{
"name": "personal_site",
"version": "1.0.0",
"description": "My personal website.",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"node-sass": "node-sass --output-style compressed --include-path node_modules/bourbon/app/assets/stylesheets/ --include-path node_modules/bourbon-neat/app/assets/stylesheets/ 'src/scss/styles.scss' 'dist/css/bundle.min.css'",
"html-minifier": "html-minifier --collapse-whitespace --remove-comments --remove-attribute-quotes -o 'dist/index.html' 'src/index.html'",
"imagemin": "imagemin src/images dist/images",
"serve": "http-server ./dist"
},
"author": "Dean Gibson",
"license": "ISC",
"dependencies": {
"bourbon": "^4.2.6",
"bourbon-neat": "^1.7.4",
"normalize-scss": "^4.0.3"
},
"devDependencies": {
"html-minifier": "^1.3.0",
"http-server": "^0.9.0",
"node-sass": "^3.4.2"
}
}
Run Code Online (Sandbox Code Playgroud)
所以,首先,我要运行这些脚本分别例如npm run node-sass或者npm run html-minifier等我会非常想是运行npm serve,这将做到以下几点:
src文件夹中的所有内容,并在文件更改时运行相应的脚本node-sass等.我怎样才能最好地解决这个问题?
Meh*_*hdi 26
您可以使用以下方式查看目录nodemon.
一个解决方案是创建三个监视脚本,每个任务一个:
watch:node-sass,watch:html-minifier,和watch:imagemin.然后有一个中心脚本watch开始三:
{
"name": "personal_site",
"version": "1.0.0",
"description": "My personal website.",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"node-sass": "node-sass --output-style compressed --include-path node_modules/bourbon/app/assets/stylesheets/ --include-path node_modules/bourbon-neat/app/assets/stylesheets/ 'src/scss/styles.scss' 'dist/css/bundle.min.css'",
"html-minifier": "html-minifier --collapse-whitespace --remove-comments --remove-attribute-quotes -o 'dist/index.html' 'src/index.html'",
"imagemin": "imagemin src/images dist/images",
"serve": "http-server ./dist",
"watch:node-sass": "nodemon -e scss -x \"npm run node-sass\"",
"watch:html-minifier": "nodemon -e html -x \"npm run html-minifier\"",
"watch:imagemin": "nodemon --watch src/images -x \"npm run imagemin\"",
"watch": "npm run watch:node-sass & npm run watch:html-minifier & npm run watch:imagemin"
},
"author": "Dean Gibson",
"license": "ISC",
"dependencies": {
"bourbon": "^4.2.6",
"bourbon-neat": "^1.7.4",
"normalize-scss": "^4.0.3"
},
"devDependencies": {
"html-minifier": "^1.3.0",
"http-server": "^0.9.0",
"node-sass": "^3.4.2"
}
}
Run Code Online (Sandbox Code Playgroud)
另请阅读:如何使用npm作为构建工具.
rev*_*elt 18
我建议onchange,看看这个样板.
例如,
"watch:css": "onchange 'src/scss/*.scss' -- npm run build:css",
Run Code Online (Sandbox Code Playgroud)
要么
"watch:js": "onchange 'src/js/*.js' -- npm run build:js",
Run Code Online (Sandbox Code Playgroud)
不需要Grunt或Gulp!
| 归档时间: |
|
| 查看次数: |
27312 次 |
| 最近记录: |