記錄下在使用 Webpack 時,
如何使用 Bebel 並用 @babel/preset-typescript
的方式配合使用 Typescript 的功能
將 @babel/preset-typescript 設定在 babel-loader 的 presets 裡就好了。
package.json:
webpack.config.js:
{ "name": "xxx-proejct", "scripts": { "deploy": "webpack" }, "devDependencies": { "@babel/core": "7.18.10", "@babel/preset-env": "7.18.10", "@babel/preset-typescript": "^7.24.7", "babel-loader": "8.2.5", "css-loader": "5.0.1", "mini-css-extract-plugin": "1.3.3", "sass": "1.54.9", "sass-loader": "10.1.0", "style-loader": "3.3.1", "webpack": "5.74.0", "webpack-cli": "4.10.0" } }
webpack.config.js:
var path = require('path'); var MiniCssExtractPlugin = require('mini-css-extract-plugin'); module.exports = { entry: { index_js: { import: "./src/app.js", filename: "js/index_bundle.js" } }, output: { path: __dirname + "/dist" }, watch: false, devtool : 'source-map', mode : "production", resolve : { extensions : ['.js', '.ts'], modules: [path.resolve(__dirname, '.'), 'node_modules'] }, module: { rules : [{ test : /\.(ts|js)$/, use : { loader : 'babel-loader', options : { presets : ['@babel/preset-env', '@babel/preset-typescript'] } } }, { test: /\.s[ac]ss$/, use: [ MiniCssExtractPlugin.loader, "css-loader", "sass-loader" ] }] }, plugins: [new MiniCssExtractPlugin({ filename: "./css/index_bundle.css" })], externals: { angular: "angular" } }
沒有留言 :
張貼留言