programing

npm을 실행하는 경우 빌드 실행 시 VUE에서 build.js 파일만 생성

prostudy 2022. 5. 23. 21:28
반응형

npm을 실행하는 경우 빌드 실행 시 VUE에서 build.js 파일만 생성

npm 빌드를 실행하면 dist 디렉토리에 build.js만 생성되며 이것은 내 패키지다.json 및 내 웹 팩 구성.웹 팩의 구성 또는 패키지 구성에 문제가 있는지 여부 알 수 없는 경우

꾸러미json

    {
  "name": "humanspiral-front",
  "description": "Human Spiral Image Generator Front End",
  "version": "1.0.0",
  "author": "Isaac Laurrabaquio <marcodeleonmx@gmail.com>",
  "license": "MIT",
  "private": true,
  "scripts": {
    "dev": "cross-env NODE_ENV=development webpack-dev-server --open --hot",
    "build": "cross-env NODE_ENV=production webpack --progress --hide-modules --mode production"
  },
  "dependencies": {
    "axios": "^0.19.0",
    "vue": "^2.5.11"
  },
  "browserslist": [
    "> 1%",
    "last 2 versions",
    "not ie <= 8"
  ],
  "devDependencies": {
    "babel-core": "^6.26.0",
    "babel-loader": "^7.1.2",
    "babel-preset-env": "^1.6.0",
    "babel-preset-stage-3": "^6.24.1",
    "copy-webpack-plugin": "^4.0.3",
    "cross-env": "^5.0.5",
    "css-loader": "^0.28.7",
    "file-loader": "^1.1.4",
    "uglifyjs-webpack-plugin": "^2.1.3",
    "vue-loader": "^14.2.2",
    "vue-template-compiler": "^2.4.4",
    "webpack": "^4",
    "webpack-cli": "^3.3.6",
    "webpack-dev-server": "^3"
  }
}

웹 팩 구성 파일.

var path = require('path')
var webpack = require('webpack')
const TerserPlugin = require('terser-webpack-plugin');

module.exports = {
  mode: 'production',
  entry: path.resolve(__dirname,'./src/main.js'),
  output: {
    path: path.resolve(__dirname, './dist'),
    publicPath: './static',
    filename: 'build.js'
  },
  module: {
    rules: [
      {
        test: /\.css$/,
        use: [
          'vue-style-loader',
          'css-loader'
        ],
      },      {
        test: /\.vue$/,
        loader: 'vue-loader',
        options: {
          loaders: {
          }
          // other vue-loader options go here
        }
      },
      {
        test: /\.js$/,
        loader: 'babel-loader',
        exclude: /node_modules/
      },
      {
        test: /\.(png|jpg|gif|svg)$/,
        loader: 'file-loader',
        options: {
          name: '[name].[ext]?[hash]'
        }
      }
    ]
  },
  resolve: {
    alias: {
      'vue$': 'vue/dist/vue.esm.js'
    },
    extensions: ['*', '.js', '.vue', '.json']
  },
  devServer: {
    historyApiFallback: true,
    noInfo: true,
    overlay: true
  },
  performance: {
    hints: false
  },
  devtool: '#eval-source-map'
}

if (process.env.NODE_ENV === 'production') {
  module.exports.devtool = '#source-map'
  // http://vue-loader.vuejs.org/en/workflow/production.html
  module.exports.plugins = (module.exports.plugins || []).concat([
    new webpack.DefinePlugin({
      'process.env': {
        NODE_ENV: '"production"'
      }
    }),
    new webpack.LoaderOptionsPlugin({
      minimize: true
    })
  ])
  module.exports.optimization = {
      minimizer: [new TerserPlugin()],
      minimize: true
  }
}

서버에 배포할 모든 파일을 생성해야 하지만 빌드.js만 생성해야 함

참조URL: https://stackoverflow.com/questions/57116564/when-i-run-npm-run-build-only-generate-a-build-js-file-on-vue

반응형