Skip to content

bthtml/webpack4

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

webpack4.26.1

名称:

webpack4搭建多页面demo

webpack版本号:

4.26.1

填坑之旅

1.webpack4 Cannot find module '@babel/core'

原因"babel-loader": "^8.0.0" 版本问题。

使用"babel-loader": "^7.1.5"即可解决该错误。

2.extract-text-webpack-plugin插件提取单独打包css文件时,报错

原因webpack4改用mini-css-extract-plugin打包

const miniCssExtractPlugin = require("mini-css-extract-plugin");
    module: {
        rules: [
                    {
                test:/\.css$/,
                use:[
                    {
                        loader: 'style-loader',
                    },
                    {
                        loader: miniCssExtractPlugin.loader,
                        options:{
                            publicPath: '../'
                        }
                    },
                    'css-loader','postcss-loader'
                ]
            },
        ]
        }

3.html-webpack-plugin 中使用 title等选项设置模版中的值无效

原因html-loader与html-webpack-plugin冲突,html-loader直接把 <%= htmlWebpackPlugin.options.title %>解析成字符串

利用ejs模板的语法来动态插入各自页面的thunk和css样式可解决

4. postcss 配置不正确导致postcss-loader无效,无法自动添加css前缀

postcss.config.js的配置如下

module.exports = {
    plugins: [
        require('autoprefixer')({
            browsers: ['cover 99.5% in CN']
        })
    ]
}

About

webpack4多页面配置,生成html静态文件,清除dist,复制指定文件,打包分离css,自动添加css前缀,压缩css js

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors