从Gulp切换到Webpack的错误

时间:2019-04-22 15:26:54

标签: javascript webpack gulp babeljs

我想从gulp切换到webpack,但是我遇到了一些我无法解决的问题。

首先,我要创建一个编辑器,然后用gulp实例化编辑器:

new RSMDE({
    variables: vars,
    element: document.getElementById('mdediror'),
    initialValue:
    '# EasyMDE \n Go ahead, play around with the editor! Be sure to check out **bold**, *italic* and ~~strikethrough~~ styling, [links](https://google.com) and all the other features. You can type the Markdown syntax, use the toolbar, or use shortcuts like `ctrl-b` or `cmd-b`.',
    });

在我的编辑器文件中,我曾经有这个:

// Importing libraries here.

function RSMDE(options) {
   // Handle options parameter
    options = options || {};

    // Used later to refer to it"s parent
    options.parent = this;

    var autoDownload = true;
    // Editor code goes here
    ....
}
module.exports = RSMDE;

但是现在我想切换到webpack,但是在编译时遇到了一个问题。我收到此错误:  Uncaught TypeError: Cannot assign to read only property 'exports' of object '#<Object>'

我已将module.exports = RSMDE;更改为export default RSMDE的问题消失了,但是当我将function RSMDE(options){}更改为class RSMDE时,代码将如下所示:

// Importing libraries here.

class RSMDE {
   // Handle options parameter
    options = options || {};

    // Used later to refer to it"s parent
    options.parent = this;

    var autoDownload = true;
    // Editor code goes here
    ....
}
export default RSMDE;

但是现在我得到了另一个错误:

  • Unexpected token =>此错误位于options.parent
  • 现在我也不知道如何将参数从HTML传递给类

0 个答案:

没有答案