如何在webpack构建中包含Bower的oasis.js?

时间:2015-11-24 16:06:51

标签: javascript webpack

我正在使用webpack来构建我的项目,而我却无法将其包含在oasis.js中,特别是由{2}引入Bower,因为没有npm可用的模块。

我的webpack配置如下:

'use strict';

const BowerWebpackPlugin = require('bower-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
  entry: './app/index.js',
  output: {
    path: 'www',
    filename: 'bundle.js'
  },
  module: {
      loaders: [
          { test: /\.css$/, loader: 'style-loader!css-loader' },
          { test: /\.html$/, loader: 'html-loader' },
          { test: /\.svg$/, loader: 'file-loader' }
      ]
  },
  plugins: [
      new BowerWebpackPlugin({ excludes: [/oasis\.amd\.js$/] }),
      new HtmlWebpackPlugin()
  ]
};

和我的./app/index.js拉入Oasis看起来像:

'use strict';

var oasis = require('oasis.js');

当我运行webpack -d时,我收到一些错误消息,例如:

ERROR in ./bower_components/oasis.js/dist/oasis.js
Module not found: Error: Cannot resolve module 'oasis/xhr' in /Users/jeffreycharles/projects/dev-container/bower_components/oasis.js/dist
 @ ./bower_components/oasis.js/dist/oasis.js 2983:0-3092:4 3680:0-3780:4

ERROR in ./bower_components/oasis.js/dist/oasis.js
Module not found: Error: Cannot resolve module 'oasis/connect' in /Users/jeffreycharles/projects/dev-container/bower_components/oasis.js/dist
 @ ./bower_components/oasis.js/dist/oasis.js 2983:0-3092:4 3093:0-3189:4

ERROR in ./bower_components/oasis.js/dist/oasis.js
Module not found: Error: Cannot resolve module 'oasis/logger' in /Users/jeffreycharles/projects/dev-container/bower_components/oasis.js/dist
 @ ./bower_components/oasis.js/dist/oasis.js 2983:0-3092:4 3093:0-3189:4 3217:0-3404:4 3453:0-3679:4 3680:0-3780:4

ERROR in ./bower_components/oasis.js/dist/oasis.js
Module not found: Error: Cannot resolve module 'oasis/version' in /Users/jeffreycharles/projects/dev-container/bower_components/oasis.js/dist
 @ ./bower_components/oasis.js/dist/oasis.js 2983:0-3092:4

我觉得很奇怪,因为我可以在oasis文件中的第4961行看到define("oasis/xhr",,而webpack说它无法解析的其他模块都在我链接的同一个文件中。

我还尝试设置noParse并使用脚本加载程序加载Oasis但是它抱怨RSVP没有被定义。当我在HTML中使用脚本标记加载Oasis时,这不是一个问题(事实上,当我这样做时,它都能正常工作)。

如何在我的项目中构建Webpack并包含Oasis.js?

0 个答案:

没有答案