gpt4 book ai didi

javascript - Vue在生产环境DEV模式下

转载 作者:可可西里 更新时间:2023-11-01 01:54:20 25 4
gpt4 key购买 nike

版本2.5.13

源代码链接 https://jsfiddle.net/esrgxLfu/

描述我有一个 PHP 应用程序,它主要将 Vue JS 用于设置页面。所有设置都是用 Vue 创建的,我们使用 Webpack。一切正常,当我们在实时版本中时,没有关于 Vue 处于开发模式的控制台错误。我们也仅将 Vue 用于仪表板页面上的一个组件。它是一个 Vue TODO 列表,就像 Vue 文档中的一样。在仪表板页面上,我们得到 Vue 处于开发模式的控制台消息。我们对仪表板和设置页面使用相同的 Webpack,因此设置相同。我花了几个小时试图找到答案,但没有成功,这就是我创建此问题的原因。

在 php 文件中,我们将 vue 组件放在:

<div id="vue-tasks"></div>

然后我们包含了 javascript 文件和变量。

你可以看到 fiddle 中使用的所有内容,但我真的不认为我可以重现它,如果你不能帮助我,我很抱歉,但它使用了来自 PHP Symfony 和 twig 的一堆东西所以我不确定我能做什么。

期望什么?Vue 将处于生产模式。

实际发生了什么?Vue 在开发环境中。

Webpack 配置

const path = require('path');
const webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const ManifestPlugin = require('webpack-manifest-plugin');
const ChunkManifestPlugin = require('chunk-manifest-webpack-plugin');
const WebpackMd5Hash = require('webpack-md5-hash');
const CleanWebpackPlugin = require('clean-webpack-plugin');

module.exports = {
entry: {
dashboard: [
'./assets/js/pages/dashboard.js' // Dashboard is the part where we have this issue and the JS is in the fiddle I provided above.
],
settings: [
'./assets/js/pages/settings/main.js'
]
},
output: {
filename: process.env.NODE_ENV === 'production' ? 'js/[name].[chunkhash].js' : 'js/[name].js',
path: path.resolve(__dirname, 'web/dist'),
publicPath: '/dist/'
},
module: {
rules: [
{
test: /\.(png|jpg|gif)$/,
use: [
{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'images/'
}
}
]
},
{
test: /\.js$/,
include: path.resolve(__dirname, "assets"),
use: ['babel-loader']
},
{
test: /\.(woff2?|ttf|eot|svg)$/,
loader: 'url-loader?limit=10000&name=fonts/[name].[ext]'
},
{
test: /\.scss$/,
include: path.resolve(__dirname, "assets"),
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: ['css-loader','resolve-url-loader','sass-loader?sourceMap']
})
},
{
test: /\.css$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: ['css-loader','resolve-url-loader']
})
},
{
test: /\.vue$/,
loader: 'vue-loader',
options: {
loaders: {
'scss': 'vue-style-loader!css-loader!sass-loader',
'sass': 'vue-style-loader!css-loader!sass-loader?indentedSyntax'
}
}
},
]
},
resolve: {
alias: {
jquery: "jquery/src/jquery",
'vue$': 'vue/dist/vue.esm.js'
}
},
plugins: [
new ExtractTextPlugin({
filename: process.env.NODE_ENV === 'production' ? 'css/[name].[chunkhash].css' : 'css/[name].css'
}),
new webpack.ProvidePlugin({
'$': 'jquery',
'jQuery': 'jquery'
}),
new WebpackMd5Hash(),
new ManifestPlugin({
basePath: '/dist/'
})
],
performance: {
hints: false
},
devtool: 'source-map'
};

if (process.env.NODE_ENV === 'production') {
module.exports.plugins = (module.exports.plugins || []).concat([
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"production"'
}
}),
new webpack.optimize.UglifyJsPlugin({
minimize: true,
comments: false,
compress: {
warnings: false
}
}),
new webpack.LoaderOptionsPlugin({
minimize: true
}),
new CleanWebpackPlugin('dist' , {
root: path.resolve(__dirname, "web"),
verbose: true,
dry: false
})
])
}

这也是我在控制台中收到的消息。

You are running Vue in development mode. Make sure to turn on production mode when deploying for production. See more tips at https://vuejs.org/guide/deployment.html

最佳答案

看起来您正在使用浏览器脚本标签而不是作为构建系统中的 bundle 的一部分来选择 Vue。

将此更改为链接到 Vue 的生产版本将解决该问题。例如,在您的 jsfiddle 中,将脚本链接替换为 https://unpkg.com/vue/dist/vue.min.js

关于javascript - Vue在生产环境DEV模式下,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47947587/

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