-
Notifications
You must be signed in to change notification settings - Fork 43
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
import statement returns undefined #62
Comments
Update I think the issue is that all of the loaders mentioned in the readme are supposed to return strings. With React Templates, I'm really trying to return a Javascript function. With the following webpack configuration, module.exports = {
output: {
libraryTarget: 'commonjs'
},
module: {
loaders: [
{
test: /\.template\.html$/,
loaders: ["raw", "react-templates-loader?targetVersion=0.14.7&modules=jsrt"]
},
],
},
}; I get the following output for template: (function () {
function repeatExample1(example,exampleIndex) {
return React.createElement('button',{"key" : (example.scoped_id),"data-param" : "example_id","data-value" : (example.data.id),"className" : _.keys(_.pick({active: this.example && this.example.data.id === example.data.id}, _.identity)).join(" ") + " " + "btn btn-primary","onClick" : (this.setParam.bind(this)),"type" : "button"},(example.data.name))
}
return function(){
return React.createElement('div',{"id" : "layout"},React.createElement('h1',{},"Basic Layout Component"),((!this.state.example)?(React.createElement('div',{"className" : "alert alert-warning"},"\n Choose an example.\n ")):null),((this.state.example)?(React.createElement('div',{"className" : "alert alert-info"},"\n ",(this.state.example.introduce()),"\n ")):null),React.createElement.apply(this, ['div',{"className" : "btn-group","role" : "group"},_.map(this.examples,repeatExample1.bind(this))]))}}
)() This is close to what we want, but of course React won't be defined. Alternatively, passing the 'use strict';
var React = require('react/addons');
var _ = require('lodash');
function repeatExample1(example, exampleIndex) {
return React.createElement(button, {
'key': example.scoped_id,
'data-param': 'example_id',
'data-value': example.data.id,
'className': _.keys(_.pick({ active: this.example && this.example.data.id === example.data.id }, _.identity)).join(' ') + ' ' + 'btn btn-primary',
'onClick': this.setParam.bind(this),
'type': 'button'
}, example.data.name);
}
module.exports = function () {
return React.createElement(div, { 'id': 'layout' }, React.createElement(h1, {}, 'Basic Layout Component'), !this.state.example ? React.createElement(div, { 'className': 'alert alert-warning' }, '\n Choose an example.\n ') : null, this.state.example ? React.createElement(div, { 'className': 'alert alert-info' }, '\n ', this.state.example.introduce(), '\n ') : null, React.createElement.apply(this, [
div,
{
'className': 'btn-group',
'role': 'group'
},
_.map(this.examples, repeatExample1.bind(this))
]));
}; This leads to a more general question, what needs to happen to load Javascript modules? |
Update 2 I've tried returning the various strings with a plugin: module.exports = {yada: 'yada'};
// import result
{yada: 'yada'} var yada = "yada";
module.exports = {yada: yada};
// import result
ReferenceError: yada is not defined module.exports = 'Hello ' + ' world!';
// import result
'Hello world!' module.exports = function(){ return 'yada' }
// import result
undefined So for some reason, difficulty arises:
|
I think of Ioaders as about resources in other languages, resources is just simple types like plain objects, strings, numbers. Not functions. |
I see, and after reading the source code, it would be really unreasonable to expect you (or really anyone) to. I think it makes sense to do what I want to do with a separate plugin. Thanks. |
@istarkov I have one question for you that would be a huge help. I'm not quite grasping how this plugin gains access to css files before Babel tries to parse it to AST. For instance, when you call |
As it is a babel plugin I could parse AST tree before any javascript will execute. Any require (and import as import converted to require with other plugins) call which confirms this and some criteria below, processed and transformed by this plugin. |
Ok, this has nothing to do with your repo, so I'll close and leave this comment here for posterity. Thanks. Trying to write another plugin that compiles html files, much as this one parses css files. However, I kept getting I defined my visitor as follows: module.exports = function (opts) {
return {
visitor: {
CallExpression: {
enter(path, opts) {
// do stuff to html
}
}
}
};
}; My problem is that plugin/preset order is not respected in Babel6 (see discussion) - though there is an experimental feature to try to resolve this: babel/babel#3281 What's weird though, is your repo doesn't have this issue - even after I bumped the |
I'm trying to use this plugin to compile react templates on the server - see the webpack plugin.
Here are my configuration settings.
server/config/webpack.js
.babelrc
An example template:
components/layout/layout.template.html
And the related React Component:
components/layout/layout.component.js
Unfortunately, template is undefined when I run with this plugin. In fact, I've put some log statements into node_modules/react-templates-loader/index.js and it seems the loader is never even called.
I'd be willing to put some time into making this work, but I really don't where to start. Do you have any idea where to start in terms of debugging this?
The text was updated successfully, but these errors were encountered: