配置Vue以进行开发和生产构建

时间:2019-03-29 02:36:58

标签: vue.js

我继承了一个Vue项目,该项目只能构建生产版本并破坏一切。它没有像我以前那样的webpack.config.js,只有一个vue.config.js文件。当我执行npm run build时,它会生成一个产品。构建命令为"build": "vue-cli-service build",但我看不到做类似--mode=development之类的方法。

我尝试添加一个生成的webpack.config.js文件,但同时又破坏了该网页,因为它不再生成相同的文件。

这是我的vue.config.js文件:

const path = require('path');
const CopyWebpackPlugin = require('copy-webpack-plugin');


module.exports = {
    lintOnSave: true,
    baseUrl: 'http://localhost:8080',
    configureWebpack: {
        entry: './src/main.js',
        module: {
            rules: [
                {
                    test: /libs\.js$/,
                    use: {
                        loader: 'script-loader'
                    }
                },
                {
                    test: /angLibs\.js$/,
                    use: {
                        loader: 'script-loader'
                    }
                },
                {
                    test: /welcome\.js$/,
                    use: {
                        loader: 'script-loader'
                    }
                },
                {
                    test: /app\.js$/,
                    use: {
                        loader: 'script-loader'
                    }
                }
            ]

        },
        output: {
            publicPath: process.env.VUE_APP_ROOT_API + '/',
            chunkFilename: '[name].bundle.js'
        },
        plugins: [
            new CopyWebpackPlugin([
                { from: path.resolve(__dirname, './static/App/i18n/*.*'), to: path.resolve(__dirname, './dist/'), force: true }
            ], { copyUnmodified: true, context: 'static/' }),
            new CopyWebpackPlugin([
                { from: path.resolve(__dirname, './static/Content/*/*.*'), to: path.resolve(__dirname, './dist/'), force: true }
            ], { copyUnmodified: true, context: 'static/' }),
            new CopyWebpackPlugin([
                { from: path.resolve(__dirname, './static/fonts/*.*'), to: path.resolve(__dirname, './dist/'), force: true }
            ], { copyUnmodified: true, context: 'static/' }),
            new CopyWebpackPlugin([
                { from: path.resolve(__dirname, './static/react/*.*'), to: path.resolve(__dirname, './dist/'), force: true }
            ], { copyUnmodified: true, context: 'static/' })
        ]
    }
};

我想拥有一个开发速度更快,不被丑化/缩小的开发版本(或保留Webpack中包含的文件的映射文件)。

1 个答案:

答案 0 :(得分:0)

这是Vue CLI v3构建。对于具有热重载的Webpack开发服务器,请使用npm run serve

否则,您可以通过{p>

development

或者,如果您没有npx vue-cli-service build --mode development

npx

请参见https://cli.vuejs.org/guide/mode-and-env.html


另一种选择是向./node_modules/.bin/vue-cli-service build --mode development 添加新脚本,例如

package.json

然后运行

"buildDev": "vue-cli-service build --mode development"

有关配置Webpack的信息,请参见https://cli.vuejs.org/guide/webpack.html

例如

npm run buildDev