在ES6应用程序中对库源映射进行网络打包时出错,可在ES5应用程序中使用
Error webpacking library source maps in ES6 app, works in ES5 app
我使用这个webpack.config.js
分发了一个ES6库,并将其转换为ES5
var webpack = require("webpack");
module.exports = {
entry: ['./src/MyLib.js'],
output: {
path: __dirname,
filename: 'dist/bundle.js',
libraryTarget: 'umd',
library: "MyLib"
},
module: {
loaders: [
{
test: /'.js$/,
loader: 'babel',
query: { presets: ['es2015'] }
},
{
test: /'.css$/,
loader: "style-loader!css-loader"
}
]
},
devtool: 'source-map'
};
正如Webpack的devtool
文档中所暗示的那样我使用source-map-loader
使库源映射在使用该库的ES5应用程序中可用。它与这个webpack.config.js 一起工作
var path = require("path");
module.exports = {
entry: './main.js',
output: {
filename: 'dist/bundle.js'
},
module: {
preLoaders: [
{
test: /'.js$/,
loader: 'source-map',
include: /my-lib/
}
]
},
resolveLoader: {
root: path.join(__dirname, "node_modules"),
},
devtool: 'source-map'
};
问题是,当库的使用者是ES6应用程序时,具有以下webpack.config.js
,它只是将babel加载程序添加到适用于ES5应用程序的配置文件中
var path = require("path");
module.exports = {
entry: './main.js',
output: {
filename: 'dist/bundle.js'
},
module: {
preLoaders: [
{
test: /'.js$/,
loader: 'source-map',
include: /my-lib/
}
],
loaders: [
{
test: /'.js$/,
loader: 'babel',
query: { presets: ['es2015'] }
}
]
},
resolveLoader: {
root: path.join(__dirname, "node_modules"),
},
devtool: 'source-map'
};
然后,当运行webpack时,会出现类似的错误
ERROR in ./~/my-lib/dist/bundle.js
Module build failed: Error: /Users/xavi/Development/my-lib/examples/es6/node_modules/my-lib/dist/bundle.js: Invalid mapping: {"generated":{"line":8,"column":0,"lastColumn":null},"source":null,"original":{"line":null,"column":null},"name":null}
...
为什么当消费者是一个ES5应用程序,而当它是一个用Babel移植的ES6应用程序时,这个源映射配置就不起作用了?如何在ES6应用程序中提供库源地图?
Babel在获取库的源映射时一定会遇到一些问题,由于您有test: /'.js$/,
,因此Babel将处理您的repo中的每一个JS文件,包括node_modules
。
我建议将test
限制为只匹配您希望Babel处理的文件,这可能足以避免这种情况,尽管它不能解决根本问题。
相关文章:
- 尝试使用HtmlUnit分析成员应用程序时出错
- 若语句出错,谷歌应用程序脚本
- 尝试在移动优先应用程序中从 SQL 数据库获取数据时出错
- AngularJS/Protactor:使用角种子基本应用程序运行量角器时出错
- 在一个移动Markt中上传应用程序时出错
- setHours()从电子表格导入的日期创建谷歌日历事件时出错-应用程序脚本
- 有角度的“;未知提供者”;在约曼应用程序中使用Grunt Build缩小后出错
- 将数据插入数据库express/mongodb应用程序时出错
- 谷歌应用程序脚本:;范围不是函数,它是对象;尝试在单元格中放置注释时出错
- "未定义“角度”;在Liferay中存储的角度应用程序上执行Protractor测试时出错
- 将数据从 ASP.Net 4.5 发布到 ASP.Net 2.0 Web 应用程序时出错
- 在我的 Rails 应用程序中使用 jQuery 数据表时出错
- 使用 jspm 配置运行打字稿 angular2 应用程序的页面加载时出错
- 脸书示例登录应用程序中出错
- 使用 heroku 运行 angularjs 种子应用程序时出错
- 用户不能在从 Heroku 节点.js应用程序在解析上更新 PFUser 时出错
- 运行反应原生 Android 应用程序 - BatchedBridge 时出错
- 调用方法'时出错;headersToken'将MessageFormat添加到Meteor应用程序后
- 在ES6应用程序中对库源映射进行网络打包时出错,可在ES5应用程序中使用
- 404在nodejs+Ionic应用程序中从index.html中的另一个文件夹导入js文件时出错