[英]setup webpack and vue3
我正在嘗試使用 webpack 和 typescript 設置 vue3。 目前我遇到的問題是,每當我嘗試運行webpack serve
時,瀏覽器控制台內都會出現警告:
runtime-core.esm-bundler.js:3413 You are running the esm-bundler build of Vue. It is recommended to configure your bundler to explicitly replace feature flag globals with boolean literals to get proper tree-shaking in the final bundle. See http://link.vuejs.org/feature-flags for more details.
我不明白。 我的 webpack 配置如下:
const path = require("path")
module.exports = {
mode: 'development',
entry: './src/index.ts',
devtool: 'inline-source-map',
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
],
},
resolve: {
alias: {
vue: "vue/dist/vue.esm-bundler.js"
},
extensions: ['.tsx', '.ts', '.js'],
},
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist'),
},
}
這是 tsconfig:
{
"compilerOptions": {
"outDir": "./dist/",
"noImplicitAny": true,
"module": "es6",
"target": "es5",
"allowJs": true,
"moduleResolution": "node"
}
}
我想在沒有此警告的情況下進行配置,然后繼續支持 sfc!
從您在錯誤中獲得的鏈接。
該構建將在不配置這些標志的情況下工作,但是強烈建議正確配置它們以便在最終捆綁包中獲得正確的 tree-shaking。
這應該可以解決您的問題。
const path = require("path");
const webpack = require('webpack');
module.exports = {
mode: 'development',
entry: './src/index.ts',
devtool: 'inline-source-map',
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
],
},
resolve: {
alias: {
vue: "vue/dist/vue.esm-bundler.js"
},
extensions: ['.tsx', '.ts', '.js'],
},
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist'),
},
plugins: [
new webpack.DefinePlugin({
"__VUE_OPTIONS_API__": true,
"__VUE_PROD_DEVTOOLS__": false,
});
],
}
還值得補充的是, @vue-cli是 vue 項目的標准工具。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.