首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Webpack与babel-loader属性类型

Webpack与babel-loader属性类型
EN

Stack Overflow用户
提问于 2016-07-10 12:07:41
回答 1查看 328关注 0票数 0

我正在尝试使用Webpack将我的节点类型记录应用程序(使用exprees服务器)迁移到ES2015。首先,我想使用属性类型。我创建的,比我需要的巴贝尔-装载机和埃林特。因此,我安装了这个软件包,并将其实现到我的快递应用程序中。

这是我的webpack.config.js

代码语言:javascript
复制
const webpack = require('webpack');
const WebpackErrorNotificationPlugin = require("webpack-error-notification");
module.exports = 
{
    entry: './src/test/test.js',
    target: 'node',
    debug: true,
    output: {
        path: './bin',
        filename: 'test.bundle.js',
    },
    module: {
        preLoaders: [{
            test: /\.js?$/,
            loaders: ['eslint'],
            exclude: /node_modules/
        }],
        loaders: [{
            test: /\.js?$/,
            exclude: /node_modules/,
            loader: 'babel',
        }]
    },
    eslint: {
        failOnWarning: false,
        failOnError: true
    },
    plugins: [
        new webpack.optimize.UglifyJsPlugin({
            compress: {
                warnings: false,
            },
            output: {
                comments: false,
            },
        }),
        new WebpackErrorNotificationPlugin()
    ]
}

.eslintrc

代码语言:javascript
复制
{
  "parser": "babel-eslint",
  "parserOptions": {
    "sourceType": "module",
    "allowImportExportEverywhere": false
  }
}

和错误码之一:

代码语言:javascript
复制
export class CmsUserModel {
    /**
     * (description)
     * 
     * @type {String}
     */
    template: string;

    /**
     * (description)
     * 
     * @type {string}
     */
    pages: string[];

    constructor() {
        this.template = "";
        this.pages = new Array<string>();
    }

       public static ToModel(model: ICmsUserModel) {
         return <CmsUserModel>{
             template : model.template,
             pages : model.pages
         };       
     }
}

有两个问题。第一种是,babal-eslint错误处理不太指定.例如:

代码语言:javascript
复制
ERROR in ./src/models/cmsUserModel.js

/Users/petrtomasek/Projects/cms/src/models/cmsUserModel.js
  44:40  error  Parsing error: Unexpected token

✖ 1 problem (1 error, 0 warnings)


ERROR in ./src/models/cmsUserModel.js
Module build failed: Error: Module failed because of a eslint error.

/Users/petrtomasek/Projects/cms/src/models/cmsUserModel.js
  44:40  error  Parsing error: Unexpected token

✖ 1 problem (1 error, 0 warnings)

这很好,但我想看到标准错误处理,如默认webpack和巴贝尔装载机打印当前错误行,如果可能的话。

第二个错误是,我仍然不能使用属性类型,例如:template: string

请问出什么事了?谢谢你的时间!

EN

回答 1

Stack Overflow用户

发布于 2016-07-10 17:50:13

我认为你应该尝试以下步骤,

代码语言:javascript
复制
1. npm install --save-dev babel-preset-es2015
2. Add query: { presets: ['es2015'] } to your webpack config with the babel loader.

loaders: [{
            test: /\.js?$/,
            exclude: /node_modules/,
            loader: 'babel',
            query: { presets: ['es2015'] }
        }]
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38291699

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档