Browserify or Babel inserting special character

时间:2015-06-30 13:47:34

标签: reactjs gulp browserify babeljs

I'm using browserify with babel as a transform. A special character (Â) is being added to my own script, as well as other modules in various places. This build/compile is on a Windows machine.

NPM Build Script

browserify -s appClient source/app-client.js -t babelify > build/app-client.js

Input Snippet:

return (
  <p>Hello,&nbsp;<span
      onClick = { () => setMode('edit') }
      style = { styles.displayMode }
      >{ word }!
      </span>
      <input
        onKeyUp = { onKeyUp}
        placeholder = { word }
        ref = 'wordInput'
        style = { styles.editMode }
      />
  </p>)

}

Output:

Hello, world!

What's odd is that  gets generated by &nbsp;, and not &nbsp. So maybe I'm not looking at the build process.

I can manually edit the JavaScript file to remove the special character.

1 个答案:

答案 0 :(得分:3)

在IDE中将受影响文件的编码类型设置为utf-8

然后添加......

<meta charset="UTF-8"> 

...到你的html页面。这应该解决所有错误字符的问题。

  

注意:如果内容未保存为meta,则不需要unicode标记。它只会使页面将所有内容解释为utf-8unicode)。