【发布时间】:2018-08-30 19:46:42
【问题描述】:
更新:我解决了这个问题。查看答案。
目标:设置 Babel。
问题:我在使用 webpack 创建 bundle.js 文件时遇到错误,使用命令:npm run dev。
screenshot 1screenshot 2
./src/js/index.js
import num from "./test";
const x = 45;
console.log(`I imported ${num} from test.js - ${x}`);
webpack.config.js:
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
module.exports = {
entry: ["babel-polyfill", "./src/js/index.js"],
output: {
path: path.resolve(__dirname, "dist"),
filename: "js/bundle.js"
},
devServer: {
contentBase: "./dist"
},
plugins: [
new HtmlWebpackPlugin({
filename: "index.html",
template: "./src/index.html"
})
],
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader"
}
}
]
}
};
【问题讨论】:
-
你缺少一个模块:
npm i -D @babel/core -
我已经安装了这个包。它显示在我的 package.json 文件中。
标签: javascript webpack babeljs