【发布时间】:2019-11-10 05:46:38
【问题描述】:
我正在使用带有 awesome-typescript-loader 和 Webpack 的 typescript 进行编译。但在 IE11 中它不起作用。我有这个错误。
SCRIPT1014
bundle.js (58458,12)
在这一行我有这个。我认为问题出在性格上`
const v6 = `
这是我对 tsconfig.json 的配置
{
"compilerOptions": {
"target": "es6",
"module": "es6",
"moduleResolution": "node",
"resolveJsonModule": true,
"declaration": false,
"esModuleInterop": true,
"noImplicitAny": false,
"jsx": "react",
"sourceMap": true,
"noLib": false,
"suppressImplicitAnyIndexErrors": true,
"baseUrl": "./src/",
"paths": {
"@pages": ["./pages/*"],
"@core": ["./core/*"],
"@pods": ["./pods/*"],
"@common": ["./common/*"],
"@state": ["./state/*"]
},
"skipLibCheck": true
},
"compileOnSave": false,
"exclude": ["node_modules"]
}
这是我的 webpack.config.js
var HtmlWebpackPlugin = require("html-webpack-plugin");
var MiniCssExtractPlugin = require("mini-css-extract-plugin");
var webpack = require("webpack");
var path = require("path");
var basePath = __dirname;
module.exports = {
context: path.join(basePath, "src"),
resolve: {
extensions: [".js", ".ts", ".tsx"],
alias: {
// Later on we will add more aliases here
pages: path.resolve(__dirname, "./src/pages/"),
core: path.resolve(__dirname, "./src/core/"),
pods: path.resolve(__dirname, "./src/pods/"),
common: path.resolve(__dirname, "./src/common/"),
state: path.resolve(__dirname, "./src/state/"),
}
},
entry: ["@babel/polyfill", "./index.tsx"],
output: {
path: path.join(basePath, "dist"),
filename: "bundle.js"
},
devtool: "source-map",
devServer: {
contentBase: "./dist", // Content base
inline: true, // Enable watch and live reload
host: "test",
port: 8080,
stats: "errors-only",
disableHostCheck: true,
historyApiFallback: true,
},
module: {
rules: [
{
test: /\.(ts|tsx)$/,
exclude: /node_modules/,
loader: "awesome-typescript-loader",
options: {
useBabel: true,
babelCore: "@babel/core" // needed for Babel v7
}
},
{
test: /\.css$/,
use: [MiniCssExtractPlugin.loader, "css-loader"]
},
{
test: /\.(png|jpg|gif|svg)$/,
loader: "file-loader",
options: {
name: "assets/img/[name].[ext]?[hash]"
}
}
]
},
plugins: [
//Generate index.html in /dist => https://github.com/ampedandwired/html-webpack-plugin
new HtmlWebpackPlugin({
filename: "index.html", //Name of file in ./dist/
template: "index.html", //Name of template in ./src
hash: true
}),
new MiniCssExtractPlugin({
filename: "[name].css",
chunkFilename: "[id].css"
})
]
};
通过 .babelrc 文件
{
"presets": [
[
"@babel/preset-env",
{
"useBuiltIns": "entry"
}
]
]
}
我对这个问题没有更多的想法。
【问题讨论】:
-
入口中不需要添加@babel/polyfill。 .babelrc 文件应该看起来像这样 { "presets": [ [ "@babel/preset-env", { "useBuiltIns": "usage", "corejs": 3 } ] ] }
-
尝试将目标设置为具体包括 ie11:babeljs.io/docs/en/babel-preset-env#targets 具体来说,它说“旁注,如果没有指定目标,@babel/preset-env 将默认转换所有 ECMAScript 2015+ 代码。” .不确定这是否包括 es2015。如果假定支持 es2015,它将留下反引号。这会破坏一切。
标签: typescript webpack internet-explorer-11 babeljs tsconfig