前言:
—-设置代理:
npm config set registry https://registry.npmjs.org/
—-npm版本号:

C:\Users\User>npm version
{ npm: '3.8.9',
  ares: '1.10.1-DEV',
  http_parser: '2.7.0',
  icu: '57.1',
  modules: '48',
  node: '6.2.0',
  openssl: '1.0.2h',
  uv: '1.9.1',
  v8: '5.0.71.47',
  zlib: '1.2.8' }

安装jspm
1、安装全局jspm,执行命令: npm install jspm -g
2、安装本地jspm,执行命令: npm install jspm –save-dev
3、执行命令:jspm init,初始化jspm,具体过程如下:

C:\Users\User\Desktop\jspm>jspm init
  Package.json file does not exist, create it? [yes]:
  Would you like jspm to prefix the jspm package.json properties under jspm? [yes]:
  Enter server baseURL (public folder path) [./]:
  Enter jspm packages folder [.\jspm_packages]:
  Enter config file path [.\config.js]:
  Configuration file config.js doesn't exist, create it? [yes]:
  Enter client baseURL (public folder URL) [/]:./
  Do you wish to use a transpiler? [yes]:
  Which ES6 transpiler would you like to use, Babel, TypeScript or Traceur? [babel]:
  ok   Verified package.json at package.json
     Verified config file at config.js
     Looking up loader files...
       system.src.js
       system.js
       system-csp-production.src.js
       system-csp-production.js
       system.js.map
       system-polyfills.js
       system-polyfills.js.map
       system-polyfills.src.js
       system-csp-production.js.map

     Using loader versions:
       systemjs@0.19.27
     Looking up npm:babel-core
     Looking up npm:babel-runtime
     Looking up npm:core-js
     Updating registry cache...
     Looking up github:jspm/nodelibs-process
     Looking up github:jspm/nodelibs-path
  ok   Installed babel as npm:babel-core@^5.8.24 (5.8.38)
     Looking up github:systemjs/plugin-json
     Looking up npm:process

  warn Timed out on locate for github:jspm/nodelibs-fs, retrying (1).
     To increase the timeout run jspm config registries.github.timeouts.lookup 120

  warn Timed out on lookup for github:jspm/nodelibs-path, retrying (1).
     To increase the timeout run jspm config registries.github.timeouts.lookup 120

  warn Timed out on lookup for github:systemjs/plugin-json, retrying (1).
     To increase the timeout run jspm config registries.github.timeouts.lookup 120
  ok   Installed github:jspm/nodelibs-process@^0.1.0 (0.1.2)
  ok   Installed npm:process@^0.11.0 (0.11.3)
     Looking up github:jspm/nodelibs-fs
  ok   Installed github:systemjs/plugin-json@^0.1.0 (0.1.2)
     Looking up github:jspm/nodelibs-assert
  ok   Installed github:jspm/nodelibs-fs@^0.1.0 (0.1.2)
     Looking up npm:assert
  ok   Installed github:jspm/nodelibs-assert@^0.1.0 (0.1.0)
     Looking up npm:buffer-shims
     Looking up npm:util
  ok   Installed npm:assert@^1.3.0 (1.4.0)
  ok   Installed npm:buffer-shims@1.0.0 (1.0.0)
     Looking up npm:inherits
  ok   Installed npm:util@0.10.3 (0.10.3)
  ok   Installed npm:inherits@2.0.1 (2.0.1)
     Looking up npm:path-browserify
  ok   Installed github:jspm/nodelibs-path@^0.1.0 (0.1.0)
     Looking up github:jspm/nodelibs-util
  ok   Installed npm:path-browserify@0.0.0 (0.0.0)
     Looking up github:jspm/nodelibs-buffer
     Looking up npm:buffer
  ok   Installed github:jspm/nodelibs-buffer@^0.1.0 (0.1.0)
     Looking up npm:base64-js
     Looking up npm:ieee754
     Looking up npm:isarray
  ok   Installed npm:buffer@^3.0.1 (3.6.0)
  ok   Installed npm:base64-js@0.0.8 (0.0.8)
  ok   Installed npm:ieee754@^1.1.4 (1.1.6)
  ok   Installed npm:isarray@^1.0.0 (1.0.0)
     Looking up github:jspm/nodelibs-child_process
  ok   Installed github:jspm/nodelibs-util@^0.1.0 (0.1.0)
  ok   Installed github:jspm/nodelibs-child_process@^0.1.0 (0.1.0)
  ok   Installed core-js as npm:core-js@^1.1.4 (1.2.6)
  ok   Installed babel-runtime as npm:babel-runtime@^5.8.24 (5.8.38)
  ok   Loader files downloaded successfully

注意:
public folder URL 设置为 ./
此时,目录C:\Users\User\Desktop\jspm下的文件就可以使用了,可支持ECMAScrpit 6的语法。
具体用法如下:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>index</title>
<script type="text/javascript" src="jspm_packages/system.js"></script>
<script type="text/javascript" src="config.js"></script>
<script type="text/javascript">
System.import("app");
</script>
</head>
<body>
</body>
</html>

还需要注意:
采用ECMAScrpit 6编码的js文件,必须以System.import(“app”);的形式应用,否则因部分ECMAScrpit 6语法得不到浏览器支持而报错。

转载:http://lib.csdn.net/article/nodejs/51017

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐