很偶然的今天想开个自己的小项目,记录一下最近项目工程上实现的一个小交互。按照之前运行非常流畅的配置走一遍,打包遇到各种坑。只好根据命令行的报错逐个排查,发现babel升级了一个大版本,已经到7.x了。看来每日沉迷项目,已经跟不上节奏了。这里记录一下遇到的问题以及解决方案。
1.webpack 4.x 插件 extract-text-webpack-plugin
(node:2628) DeprecationWarning: Tapable.plugin is deprecated. Use new API on `.hooks` insteadi 「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/distF:/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 提取单独打包css文件时报错,官方安装部分的文档只写到了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'.
新闻热点
疑难解答
图片精选