Babel Minify在生产中创建空文件

时间:2019-05-29 15:13:15

标签: javascript webpack babel

我正在玩babel和webpack。我尝试转换我的js脚本,但在生产时输出了一个空的js文件。

我尝试了babeljs.io页面,当我缩小页面时出现错误 https://babeljs.io/repl#?babili=true&browsers=IE%20%3E%3D%2011&build=&builtIns=false&spec=false&loose=false&code_lz=GYVwdgxgLglg9mABADwBQEpEG8BQjEBOAplCAUsogFSICMADANw4C-QA&debug=false&forceAllTransforms=false&shippedProposals=false&circleciRepo=&evaluate=true&fileSize=true&timeTravel=false&sourceType=module&lineWrap=true&presets=babili%2Cenv&prettier=false&targets=&version=7.4.5&externalPlugins=

还有一个Bug。 https://github.com/babel/website/issues/1868

我该怎么做才能使用webpack和babel转换并缩小js文件

我尝试了不同版本的babel,不同的预设和设置

这是我的package.json

{
  "name": "cookie",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "build:dev": "webpack -d --profile --progress",
    "build": "webpack --mode=production -p",
    "watch": "webpack --watch",
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@babel/cli": "^7.4.4",
    "@babel/core": "^7.4.5",
    "@babel/preset-env": "^7.4.2",
...
    "webpack": "^4.32.2",
    "webpack-cli": "^3.3.2"
  },
  "dependencies": {}
}

(我正在使用.babelrc中的预设环境)

webpack.config.js

const path = require('path');
module.exports = {
  entry: {
    'bundle.min.css': [
      path.resolve(__dirname, 'src/scss/index.scss'),
    ],
    'bundle.js': [
      path.resolve(__dirname, 'src/js/index.js')
    ]
  },
  output: {
    filename: '[name]',
    path: path.resolve(__dirname, 'dist'),
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        use: 'babel-loader',
        exclude: /node_modules/
      }
    ],
  }
};

如果我运行npm run build:dev脚本,则将编译我的文件。 但是在npm run build上,我的dist文件夹中得到一个空的js文件,没有错误消息。 看来Babel Minfier正在破坏文件。

我希望转译并缩小的js文件。

0 个答案:

没有答案
相关问题