webpack upgrade stepped pit

webpack3.8.1 => webpack4.39.2

1、error:webpack is not a function

fix scripts/start.js
const compiler = createCompiler(webpack, config, appName, urls, useYarn);
=>
const compiler = createCompiler({ webpack, config, appName, urls, useYarn });

2、error: this.htmlWebpackPlugin.getHooks is not a function

fix config/webpack.config.*.js
new InterpolateHtmlPlugin(env.raw),
=>
new InterpolateHtmlPlugin(HtmlWebpackPlugin,env.raw),

3, abandoned ExtractTextPlugin => as mini-css-extract-plugin

{
            test: /\.(css|less)$/,
            use: [
                {
                    loader: MiniCssExtractPlugin.loader,
                },
                {
                    loader: require.resolve('css-loader'),
                    options: {
                      importLoaders: 1,
                      sourceMap: shouldUseSourceMap,
                    },
                },
                {
                    loader: require.resolve('postcss-loader'),
                    options: {
                      // Necessary for external CSS imports to work
                      // https://github.com/facebookincubator/create-react-app/issues/2677
                      ident: 'postcss',
                      plugins: () => [
                        require('postcss-flexbugs-fixes'),
                        autoprefixer({
                          browsers: [
                            '>1%',
                            'last 4 versions',
                            'Firefox ESR',
                            'not ie < 9', // React doesn't support IE8 anyway
                          ],
                          flexbox: 'no-2009',
                        }),
                      ],
                    },
                },
                {
                    loader: require.resolve('less-loader'),
                    options: {
                        modifyVars: antdtheme,
                        javascriptEnabled: true
                    },
                },
            ]
          },

4、error: Chunk.initial was removed. Use canBeInitial/isOnlyInitial() at Chunk.get initial

Workaround: Upgrade "webpack-manifest-plugin": "^ 1.3.2" to "webpack-manifest-plugin": "^ 2.0.4"

5、warning:Tapable.plugin is deprecated. Use new API on .hooks instead

This warning message states that the use of a plugin loader or abandoned api, but does not affect packaged compilation.
To determine who issued a warning by acquiring stracktrace:
process.traceDeprecation = to true;

Guess you like

Origin www.cnblogs.com/hideonbush/p/11415851.html