首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >webpack与vue3的设置

webpack与vue3的设置
EN

Stack Overflow用户
提问于 2021-01-03 15:35:56
回答 1查看 3.1K关注 0票数 2

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

代码语言:javascript
复制
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配置如下:

代码语言:javascript
复制
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:

代码语言:javascript
复制
{
    "compilerOptions": {
        "outDir": "./dist/",
        "noImplicitAny": true,
        "module": "es6",
        "target": "es5",
        "allowJs": true,
        "moduleResolution": "node"
    }
}

我想在没有此警告的情况下进行配置,然后继续支持证监会!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-01-03 15:46:07

从你在错误中得到的链接。

构建将在不配置这些标志的情况下工作,但是强烈建议正确配置它们,以便在最后的包中获得正确的树抖动。

这应该能解决你的问题。

代码语言:javascript
复制
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项目的标准工具。

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65551612

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档