Javascript ES6&x2B;SystemJs-为什么我必须使用.js扩展来导入es6模块?
为什么我必须使用.js扩展来导入带有systemjs的es6模块?例如:Javascript ES6&x2B;SystemJs-为什么我必须使用.js扩展来导入es6模块?,javascript,ecmascript-6,systemjs,es6-module-loader,traceur,Javascript,Ecmascript 6,Systemjs,Es6 Module Loader,Traceur,为什么我必须使用.js扩展来导入带有systemjs的es6模块?例如: import { multiplier } from "adder.js"; // ok import { double, square } from 'modules'; // error var timesTwo = multiplier(2); console.log(timesTwo(4)); 错误消息: 获取404(未找到)Z@ system.js:4(匿名函数)@system.js:4(匿名函数)@ sy
import { multiplier } from "adder.js"; // ok
import { double, square } from 'modules'; // error
var timesTwo = multiplier(2);
console.log(timesTwo(4));
错误消息:
获取404(未找到)Z@
system.js:4(匿名函数)@system.js:4(匿名函数)@
system.js:4(匿名函数)@system.js:5(匿名函数)@
system.js:5(匿名函数)@system.js:5(匿名函数)@
system.js:5(匿名函数)@system.js:5(匿名函数)@
system.js:5(匿名函数)@system.js:4 system.js:4未捕获(在
承诺)错误:错误:XHR错误(404未找到)加载
(……)
这是我的带有system.js的HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>ES2015 Module Example</title>
</head>
<body>
<script src="lib/system.js"></script>
<script>
System.config({
"baseURL": "src",
// 'plugin-babel' or 'traceur' or 'typescript'
transpiler: 'plugin-babel',
// or traceurOptions or typescriptOptions
babelOptions: {
},
map: {
'traceur': './lib/traceur.min.js',
'plugin-babel': './lib/plugin-babel/plugin-babel.js',
'systemjs-babel-build': './lib/plugin-babel/systemjs-babel-browser.js'
}
}
});
System.import("app.js");
</script>
</body>
</html>
ES2015模块示例
System.config({
“baseURL”:“src”,
//“插件巴别塔”或“traceur”或“typescript”
transpiler:“插件巴别塔”,
//或TraceEuroptions或typescriptOptions
巴别斯语:{
},
地图:{
'traceur':'/lib/traceur.min.js',
'plugin babel':'/lib/plugin babel/plugin babel.js',
'systemjs babel build':'。/lib/plugin babel/systemjs babel browser.js'
}
}
});
System.import(“app.js”);
知道我遗漏了什么吗?因为system js没有在模块名后面附加
.js
。一些模块加载程序/捆绑程序(节点、网页包等)正在这样做,但没有标准规定必须这样做
这是一个很好的解决方案,但它将被弃用