npm install 不创建 dist 文件夹

新手上路,请多包涵

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

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

我在这里错过了一步还是我理解不正确?因为我希望该命令从 --- 文件夹中的文件中创建一个 dist/ src/ 夹?

咕噜声文件:

 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']);
};

包.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"
  }
}

原文由 IIIIIIIIIIIIIIIIIIIIII 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 487
2 个回答

您缺少运行 grunt 默认任务

你应该运行:

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

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

原文由 eblin 发布,翻译遵循 CC BY-SA 3.0 许可协议

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

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

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

原文由 bvdb 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题