esnunes / riotjs-loader

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

No luck compiling with Babel 6 #14

Closed tscok closed 8 years ago

tscok commented 8 years ago

As @nilpath suggested in #11 I too followed the steps on compiling with Babel 6 (http://riotjs.com/guide/compiler/#babel-6) without any luck.

I installed babel-preset-es2015-riot and babel-core and created the .babelrc file at the project root. I have also added { query: { type: 'babel' } } to the riotjs-loader. My webpack.config file is pretty much identical with the @esnunes example.

var webpack = require('webpack');

module.exports = {
    entry: './assets/js/main.js',
    output: {
        path: __dirname,
        filename: 'bundle.js'
    },
    plugins: [
        new webpack.ProvidePlugin({
            riot: 'riot'
        })
    ],
    module: {
        preLoaders: [
            { test: /\.tag$/, exclude: /node_modules/, loader: 'riotjs-loader', query: { type: 'babel' } }
        ],
        loaders: [
            { test: /\.js$|\.tag$/, exclude: /node_modules/, loader: 'babel-loader' }
        ]
    },
    resolve: {
        extensions: ['', '.js', '.tag']
    }
};

I still get syntax errors for writing functions like add() { ... }. I just don't know where to start debugging. I'm quite new to webpack so I hope someone here can sort things out a bit :)

Thanks!

nilpath commented 8 years ago

what kind of error do you get?

do you use any type attribute on the script tags in your riot.js tags? because that caused some problem for me.

tscok commented 8 years ago

Regardless of whether I use type="babel" on my script tags or not I get the same error:

ERROR in ./assets/js/tags/layout-page.tag
Module build failed: Error: SyntaxError: /Users/mikaelcarlsson/Documents/dev/annsjon/.: Unexpected token (4:14)
    at Object.module.exports (/Users/mikaelcarlsson/Documents/dev/annsjon/node_modules/riotjs-loader/index.js:37:11)
 @ ./assets/js/tags/site-main.tag 4:0-24

When I remove the function mentioned above it works :(

nilpath commented 8 years ago

I can't find it right now, but I remember reading something about add() {...} style functions not being possible to do in riotjs tags with es6. I think you have to use this.add = () => { ... }

tscok commented 8 years ago

Maybe you read that here: https://github.com/riot/examples/tree/gh-pages/es6

And you're right! I didn't realise I should use ES6 syntax with Babel 6. Thank you! :)

nilpath commented 8 years ago

No problem! :)