国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

詳解vue.js根據不同環境(正式、測試)打包到不同目錄

2024-05-06 15:32:42
字體:
來源:轉載
供稿:網友

1、在build文件夾中創建testing.js文件

// 配置環境變量 type 為 testingprocess.env.type = '"testing"'// 引入build.js文件require('./build')

2、修改config文件夾中的prod.env.js文件

module.exports = { NODE_ENV: '"production"', // 將上文設置的環境變量,賦值到 type 屬性上 type: process.env.type}

3、在package.json文件中添加npm run testing命令

"testing": "node build/testing.js", // 添加testing命令"build": "node build/build.js"

4、config ->index.js中把build這個命令復制一份改成testing(此步為了打包到不同文件夾)

build: {  env: require('./prod.env'),  // Template for index.html  index: path.resolve(__dirname, '../dist/index.html'),  // Paths  assetsRoot: path.resolve(__dirname, '../dist'),  assetsSubDirectory: 'static',  assetsPublicPath: '/mshop/',  /**   * Source Maps   */  productionSourceMap: true,  // https://webpack.js.org/configuration/devtool/#production  devtool: '#source-map',  // Gzip off by default as many popular static hosts such as  // Surge or Netlify already gzip all static assets for you.  // Before setting to `true`, make sure to:  // npm install --save-dev compression-webpack-plugin  productionGzip: false,  productionGzipExtensions: ['js', 'css'],  // Run the build command with an extra argument to  // View the bundle analyzer report after build finishes:  // `npm run build --report`  // Set to `true` or `false` to always turn it on or off  bundleAnalyzerReport: process.env.npm_config_report }, testing: {  env: require('./prod.env'),  index: path.resolve(__dirname, '../testing/index.html'),  assetsRoot: path.resolve(__dirname, '../testing'),  assetsSubDirectory: 'static',  assetsPublicPath: '/',  productionSourceMap: true,  // Gzip off by default as many popular static hosts such as  // Surge or Netlify already gzip all static assets for you.  // Before setting to `true`, make sure to:  // npm install --save-dev compression-webpack-plugin  productionGzip: false,  productionGzipExtensions: ['js', 'css'],  // Run the build command with an extra argument to  // View the bundle analyzer report after build finishes:  // `npm run build --report`  // Set to `true` or `false` to always turn it on or off  bundleAnalyzerReport: process.env.npm_config_report },

5、修改build->webpack.prod.conf文件

修改filename

new HtmlWebpackPlugin({   filename: process.env.type == '"testing"' ? config.testing.index : config.build.index  }),

修改output

  output: {  path: process.env.type == '"testing"' ? config.testing.assetsRoot : config.build.assetsRoot, },

6、修改build->build.js文件

路徑都修改為根據正式、測試環境判斷(不然執行npm run testing, npm run build命令時輸出的文件有問題)

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 修水县| 凤山县| 青冈县| 台北县| 夹江县| 城市| 庆阳市| 建始县| 泾川县| 庄浪县| 酒泉市| 乌海市| 文化| 郯城县| 古蔺县| 汕头市| 霍城县| 南通市| 仪陇县| 虞城县| 武定县| 济宁市| 牟定县| 凤山县| 张北县| 南江县| 金湖县| 桓仁| 德令哈市| 邯郸县| 岗巴县| 达拉特旗| 岳普湖县| 阿巴嘎旗| 镇远县| 颍上县| 夏津县| 苍梧县| 长丰县| 余姚市| 阳原县|