• Welcome to the world's largest Chinese hacker forum

    Welcome to the world's largest Chinese hacker forum, our forum registration is open! You can now register for technical communication with us, this is a free and open to the world of the BBS, we founded the purpose for the study of network security, please don't release business of black/grey, or on the BBS posts, to seek help hacker if violations, we will permanently frozen your IP and account, thank you for your cooperation. Hacker attack and defense cracking or network Security

    business please click here: Creation Security  From CNHACKTEAM

Recommended Posts

const { resolve }=require(' path ');

const minicsetractplugin=require(' mini-CSS-extract-plugin ');

const optimizecsasssetswebpackplugin=require(' optimize-CSS-assets-web pack-plugin ');

const HtmlWebpackPlugin=require(' html-web pack-plugin ');

/*

树摇晃:去除无用代码

前提:1.必须使用ES6模块化2.开启生产环境

作用: 减少代码体积

在package.json中配置

副作用:错误所有代码都没有副作用(都可以进行树摇晃)

问题:可能会把css/@babel/polyfill(副作用)文件干掉

副作用:css ',' * .减去]

*/

//定义开发环境变量:决定使用浏览器列表的哪个环境

过程。环境。node _ ENV=' production

//复用装货设备

const commonCssLoader=[

MiniCssExtractPlugin.loader,

css-loader ',

{

//还需要在package.json中定义浏览器列表

loader: 'postcss-loader ',

选项: {

ident: 'postcss ',

插件:()=[require(' post CSS-preset-env ')()]

}

}

];

模块。导出={

条目:/src/js/index.js ',

输出: {

文件名: ' js/build.【content has :10 】. js ',

path: resolve(__dirname,“build”)

},

模块: {

规则: [

{

//在package.json中eslintConfig - airbnb

test: /\ .js$/,

exclude: /node_modules/,

//优先执行

enforce: 'pre ',

装载机: '装载机,

选项: {

fix: true

}

},

{

//以下装货设备只会匹配一个

//注意:不能有两个配置处理同一种类型文件

:之一[

{

test: /\ .css$/,

使用: [.commonCssLoader]

},

{

test: /\ .减去$/,

使用: [.commonCssLoader,' less-loader']

},

/*

正常来讲,一个文件只能被一个装货设备处理。

当一个文件要被多个装货设备处理,那么一定要指定装货设备执行的先后顺序:

先执行埃斯林特在执行巴别塔

*/

{

test: /\ .js$/,

exclude: /node_modules/,

装载机: '巴别塔装载机:

选项: {

presets: [

[

@babel/preset-env ',

{

'使用内置: '用法:

corejs:版本: 3 },

目标: {

铬: '60 ',

firefox: '50 '

}

}

]

],

//开启巴别塔缓存

//第二次构建时,会读取之前的缓存

cacheDirectory: true

}

},

{

test: /\ .(jpg|png|gif)/,

loader: 'url加载程序,

选项: {

limit: 8 * 1024,

名称:[哈希:10].[ext]',

输出路径: 'imgs ',

esModule:错误

}

},

{

test: /\ .html$/,

loader: 'html-loader '

},

{

不包括: /.(js|css|less|html|jpg|png|gif)/,

'装载机: '文件加载程序,

选项: {

输出路径: '媒体'

}

}

]

}

]

},

插件: [

新的minicsetractplugin({

文件名: ' CSS/build.【content hash :10 】.' CSS '

}),

新的OptimizeCssAssetsWebpackPlugin(),

新建HtmlWebpackPlugin({

模板: '。/src/index.html ',

minify: {

折叠空白:真,

removeComments: true

}

})

],

型号: '生产:

“开发工具:”源映射'

};

Link to comment
Share on other sites