久久久精品一区ed2k-女人被男人叉到高潮的视频-中文字幕乱码一区久久麻豆樱花-俄罗斯熟妇真实视频

vue.js中怎么根據(jù)不同環(huán)境打包到不同目錄

這期內(nèi)容當(dāng)中小編將會給大家?guī)碛嘘P(guān)vue.js中怎么根據(jù)不同環(huán)境打包到不同目錄,文章內(nèi)容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。

成都創(chuàng)新互聯(lián)專業(yè)為企業(yè)提供泗縣網(wǎng)站建設(shè)、泗縣做網(wǎng)站、泗縣網(wǎng)站設(shè)計、泗縣網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計與制作、泗縣企業(yè)網(wǎng)站模板建站服務(wù),十余年泗縣做網(wǎng)站經(jīng)驗,不只是建網(wǎng)站,更提供有價值的思路和整體網(wǎng)絡(luò)服務(wù)。

1、在build文件夾中創(chuàng)建testing.js文件

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

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

module.exports = {
 NODE_ENV: '"production"',
 // 將上文設(shè)置的環(huán)境變量,賦值到 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這個命令復(fù)制一份改成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文件

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

復(fù)制代碼 代碼如下:

rm(path.join(process.env.type == '"testing"' ? config.testing.assetsRoot : config.build.assetsRoot, process.env.type == '"testing"' ? config.testing.assetsSubDirectory : config.build.assetsSubDirectory), err => {

7、根據(jù)不同環(huán)境配置不同域名地址

let baseURL
if (process.env.NODE_ENV === 'production') {
 if (process.env.type === 'testing') { // 測試環(huán)境
  baseUrl = '測試環(huán)境地址'
 } else {               // 正式環(huán)境
  baseUrl = '正式環(huán)境地址'
 }
} else {                // 本地環(huán)境
 baseUrl = '本地環(huán)境地址'
}

最后執(zhí)行:

npm run testing 就會執(zhí)行測試環(huán)境配置的地址,并生成testing文件夾
npm run build就會執(zhí)行正式環(huán)境配置的地址,并生成dist文件夾

上述就是小編為大家分享的vue.js中怎么根據(jù)不同環(huán)境打包到不同目錄了,如果剛好有類似的疑惑,不妨參照上述分析進行理解。如果想知道更多相關(guān)知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。

當(dāng)前標(biāo)題:vue.js中怎么根據(jù)不同環(huán)境打包到不同目錄
網(wǎng)站路徑:http://sd-ha.com/article48/jgiphp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供商城網(wǎng)站、微信公眾號、軟件開發(fā)、電子商務(wù)、關(guān)鍵詞優(yōu)化、用戶體驗

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

h5響應(yīng)式網(wǎng)站建設(shè)