将php编译成js,phpstorm 配置实时编译js文件并且自动更新到服务器

首选我们需要安装babel-cli

npm install –save-dev babel-cli

在根目录下创建一个.babelrc文件

{

"presets": [

"es2015"

]

}

1

2

3

4

5

{

"presets":[

"es2015"

]

}

安装babel的ES6的preset

npm install –save-dev babel-preset-es2015

添加一个File watcher

在Settings > Tools > File Watchers 添加Babel的watcher,记得前面要打对勾选中!

Program的设置为

$ProjectFileDir$\node_modules\.bin\babel.cmd

现在改变js文件的话应该就会默认在根目录底下创建出dist文件夹,转换好的js文件就会出现在里面啦!

如果报错的话可以将Arguments里的dev改成es2015,如下:

$FilePathRelativeToProjectRoot$ –out-dir dist –source-maps –presets es2015

这样是直接编译目录, 我需要编译单个文件:

配置应该是:

$FilePathRelativeToProjectRoot$ –out-file $FileDir$\$FileNameWithoutAllExtensions$.min.$FileExt$ –watch –presets es2015

但是这样的话, 我的最终编译文件也会被监控编译导致死循环,

因此需要这样设置(排除min.js文件)!

3f9bd65922512c031a56dd2a237dcdf9.png

然后就可以了!

编译结果:

"use strict";

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

/**

* Created by PhpStorm.

* User: iyahe@qq.com (天明)

* Date: 2019/11/17

* Time: 22:01

* Description:

*/

var Upload = function () {

function Upload() {

_classCallCheck(this, Upload);

this.init = true;

this.init = true;

}

_createClass(Upload, [{

key: "start",

value: function start() {

window.console.log(123);

window.console.log(456);

window.console.log(78910);

window.console.log("hello");

}

}]);

return Upload;

}();

new Upload().start();

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

"use strict";

var_createClass=function(){functiondefineProperties(target,props){for(vari=0;i

function_classCallCheck(instance,Constructor){if(!(instanceinstanceofConstructor)){thrownewTypeError("Cannot call a class as a function");}}

/**

* Created by PhpStorm.

* User:  iyahe@qq.com (天明)

* Date: 2019/11/17

* Time: 22:01

* Description:

*/

varUpload=function(){

functionUpload(){

_classCallCheck(this,Upload);

this.init=true;

this.init=true;

}

_createClass(Upload,[{

key:"start",

value:functionstart(){

window.console.log(123);

window.console.log(456);

window.console.log(78910);

window.console.log("hello");

}

}]);

returnUpload;

}();

newUpload().start();

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值