11 2021 档案
摘要:配置只第一次加载需要引入的第三方包 提升打包性能 npm install add-asset-html-webpack-plugin --save const addAssetHtmlWebpackPlugin = require('add-asset-html-webpack-plugin') /
阅读全文
摘要:npm install webpack-cli@3.1.2 webpack@4.25.1 --save-dev npm install ts-loader@5.3.2 typescript@3.2.2 --save-dev 根目录下 创建 tsconfig.json { "compilerOptio
阅读全文
摘要:环境变量的使用 "scripts": { "dev-build": "webpack --config ./build/webpack.common.js", "dev": "webpack-dev-server --config ./build/webpack.common.js", "build
阅读全文
摘要:shimming plugins:[ new htmlWebpackPligin({ template:`./src/index.html` }), new cleanWebpackPligin(['dist'],{ root: path.resolve(__dirname,'../') }), /
阅读全文
摘要:contenthash 配置解决js缓存的问题 optimization:{ runtimeChunk:{ name: 'runtime' }, usedExports:true, splitChunks:{ chunks:"all" , cacheGroups:{ vendors: { test:
阅读全文
摘要:css 代码分割 "sideEffects": ["*.css"], npm install --save-dev mini-css-extract-plugin@0.5.0 const miniCssExtractPlugin = require('mini-css-extract-plugin'
阅读全文
摘要:// 配置 js 代码分割 // 第一种 entry:{ // lodash:'./src/lodash.js' , main:'./src/index.js' }, // 第二种 optimization:{ splitChunks:{ chunks:"all" } }, plugins:[] /
阅读全文
摘要:// 合并开发 环境 配置区分打包 npm install webpack-merge@4.1.5 -D package.json "scripts": { "dev": "webpack-dev-server --config ./build/webpack.dev.js", "build": "
阅读全文
摘要:配置 tree shaking plugins:[ ], // 增加这个 (开发环境下 增加, 线上环境不用增加) // optimization:{ // usedExports: true // }, devServer:{ } package.json "name": "webpack4",
阅读全文
摘要:// 配置 babel es6 语法转成 es5 npm install --save-dev babel-loader @babel/core npm install @babel/preset-env --save-dev npm install --save @babel/polyfill n
阅读全文
摘要:// 配置 source-map 快速定位js代码错误位置 // 开发配置 // mode:'development', // development || production // source-map->会生成单独的 .map 文件 // inline-source-map 不会生成单独的 .
阅读全文
摘要:// 配置 entry 和 output entry:{ main:'./src/index.js', // sub:'./src/index.js' }, output:{ // filename: 'dist.js', // publicPath:'http:///www.cdn.com', /
阅读全文
摘要:// 自动生成 html 文件 npm install html-webpack-plugin@3.2.0 -D const htmlWebpackPligun = require('html-webpack-plugin') plugins:[ new htmlWebpackPligun({ te
阅读全文
摘要:// 打包字体文件 { test:/\.(woff2|woff|ttf)$/, use:{ loader:'file-loader' } } ,
阅读全文
摘要:// { // test:/\.css$/, // use:['style-loader','css-loader'] // } , { test:/\.scss$/, use:[ 'style-loader', // 'css-loader', { loader:'css-loader', opt
阅读全文
摘要:// 打包文件图片url-loader // url-loader 可以配置是否生成 base64 格式图片 npm install url-loader -D rules:[ { test:/\.(jpg|png|gif)$/, use:{ loader: 'url-loader', option
阅读全文
摘要:// 复制文本 function copyText(text){ // 数字没有 .length 不能执行selectText 需要转化成字符串 const textString = text.toString(); let input = document.querySelector('#copy
阅读全文

浙公网安备 33010602011771号