esnunes / riotjs-loader

riotjs module loader for webpack
MIT License
103 stars 41 forks source link

use babel6 and use es6 in tag will lose "this" #27

Closed leekangtaqi closed 8 years ago

leekangtaqi commented 8 years ago

webpack.config.js

var webpack = require('webpack');
var path = require('path');

module.exports = {
    entry: {
        main: ['whatwg-fetch', './web/main.js']
    },
    output: {
        path: path.resolve(__dirname, './public/js'),
        filename: 'bundle.js'
    },
    resolve: {
        extensions: ['', '.js'],
        root: __dirname,
        alias: {
        // riot: '../node_modules/riot/riot.min.js',
        }
    },
    module: {
        preLoaders: [
            { test: /\.html$/, exclude: /node_modules/, loader: 'riotjs-loader', query: { type: 'babel' } }
        ],
        loaders: [
            {
                test: /\.js$/,
                include: /web/,
                loader: 'babel',
                query: {
                    presets: ['es2015', 'stage-3']
                }
            },
            {
                test: /\.scss$/,
                loader: 'style!css!sass'
            }
        ]
    },
    plugins: [
        new webpack.ProvidePlugin({
            riot: 'riot'
        })
    ],
    devServer: {
        contentBase: './', //html root
        hot: true
    }
    // historyApiFallback: true,
};

app.html => tag

require('./todo/todo-list.html');
<app>
    <div>riot</div>
    <todo-list todos="{todos}"/>
    <script>
        console.log(this);         //undefined
        this.todos = [                //error!!boom!!! 
            {name: '111', id: 0},
            {name: '112', id: 1}
        ]
    </script>
</app>
leekangtaqi commented 8 years ago

help me please. wait online

teamgroove commented 8 years ago

i would need more of the code of the example, but what i can say for sure now: "this" is never exposed out to this scope and the part of the script-tag. what did you expect to have in "this"? Did you already fix the issue?

leekangtaqi commented 8 years ago

i already fix it. thank u.