Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XTagElement is not defined #200

Open
pws019 opened this issue Apr 26, 2018 · 3 comments
Open

XTagElement is not defined #200

pws019 opened this issue Apr 26, 2018 · 3 comments

Comments

@pws019
Copy link

pws019 commented Apr 26, 2018

when I use webpack&babel,
the result show "XTagElement is not defined"
...
tip:x-tag-version:2.0.9-alpha

.babelrc

{
  "presets": [
    "env"
  ]
}

webpack

{
   test:/\.js$/,
   use:{
            loader:'babel-loader'
   },
   //exclude: /node_modules/
}

index.js

import '../css/index.css';
import {xtag, XTagElement} from 'x-tag';

var PraiseBtn = xtag.create('praise-button',class extends XTagElement{

  constructor() {
    super();
    console.log('xtag init');
  }

  '::template(true)' () {
    return `
      <div class="praise-btn">这是一个praiseButton</div>
    `
  };

  'click::event' () {
    console.log('click-element');
  }
})

export default PraiseBtn;

index.html

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <!-- <script src="https://cdn.bootcss.com/x-tag/2.0.9-alpha/x-tag-polyfilled.js"></script> -->
  <title>Document</title>
</head>
<body>
  <praise-button></praise-button>
<script type="text/javascript" src="./assets/js/index.js"></script></body>
</html>

the result:
image

how can I fix the problem?

@ghost
Copy link

ghost commented Apr 26, 2018

I've never used babel, but why is the x-tag cdn commented out?

@pws019
Copy link
Author

pws019 commented Apr 26, 2018

@KipOmaha because I npm install x-tag.Then I don't need link script.Just import the x-tag in Js

import {xtag, XTagElement} from 'x-tag';

But when I use webpack bundle the x-tag, as mentioned above.
If I don't bundle the x-tag, I meet anothre issue ->

 Class constructor XXX cannot be invoked without 'new'

Of course,when I don't use Babel and write native code,then It's ok.
But I don't how can I make it work with webpack+babel well...

@ghost
Copy link

ghost commented Apr 26, 2018

try the raw source ? So you don't run into conflicting polys?

@ghost ghost mentioned this issue Jul 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant