npm install 不创建 dist 文件夹

npm install doesnt create dist folder

我正在按照本教程 link 创建一个 grafana 插件。

但是当我将此代码 link 从教程复制到我的测试服务器(没有 dist/ 文件夹)并且 运行 npm install npm 不会创建新的 dist/ 文件夹,而不是创建一个 node_modules 文件夹。

我是不是漏掉了一步,还是理解有误?因为我希望该命令从 src/ 文件夹中的文件中创建一个 dist/ 文件夹?

g运行t 文件:

module.exports = (grunt) => {
  require('load-grunt-tasks')(grunt);

  grunt.loadNpmTasks('grunt-execute');
  grunt.loadNpmTasks('grunt-contrib-clean');

  grunt.initConfig({

    clean: ['dist'],

    copy: {
      src_to_dist: {
        cwd: 'src',
        expand: true,
        src: ['**/*', '!**/*.js', '!**/*.scss'],
        dest: 'dist'
      },
      pluginDef: {
        expand: true,
        src: [ 'plugin.json', 'README.md' ],
        dest: 'dist',
      }
    },

    watch: {
      rebuild_all: {
        files: ['src/**/*', 'plugin.json'],
        tasks: ['default'],
        options: {spawn: false}
      },
    },

    babel: {
      options: {
        sourceMap: true,
        presets: ['es2015'],
        plugins: ['transform-es2015-modules-systemjs', 'transform-es2015-for-of'],
      },
      dist: {
        files: [{
          cwd: 'src',
          expand: true,
          src: ['*.js'],
          dest: 'dist',
          ext: '.js'
        }]
      },
    },

  });

  grunt.registerTask('default', ['clean', 'copy:src_to_dist', 'copy:pluginDef', 'babel']);
};

package.json:

{
  "name": "clock-panel",
  "version": "1.0.0",
  "description": "Clock Panel Plugin for Grafana",
  "main": "src/module.js",
  "scripts": {
    "lint": "eslint --color .",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [
    "clock",
    "grafana",
    "plugin",
    "panel"
  ],
  "author": "Raintank",
  "license": "MIT",
  "devDependencies": {
    "babel": "~6.5.1",
    "babel-eslint": "^6.0.0",
    "babel-plugin-transform-es2015-modules-systemjs": "^6.5.0",
    "babel-preset-es2015": "^6.5.0",
    "eslint": "^2.5.1",
    "eslint-config-airbnb": "^6.2.0",
    "eslint-plugin-import": "^1.4.0",
    "grunt": "~0.4.5",
    "grunt-babel": "~6.0.0",
    "grunt-contrib-clean": "~0.6.0",
    "grunt-contrib-copy": "~0.8.2",
    "grunt-contrib-uglify": "~0.11.0",
    "grunt-contrib-watch": "^0.6.1",
    "grunt-execute": "~0.2.2",
    "grunt-systemjs-builder": "^0.2.5",
    "load-grunt-tasks": "~3.2.0"
  },
  "dependencies": {
    "lodash": "~4.0.0",
    "moment": "^2.12.0"
  }
}

npm install 命令安装您的项目将用作依赖项的包。它将在您的当前目录中创建 node_modules 目录(如果尚不存在),并将包下载到该目录。

您缺少运行宁grunt默认任务

你应该运行:

npm install(安装您的依赖项),然后是 grunt(将 src 文件复制到 dist,如您在 Gruntfile.js copy:src_to_dist 任务中所见)

所以简而言之 运行:$ npm install && grunt

实际上,运行 一个 npm install 也会执行你的 package.jsonprepublish,如果有的话。

根据您的需要,听起来您想这样做:

  "scripts": {
    "build": "grunt",
    "prepublish": "npm run build"
  },