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

spm doc watch 模式下 require 超过2层目录反斜杠解析出错 Uncaught SyntaxError: Unexpected token ILLEGAL #32

Closed
forestlioooooo opened this issue Jan 27, 2015 · 7 comments
Assignees

Comments

@forestlioooooo
Copy link

在 js 中,我使用了:

require("./style/user.less");

但是在前端获取到的数据确变成了:

require("./style\user.css"); // 这里的第二个反斜杠变成了正斜杠

这里的第二个反斜杠变成了正斜杠

这个问题很奇怪,其它使用这种方式写的虽然第二个反斜杠变成了正斜杠,但是css都加在到了,只有这个user.js 中使用的css没有被加在出来。

这是user.js的代码:

'use strict';
require('./static/user.less');


var $ = require('jquery');

/**
 */
var User = function(options, dom) {
        this.options = $.extend({
                /**
                {
                        "id":008567, // 用户ID
                        "name":"李贤淑", // 用户名称
                        "status":"online", // 用户状态
                        "desc":"有事儿请打15810713726", // 用户描述
                        "image":undefined,
                        features:{ // 用户特征
                                "lastusedtime":1420774204607,
                                "notify":0,
                                "emergency-notify":0,
                                ...
                        }
                }
                */
                data: undefined,
                /**
                构造头像图片路径
                @id:user id
                @size:image size,36 now
                */
                buildAvatarUrl: function(id, status, size) {},
                /**
                特征插件
                {
                        "feature-name":function(name){....;return feature;}
                }
                */
                features: {}
        }, options || {});
        this.$dom = $(dom || User.template).data('user', this);

        this.features = {};
        var $features = this.$features = this.$dom.find('> .mo-user-content > .mo-user-features');
        var self = this;
        $.each(this.options.features || [], function(name, generator) {
                var feature = self.features[name] = generator(name);
                var $dom = $(feature.dom());
                $dom.attr('mo-user-feature-name', name);
                $features.append($dom);
        });

        this.update(this.options.data || {});
};

User.prototype.id = function() {
        return this.options.data.id;
};

/**
@data:
{
        "id":008567, // 用户ID
        "name":"李贤淑", // 用户名称
        "status":"online", // 用户状态
        "desc":"有事儿请打15810713726", // 用户描述
        "image":undefined,
        features:{ // 用户特征
                "lastusedtime":1420774204607,
                "notify":0,
                "emergency-notify":0,
                ...
        }
}
*/
User.prototype.update = function(data) {
        this.data = $.extend(this.data || {}, data || {});
        this.$dom.attr('data-user-id', data.id || '');
        (this.$avatar = this.$avatar || this.$dom.find('>.avatar')).css(
                'background-image', 'url(' + (data.image || this.options.buildAvatarUrl(data.id, data.status || '', 36)) + ')'
        );
        (this.$status = this.$status || this.$dom.find('> .avatar > .status')).attr('class', 'status ' + data.status || '');
        (this.$username = this.$username || this.$dom.find('> .mo-user-content > .mo-user-name')).text(data.name || '');
        (this.$desc = this.$desc || this.$dom.find('> .mo-user-content > .mo-user-desc')).text(data.desc || '');

        var self = this;
        $.each(this.features, function(name, feature) {
                feature.update(data.features[name], self, self.$features.find('[mo-user-feature-name=' + name + ']'));
        });
};

User.prototype.dom = function() {
        return this.$dom;
};

User.template = '<li class="mo-user">' + '<a href="#" class="avatar s36" style="background-image:url(../images/avatar.36.36.png);">' + '<i class="status online"></i>' + '</a>' + '<a href="#" class="mo-user-content">' + '<span class="mo-user-name"></span>' + '<ul class="mo-user-features">' + '</ul>' + '<span class="mo-user-desc"></span>' + '</a>' + '</li>';
/**
<li class="mo-user">
        <a href="#" class="avatar s36" style="background-image:url(../images/avatar.36.36.png);">
                <i class="status online"></i>
        </a>
        <a href="#" class="mo-user-content">
                <span class="mo-user-name"></span>
                <ul class="mo-user-features">
                </ul>
                <span class="mo-user-desc"></span>
        </a>
</li>
*/

module.exports = User.constructor = User;

全部代码我已经提交到了:https://github.com/GENGSHUANGs/mocenter

1、spm install
2、spm doc watch

访问:http://localhost:8000/examples/index2.html
Console中可看到错误,我的环境是chrome 版本 40.0.2214.91 m

@forestlioooooo forestlioooooo changed the title spm doc watch 模式下 require 超过2层目录反斜杠解析出错 spm doc watch 模式下 require 超过2层目录反斜杠解析出错 Uncaught SyntaxError: Unexpected token ILLEGAL Jan 27, 2015
@afc163
Copy link
Member

afc163 commented Jan 27, 2015

应该是这个问题:spmjs/spm#1142

重新安装 spm 再试试。

@forestlioooooo
Copy link
Author

我重装了spm ,但是版本还是3.3.4,如果升级到更高版本?

@afc163
Copy link
Member

afc163 commented Jan 28, 2015

主要是为了更新依赖,大版本应该没变。

更新后是否修复了楼主的问题?

@forestlioooooo
Copy link
Author

问题依旧:
我重装的方式是:

npm remove spm -g
npm install spm -g

安装过程中未报错

我的操作系统环境是:win 8.1 以及 win 10 TechnicalPreview

@forestlioooooo
Copy link
Author

还有个情况:在#1142 下,说到是\u的问题,我在最新的测试下:

require("./style\x-user.css");

也是失败的
环境:win 10 TechnicalPreview,win8.1 还没测试

@forestlioooooo
Copy link
Author

发布了没?我重装spm之后,serve-spm 的 js.js 46行 winPath(...) 并没有加上

@sorrycc
Copy link
Member

sorrycc commented Jan 29, 2015

npm install spm@ninja,发在 ninja tag 上。

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

3 participants