gpt4 book ai didi

webpack - 设置 webpack 和 vue3

转载 作者:行者123 更新时间:2023-12-02 02:26:40 27 4
gpt4 key购买 nike

我正在尝试使用 webpack 和 typescript 设置 vue3。目前我遇到的问题是,每当我尝试运行 webpackserve 时,浏览器控制台内都会出现警告:

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-config 如下:

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!

最佳答案

来自错误中的链接。

The build will work without configuring these flags, however it is strongly recommended to properly configure them in order to get proper tree-shaking in the final bundle.

这应该可以解决您的问题。

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 项目的标准工具。

关于webpack - 设置 webpack 和 vue3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65551612/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com