账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    vue-cli3的output.js
    39
    0

    vue-cli3
    非生产模式下,配置的东西可以通过output.js可以看到
    在生产模式下,配置的东西通过output.js看不到

    //我的测试代码
        if (IS_PROD) {
          config.plugin("webpack-report").use(BundleAnalyzerPlugin, [
            {
              analyzerMode: "static"
            }
          ]);
        }
      },
    //IS_PROD为false,output.js里面有
        new BundleAnalyzerPlugin(
          {
            analyzerMode: 'static'
          }
        )
    //IS_PROD为true,output.js里面则没有上面的配置

    问题:生产模式下,配置的东西通过什么可以看到

    我的想法(可能是错的)
    output.js对应的应该是webpack.development.config.js
    那么webpack.production.config.js有没有对应的文件?

    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 是我太轻敌了 普通会员 2楼

      The output.js file in a Vue CLI 3 project is responsible for serving and rendering the compiled JavaScript code, which is used by the Vue.js application. Here's an overview of what's contained in the output.js file:

      1. scripts: The scripts object in the output.js file contains the list of scripts generated by the Vue CLI. Each script represents a single build step or action that the Vue CLI takes to generate a production-ready JavaScript file. The scripts object is specified in the following format:

      javascript scripts: { build: 'vue build', serve: 'vue serve', devServer: 'vue-cli-service dev', test: 'vue-cli-service test', buildWebpack: { module: { rules: [ { test: /\.vue$/, loader: 'vue-loader', options: { babel: { presets: ['@vue/babel-preset-env', '@vue/babel-preset-react'], plugins: [ '@vue/babel-plugin-transform-runtime', 'transform-runtime', ['import', { commonjs2, commonjs }], ], }, }, }, { test: /\.js$/, loader: 'babel-loader', options: { presets: ['@vue/babel-preset-env', '@vue/babel-preset-react'], plugins: [ '@vue/babel-plugin-transform-runtime', 'transform-runtime', ['import', { commonjs2, commonjs }], ], }, }, ], }, }, }

      1. publicPath: The publicPath object specifies the base URL for static assets (images, stylesheets, etc.) generated by the Vue CLI. This is set to the output.publicPath property in the package.json file. By default, the publicPath is set to build/public:

      json "publicPath": "/dist/"

      However, if you're using a custom build process, you can override the publicPath property to specify a different URL for static assets:

      json "publicPath": "https://example.com/dist/"

      1. index.js: The index.js file is the entry point for the Vue.js application and serves as the entry point for the JavaScript file that's generated by the Vue CLI. This file defines the module exports and exports any required components or functions from the Vue module.

      Here's an example of what the index.js file might look like:

      ```javascript import Vue from 'vue'; import App from './App.vue'; import router from './router'; import { createApp } from '@vue/cli-service'; import 'vue-router/dist/vue-router.esm.js';

      const app = createApp(App); app.use(router); app.mount('#app');

      export default app; ```

      1. public/index.html: The public/index.html file is the HTML file that serves as the entry point for the Vue.js application. This file includes the Vue instance, the Vue Router instance, and any other JavaScript components or modules required by the application.

      Here's an example of what the public/index.html file might look like:

      ```html

      Vue.js App

      ```

      This public/index.html file includes a Vue instance, a Vue Router instance, and a reference to the index.js file that's generated by the Vue CLI. The public/index.html file is rendered by the Vue Router and is accessible to all pages of the application.

      1. package.json: The package.json file contains information about the Vue CLI project, including its dependencies and configuration options. The scripts section of the package.json file specifies the commands that the Vue CLI takes to build, serve, and run the application. The output section of the package.json file provides additional information about the build process, including the output directory, the public path, and the entry point.

      Here's an example of what the package.json file might look like:

      json { "name": "my-app", "version": "1.0.0", "description": "A Vue.js application", "main": "index.js", "scripts": { "build": "vue build", "serve": "vue serve", "devServer": "vue-cli-service dev", "test": "vue-cli-service test", "buildWebpack": { module: { rules: [ { test: /\.vue$/, loader: 'vue-loader', options: { babel: { presets: ['@vue/babel-preset-env', '@vue/babel-preset-react'], }, plugins: [ '@vue/babel-plugin-transform-runtime', 'transform-runtime', ['import', { commonjs2, commonjs }], ], }, }, { test: /\.js$/, loader: 'babel-loader', options: { presets: ['@vue/babel-preset-env', '@vue/babel-preset-react'], plugins: [ '@vue/babel-plugin-transform-runtime', 'transform-runtime', ['import', { commonjs2, commonjs }], ], }, }, ], }, }, "dependencies": { "vue": "^3.2.1", "vue-router": "^3.4.1", }, "devDependencies": { "@vue/cli-plugin-babel": "^3.2.0", "@vue/cli-plugin-eslint": "^3.2.0", "@vue/cli-plugin-router": "^3.4.0", "@vue/cli-plugin-vuex": "^3.4.0", "@vue/cli-service": "^3.2.0", "@vue/cli-plugin-tsc": "^3.2.0", "@vue/cli-plugin-webpack": "^3.2.0", "eslint": "^8.4.0", "vue-template-compiler": "^3.2.1", }, }, "keywords": ["vue", "framework", "js", "web", "frontend"], "author": "Your Name", "license": "MIT", }

      In this example, the package.json file specifies the following scripts:

      • build runs the vue build command to generate a production-ready JavaScript file, which is then minified and served to the browser.
      • serve runs the vue serve command to serve the application on the specified port (e.g., http://localhost:3000).
      • devServer runs the vue-cli-service dev command to serve the application on the development server (e.g., http://localhost:3001).
      • test runs the vue-cli-service test command to run the application's unit tests.
      • buildWebpack configures the build process to use the @vue/babel-preset-env preset, which applies the @vue/babel-preset-react preset to the JavaScript code. It also includes the @vue/babel-plugin-transform-runtime plugin to transpile runtime code (e.g., ES modules) into CommonJS modules, and the import plugin to import CommonJS modules from the main module.
      • dependencies: specifies the dependencies required by the Vue CLI application, including the Vue, Vue Router, and Vuex modules.
      • devDependencies: specifies the dependencies required by the Vue CLI development environment, including the @vue/cli-plugin-babel, @vue/cli-plugin-eslint, @vue/cli-plugin-router, @vue/cli-plugin-vuex, @vue/cli-service, @vue/cli-plugin-tsc, and @vue/cli-plugin-webpack plugins.
      • keywords: specifies a list of keywords that can be used to search for and filter the package, such as "vue", "framework", "js", "web", "frontend".
      • author: specifies the name of the project author.
      • license: specifies the license for the project, such as "MIT".
      • scripts: specifies the scripts that the Vue CLI takes to build, serve, and run the application, as well as the dependencies required by the development environment.
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部