npm-build-boilerplate

授权协议 Readme
开发语言 JavaScript
所属分类 应用工具、 终端/远程登录
软件类型 开源软件
地区 不详
投 递 者 令狐嘉运
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

npm-build-boilerplate

A collection of packages that build a website using npm scripts.

List of packages used

autoprefixer, browser-sync, eslint, imagemin-cli, node-sass, onchange, npm-run-all, postcss-cli, svgo, svg-sprite-generator, uglify-js.

Many, many thanks go out to Keith Cirkel for his post and his useful CLI tools!

Using in your project

  • First, ensure that node.js & npm are both installed. If not, choose your OS and installation method from this page and follow the instructions.
  • Next, use your command line to enter your project directory.
    • If this a new project (without a package.json file), start by running npm init. This will ask a few questions and use your responses to build a basic package.json file. Next, copy the "devDependencies" object into your package.json.
    • If this is an existing project, copy the contents of "devDependencies" into your package.json.
  • Now, copy any tasks you want from the "scripts" object into your package.json "scripts" object.
  • Finally, run npm install to install all of the dependencies into your project.

You're ready to go! Run any task by typing npm run task (where "task" is the name of the task in the "scripts" object). The most useful task for rapid development is watch. It will start a new server, open up a browser and watch for any SCSS or JS changes in the src directory; once it compiles those changes, the browser will automatically inject the changed file(s)!

List of available tasks

clean

rm -f dist/{css/*,js/*,images/*}

Delete existing dist files

autoprefixer

postcss -u autoprefixer -r dist/css/*

Add vendor prefixes to your CSS automatically

scss

node-sass --output-style compressed -o dist/css src/scss

Compile Scss to CSS

lint

eslint src/js

"Lint" your JavaScript to enforce a uniform style and find errors

uglify

mkdir -p dist/js && uglifyjs src/js/*.js -m -o dist/js/app.js && uglifyjs src/js/*.js -m -c -o dist/js/app.min.js

Uglify (minify) a production ready bundle of JavaScript

imagemin

imagemin src/images/* -o dist/images

Compress all types of images

icons

svgo -f src/images/icons && mkdir -p dist/images && svg-sprite-generate -d src/images/icons -o dist/images/icons.svg

Compress separate SVG files and combine them into one SVG "sprite"

serve

browser-sync start --server --files 'dist/css/*.css, dist/js/*.js, **/*.html, !node_modules/**/*.html'

Start a new server and watch for CSS & JS file changes in the dist folder

build:css

run-s scss autoprefixer

Alias to run the scss and autoprefixer tasks. Compiles Scss to CSS & add vendor prefixes

build:js

run-s lint concat uglify

Alias to run the lint, concat and uglify tasks. Lints JS, combines src JS files & uglifies the output

build:images

run-s imagemin icons

Alias to run the imagemin and icons tasks. Compresses images, generates an SVG sprite from a folder of separate SVGs

build

run-s build:*

Alias to run all of the build commands

watch:css

onchange 'src/**/*.scss' -- run-s build:css

Watches for any .scss file in src to change, then runs the build:css task

watch:js

onchange 'src/**/*.js' -- run-s build:js

Watches for any .js file in src to change, then runs the build:js task

watch:images

onchange 'src/images/**/*' -- run-s build:images

Watches for any images in src to change, then runs the build:images task

watch

run-p serve watch:*

Run the following tasks simultaneously: serve, watch:css, watch:js & watch:images. When a .scss or .js file changes in src or an image changes in src/images, the task will compile the changes to dist, and the server will be notified of the change. Any browser connected to the server will then inject the new file from dist

postinstall

run-s build watch

Runs watch after npm install is finished

Need help?

Feel free to create an issue, tweet me, or send me an email. I'd be glad to help where I can!

 相关资料
  • 问题内容: 和之间有什么区别? 我在项目中注意到,有时npm在执行时会开始失败,但是在运行时,它可以正常工作。 如何这两个目标的内部运作,即与不同? 问题答案: 将依赖项安装到您正在处理的节点项目的目录中。您可以调用另一个node.js项目(模块),以将其安装为项目的依赖项。 是的别名,除非您在package.json文件中指定“ build”的作用,否则它什么都不做。它使您可以在将其用于另一个项

  • 问题内容: 我有一个在Docker容器中运行的应用程序。它需要公司私有NPM注册表(Sinopia)中的一些私有模块,访问这些模块需要用户身份验证。Dockerfile是。 我努力了: 1)创造在项目的根的.npmrc文件,这其实没有什么区别和NPM似乎使用ENV变量忽略它2) ,等等,但用户不登录。 本质上,我似乎无法在此过程中对用户进行身份验证。我希望有人可能已经遇到了这个问题(似乎是一个显而

  • 对于一个新模块,我尝试使用,而不使用gulp/Grunt/其他专业构建工具。 我的build.js只是 然而,运行 仅在不打印任何内容的情况下退出,状态为0。 运行: 也执行所有正常操作,但也不运行build.js。 如何让npm运行我的构建脚本? 编辑:即使是简单的bash命令似乎也不起作用,例如 不会生成具有该名称的文件。

  • 问题内容: 对于新模块,我试图在没有gulp / Grunt /其他专用构建工具的情况下使用。 我的build.js很简单 但是,跑步 仅退出而不打印任何内容,状态为0。 运行: 也可以执行所有正常操作,但是也不运行build.js。 如何让npm运行我的构建脚本? 编辑:即使简单的bash命令似乎也不起作用,例如 不使用该名称创建文件。 问题答案: 不幸的是,已经是 内部 命令,如docs中所述

  • 我写了一个lib库,package.json中定义了一些配置 我需要执行build命令把代码编译到dist,再去发布,但是一开始dist是空文件夹,每次执行build命令,都会报错,说没有dist/index.d.ts 我如何设置build的时候不关联这个types字段。

  • 问题内容: 我正在尝试在Ubuntu 18.04上部署可正常运行的Windows 10 Spring-Boot / React应用程序,但是尽管进行了无数次尝试修复,但仍会出现“ react-scripts:Permission denied”错误。希望你们中的一位反应专家可以发现我的错。 我的package.json看起来像这样 我以root用户身份登录,并使用nvm来安装node和lts。我这