最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

babel7.x和webpack4.x配置vue項(xiàng)目的方法步驟

 更新時間:2019年05月12日 10:10:17   作者:洛卿九  
這篇文章主要介紹了babel7.x和webpack4.x配置vue項(xiàng)目的方法步驟,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

很偶然的今天想開個自己的小項(xiàng)目,記錄一下最近項(xiàng)目工程上實(shí)現(xiàn)的一個小交互。按照之前運(yùn)行非常流暢的配置走一遍,打包遇到各種坑。只好根據(jù)命令行的報(bào)錯逐個排查,發(fā)現(xiàn)babel升級了一個大版本,已經(jīng)到7.x了??磥砻咳粘撩皂?xiàng)目,已經(jīng)跟不上節(jié)奏了。這里記錄一下遇到的問題以及解決方案。

1.webpack 4.x 插件 extract-text-webpack-plugin

(node:2628) DeprecationWarning: Tapable.plugin is deprecated. Use new API on `.hooks` instead
i 「wds」: Project is running at http://localhost:8300/
i 「wds」: webpack output is served from /
i 「wds」: Content not from webpack is served from F:\private\plugin-insert\dist
F:\private\plugin-insert\node_modules\webpack\lib\Chunk.js:838
        throw new Error(
        ^

Error: Chunk.entrypoints: Use Chunks.groupsIterable and filter by instanceof Entrypoint instead
  at Chunk.get (F:\private\plugin-insert\node_modules\webpack\lib\Chunk.js:838:9)
  at F:\private\plugin-insert\node_modules\extract-text-webpack-plugin\dist\index.js:176:48
  at Array.forEach (<anonymous>)
  at F:\private\plugin-insert\node_modules\extract-text-webpack-plugin\dist\index.js:171:18
  at AsyncSeriesHook.eval [as callAsync] (eval at create (F:\private\plugin-insert\node_modules\tapable\lib\HookCodeFactory.js:32:10), <anonymous>:7:1)
  at AsyncSeriesHook.lazyCompileHook (F:\private\plugin-insert\node_modules\tapable\lib\Hook.js:154:20)
  at Compilation.seal (F:\private\plugin-insert\node_modules\webpack\lib\Compilation.js:1231:27)
  at hooks.make.callAsync.err (F:\private\plugin-insert\node_modules\webpack\lib\Compiler.js:541:17)
  at _done (eval at create (F:\private\plugin-insert\node_modules\tapable\lib\HookCodeFactory.js:32:10), <anonymous>:9:1)
  at _err1 (eval at create (F:\private\plugin-insert\node_modules\tapable\lib\HookCodeFactory.js:32:10), <anonymous>:32:22)

extract-text-webpack-plugin 提取單獨(dú)打包c(diǎn)ss文件時報(bào)錯,官方安裝部分的文檔只寫到了webpack 3,目前還沒有webpack 4版本,可以使用 extract-text-webpack-plugin@next 解決,也可以使用 mini-css-extract-plugin 。

mini-css-extract-plugin 插件用法如下:

const MiniCssExtractPlugin = require("mini-css-extract-plugin") ;

const config = module.exports = {

   plugins: [
     new MiniCssExtractPlugin({
      filename: "[name].[chunkhash:8].css",
       chunkFilename: "[id].css"
      })
   ],

   module: {
    rules: [
      {
      test: /\.css$/,
      use: [
         MiniCssExtractPlugin.loader,
          "css-loader"
       ]
     }
    ]
    }
}

module.exports = config

2.babel 升級 6.x 到 7.x

(1) @babel/core

Module build failed (from ./node_modules/babel-loader/lib/index.js):
Error: Cannot find module '@babel/core'
 babel-loader@8 requires Babel 7.x (the package '@babel/core'). 
 If you'd like to use Babel 6.x ('babel-core'), you should install 'babel-loader@7'.

沒找到 @babel/core ,這里把 babel-core 卸載,并安裝 @babel/core 。

npm un babel-core
npm i -D @babel/core

(2) @babel/preset-*

Module build failed (from ./node_modules/babel-loader/lib/index.js):
Error: Plugin/Preset files are not allowed to export objects, only functions.

將 babel-preset-* 卸載,重新安裝 @babel/preset-* ,并且修改 .babelrc 中的 presets

npm:
- babel-preset-env
+ @babel/perset-env

.babelrc:
- "presets": ["env"]
+ "presets": ["@babel/preset-env"]

另,stage-*已棄用

(3) @babel/plugin-*

Module build failed (from ./node_modules/babel-loader/lib/index.js):
TypeError: this.setDynamic is not a function
  at PluginPass.pre
  ...

這次是插件了,一樣把babel-plugin-*卸載,重新安裝@babel/plugin-*

然后修改.babelrc文件

具體的包名可以在 npm倉庫 里找

(4) 最終文件

.babelrc
{
  "presets": ["@babel/preset-env"],
  "plugins": [
      "@babel/plugin-transform-runtime"
  ]
}

package.json
"devDependencies": {
  "@babel/core": "^7.1.2",
  "@babel/plugin-transform-runtime": "^7.1.0",
  "@babel/preset-env": "^7.1.0",
  "babel-loader": "^8.0.4",
  
  ...
 },
"dependencies": {
  "@babel/runtime": "^7.1.2",
  "vue": "^2.5.17",
  "vue-loader": "^15.4.2",
  "vue-router": "^3.0.1",
  "vuex": "^3.0.1",
  "webpack": "^4.22.0",
  "webpack-cli": "^3.1.2",
  "webpack-dev-server": "^3.1.10",
  "webpack-merge": "^4.1.4"
  ...
 }

(5) 總結(jié)

babel 舍棄了以前的 babel-*-* 的命名方式,改成了 @babel/*-*

修改依賴和 .babelrc 文件后就能正常啟動項(xiàng)目了。

3.vue-loader 15.x vueLoaderPlugin

vue-loader was used without the corresponding plugin. 
Make sure to include VueLoaderPlugin in your webpack config.
//兩個方式都可以的,隨便用一個

const VueLoaderPlugin = require('vue-loader/lib/plugin');

// 或者 

const { VueLoaderPlugin } = require('vue-loader');


plugins: [
  // make sure to include the plugin for the magic
  new VueLoaderPlugin()
]

詳細(xì) https://github.com/vuejs/vue-loader/issues/1238

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Vue3中使用qrcode庫實(shí)現(xiàn)二維碼生成

    Vue3中使用qrcode庫實(shí)現(xiàn)二維碼生成

    Vue3中實(shí)現(xiàn)二維碼生成需要使用第三方庫來處理生成二維碼的邏輯,常用的庫有?qrcode和?vue-qrcode,本文主要介紹了Vue3中使用qrcode庫實(shí)現(xiàn)二維碼生成,感興趣的可以了解一下
    2023-12-12
  • Vue?基于?vuedraggable?實(shí)現(xiàn)選中、拖拽、排序效果

    Vue?基于?vuedraggable?實(shí)現(xiàn)選中、拖拽、排序效果

    這篇文章主要介紹了Vue?基于?vuedraggable?實(shí)現(xiàn)選中、拖拽、排序效果,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-05-05
  • vue自定義組件@click點(diǎn)擊失效問題及解決

    vue自定義組件@click點(diǎn)擊失效問題及解決

    這篇文章主要介紹了vue自定義組件@click點(diǎn)擊失效問題及解決方案,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-04-04
  • vue-model實(shí)現(xiàn)簡易計(jì)算器

    vue-model實(shí)現(xiàn)簡易計(jì)算器

    這篇文章主要為大家詳細(xì)介紹了vue-model實(shí)現(xiàn)簡易計(jì)算器,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-08-08
  • vue.js根據(jù)代碼運(yùn)行環(huán)境選擇baseurl的方法

    vue.js根據(jù)代碼運(yùn)行環(huán)境選擇baseurl的方法

    本篇文章主要介紹了vue.js根據(jù)代碼運(yùn)行環(huán)境選擇baseurl的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-02-02
  • vue 2.8.2版本配置剛進(jìn)入時候的默認(rèn)頁面方法

    vue 2.8.2版本配置剛進(jìn)入時候的默認(rèn)頁面方法

    今天小編就為大家分享一篇vue 2.8.2版本配置剛進(jìn)入時候的默認(rèn)頁面方法,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-09-09
  • element?Drawer?抽屜無法渲染問題及解決

    element?Drawer?抽屜無法渲染問題及解決

    這篇文章主要介紹了element?Drawer?抽屜無法渲染問題及解決,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-10-10
  • elementui導(dǎo)出數(shù)據(jù)為xlsx、excel表格

    elementui導(dǎo)出數(shù)據(jù)為xlsx、excel表格

    本文主要介紹了elementui導(dǎo)出數(shù)據(jù)為xlsx、excel表格,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-09-09
  • vue+elemet實(shí)現(xiàn)表格手動合并行列

    vue+elemet實(shí)現(xiàn)表格手動合并行列

    這篇文章主要為大家詳細(xì)介紹了vue+elemet實(shí)現(xiàn)表格手動合并行列,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-08-08
  • Vue實(shí)現(xiàn)無限加載瀑布流

    Vue實(shí)現(xiàn)無限加載瀑布流

    這篇文章主要為大家詳細(xì)介紹了Vue實(shí)現(xiàn)無限加載瀑布流,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-11-11

最新評論

兖州市| 新田县| 江阴市| 台中市| 邵东县| 姜堰市| 太和县| 秀山| 博野县| 江川县| 梅州市| 梅州市| 炉霍县| 勃利县| 仁怀市| 石城县| 靖边县| 通辽市| 平乐县| 尼玛县| 富阳市| 任丘市| 启东市| 南昌县| 岳阳市| 丰原市| 弥渡县| 茂名市| 保靖县| 阳谷县| 仙桃市| 焦作市| 扬中市| 高州市| 玛纳斯县| 鸡泽县| 四会市| 出国| 石泉县| 塔河县| 富阳市|