不用写后缀名,
•
用as的时候 await会报错,改用then() 解决
编写代码
src/index.js
src/bar.js
import bar from './bar';
import bar as bar1 from './bar1';
bar();
export default function bar() {
//
}
使用 webpack 打包
Without config or provide custom webpack.config.js
const path = require('path');
module.exports = {
entry: './src/index.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js'
}
};
page.html
<!doctype html><html><head>
...
</head><body>
...
<script src="dist/bundle.js"></script></body></html>
然后在命令行运行 webpack 就会创建 bundle.js。
评论区