Webpack中的requirejs和骨干错误在浏览器中输出

时间:2016-03-31 19:14:08

标签: backbone.js requirejs webpack

这是我的webpack配置:

{
    entry: './public/static/js/app/app.js',
    output: {
        path: './public/static/dist/js/',
        filename: 'app-compiled.js',
        pathinfo: true
    },
    module: {
        loaders: [
            {
                test: /public\/static.*\.js$/,
                loader: 'babel-loader',
            },
            {
                test: /\.html$/,
                loader: 'raw'
            },
        ],
    },
    plugins: [
        new webpack.dependencies.LabeledModulesPlugin()
    ],
    resolveLoader: {
        alias: {
            'text': 'raw',
        },
        root: ['./public/static/js/app']
    },
    resolve: {
        extensions: ['', '.js'],
        root: [
            path.resolve('./public/static/js/app'),
        ],
        modulesDirectories: ['node_modules'],
        alias: {
            'backbone': path.resolve('./public/static/js/lib/backbone.js'),
            'backbone.relational': path.resolve('./public/static/js/lib/backbone-relational.js'),
            'backbone.wreqr': path.resolve('./public/static/js/lib/backbone.wreqr.min.js'),
            'marionette': path.resolve('./public/static/js/lib/marionette.js'),
            'text': path.resolve('./public/static/js/lib/text.js'),
            'smoke': path.resolve('./public/static/js/lib/smoke.js'),
            '_': path.resolve('./public/static/js/lib/underscore.js'),
            'underscore.inflection': path.resolve('./public/static/js/lib/underscore.inflection.js'),
            'chosen': path.resolve('./public/static/js/lib/chosen.js'),
            'spin': path.resolve('./public/static/js/lib/spin.min.js'),
            'uuid': path.resolve('./public/static/js/lib/uuid-v4.min.js'),
            'ladda': path.resolve('./public/static/js/lib/ladda.min.js'),
            'jquery': path.resolve('./public/static/js/lib/jquery.js')
        }
    },
    debug: true,
    devtool: 'sourcemap',
};

我在浏览器中看到的问题是root is undefined。读取的编译代码为var previousBackbone = root.Backbone;

1 个答案:

答案 0 :(得分:0)

您不应该需要Babel来转换节点结节,例如Backbone。我们希望Webpack在给定的npm包中使用预先构建的javascript。在不排除node_modules的转换之后,我预计Babel会对Backbone进行一些优化,不应该这样做。要排除node_modules,请向babel加载程序添加exclude属性,例如

<StackLayout>
  <StackLayout orientation="horizontal" style="padding: 5">
    <Image src="~/res/logo.png" width="50" height="50" verticalAlignment="top"/>
    <Label text="I am a message" textWrap="true" backgroundColor="red" />
  </StackLayout>
  <StackLayout orientation="horizontal" style="padding: 5">
    <Image src="~/res/logo.png" width="50" height="50" verticalAlignment="top"/>
    <Label text="This is a longer message, which is worth adding because then I can make sure that longer messages display properly in the messages view! They need to wrap, obviously!" backgroundColor="red" textWrap="true" />
  </StackLayout>
</StackLayout>