Webpack

vue项目打包文件配置(vue-clli3)

为君一笑 提交于 2020-12-16 23:55:59
练手项目完结打包的时候遇到一些问题,特此记录 先贴我的vue.config.js文件的代码(vue-cli3构建的项目默认是没有此文件的,需手动添加)更多详细配置参考官方配置文档,我的项目不大不小,这些配置貌似就够了 module.exports = { // webpack配置,此处是因为我的项目打包时报错(WARNING in asset size limit: The following asset(s) exceed the recommended size limit ,因此有了这个webpack配置,若不存在静态资源过大,可不要这部分代码) configureWebpack: { // 警告 webpack 的性能提示 performance: { hints: 'warning' , // 入口起点的最大体积 maxEntrypointSize: 50000000 , // 生成文件的最大体积 maxAssetSize: 30000000 , // 只给出 js 文件的性能提示 assetFilter: function (assetFilename) { return assetFilename.endsWith('.js' ); } } }, baseUrl: './' , // 1.默认为 "/":部署在一个域名的根路径上 ; 2. "./"

UglifyJS中文文档

烂漫一生 提交于 2020-12-16 10:36:12
UglifyJS是JavaScript解析器,缩小器,压缩器和美化器工具箱。 由于webpack本身集成了UglifyJS插件(webpack.optimize.UglifyJsPlugin),其命令 webpack -p 即表示调用UglifyJS来压缩代码,还有不少webpack插件如 html-webpack-plugin 也会默认使用UglifyJS。 与UglifyJS2相比API变动较大,简化较多,文档也增加了不少示例。 由于webpack本身集成了UglifyJS插件(webpack.optimize.UglifyJsPlugin),其命令 webpack -p 即表示调用UglifyJS来压缩代码,还有不少webpack插件如 html-webpack-plugin 也会默认使用UglifyJS。因此我们其实经常要用到它,但UglifyJS本身配置较复杂/选项繁多,又没有中文文档,使用起来如坠云雾。鉴于此特翻译此文,谬误甚多,敬请斧正。 词典: parse 解释 compress 压缩 mangle 混淆 beautify 美化 minify 最小化 CLI 命令行工具 sourcemap 编译后代码对源码的映射,用于网页调试 AST 抽象语法树 name 名字,包括变量名、函数名、属性名 toplevel 顶层作用域 unreachable 不可达代码

前端图片压缩调研

一世执手 提交于 2020-12-15 09:22:59
概述 最近做项目思考了一下前端图片压缩问题,有一些小的心得,记录下来,供以后开发时参考,相信对其他人也有用。下面按优先级列出了 前端图片压缩的解决方案 。 webpack 现在前端项目都是利用webpack打包,所以我调研了一下在webpack里面压缩图片的解决方案,主要使用基于imagemin插件的 imagemin-webpack-plugin插件 。 首先安装imagemin-webpack-plugin插件: npm install imagemin-webpack-plugin 然后在 webpack配置 中添加如下配置,就可以在项目打包的时候自动压缩图片了。 var ImageminPlugin = require('imagemin-webpack-plugin').default module.exports = { plugins: [ // Make sure that the plugin is after any plugins that add images new ImageminPlugin({ test: /\.(jpe?g|png|gif|svg)$/i, disable: process.env.NODE_ENV !== 'production', // Disable during development pngquant: { quality

After build via Webpack 5 app stoped working on Internet Explorer (IE11)

依然范特西╮ 提交于 2020-12-15 06:09:01
问题 As announced in Webpacks 5.0 release blog post build still works in most browsers after a few minor adjustments in webpack.config.js . But it stopped working in Internet Explorer (11) because the generated output is mixed ES6 and ES5 and therefore incompatible with IE (see image). As it actually leads to no successful build using a variety of babel plugins I'm asking myself if theres an "easy" way to specify ES5 as the generated output. From beta phase of webpack-5 I found a flag on Medium

After build via Webpack 5 app stoped working on Internet Explorer (IE11)

删除回忆录丶 提交于 2020-12-15 06:07:01
问题 As announced in Webpacks 5.0 release blog post build still works in most browsers after a few minor adjustments in webpack.config.js . But it stopped working in Internet Explorer (11) because the generated output is mixed ES6 and ES5 and therefore incompatible with IE (see image). As it actually leads to no successful build using a variety of babel plugins I'm asking myself if theres an "easy" way to specify ES5 as the generated output. From beta phase of webpack-5 I found a flag on Medium

Module build failed Cannot find module '@babel/preset-env'

帅比萌擦擦* 提交于 2020-12-15 05:19:19
问题 I was working on my react application with set up babel. Unfortunately while setting it up using yarn and when I build my bundle.js file, I run into some problems: ERROR in ./src/app.js Module build failed (from ./node_modules/babel-loader/lib/index.js): Error: Cannot find module '@babel/preset-env' from '/Users/react-file/Desktop/indecision' at Function.resolveSync [as sync] (/Users/react-file/Desktop/indecision/node_modules/resolve/lib/sync.js:89:15) at resolveStandardizedName (/Users/react

Webpack build or TypeScript is creating JS files right in my SRC

对着背影说爱祢 提交于 2020-12-15 04:31:17
问题 I don't undrestand what's doing this. This doesn't seem normal right? I am getting a .js file generated for every .tsx or .ts file after I build but this shouldn't be in my source . I should only see .js files in my build obviously. My Scripts "start": "PORT=3000 nodemon --trace-warnings --experimental-json-modules --no-warnings dist/server/server.js", "build": "NODE_ENV=production yarn lint && yarn copyData && yarn compile-server && yarn start & webpack -p --env=prod --watch", "dev": "NODE

Webpack build or TypeScript is creating JS files right in my SRC

ぐ巨炮叔叔 提交于 2020-12-15 04:31:13
问题 I don't undrestand what's doing this. This doesn't seem normal right? I am getting a .js file generated for every .tsx or .ts file after I build but this shouldn't be in my source . I should only see .js files in my build obviously. My Scripts "start": "PORT=3000 nodemon --trace-warnings --experimental-json-modules --no-warnings dist/server/server.js", "build": "NODE_ENV=production yarn lint && yarn copyData && yarn compile-server && yarn start & webpack -p --env=prod --watch", "dev": "NODE

以太坊开发去中心化投票DApp与智能合约实例

时间秒杀一切 提交于 2020-12-13 19:38:26
在整个加密货币市场的市值超过7000亿美元之后,加密货币市场在过去几个月太疯狂了,但这只是一个开始。随着区块链系统的不断发展和扩展,进入这一新领域并利用这项技术的一个好方法是使用去中心化应用程序,也称为dApps。 CryptoKitties 以其使以太坊区块链拥挤而闻名,是dApp的一个很好的例子,它将可养殖和可收藏的概念与区块链相结合。这个耸人听闻的游戏只是一个创造性的例子,几乎有无限的机会。 虽然看似非常复杂,但已经开发出某些框架和工具来抽象你与区块链和智能合约的交互。在这篇博文中,我将通过一种方式在以太坊上创建一个去中心化的投票应用程序。我将简要介绍以太坊,但你可能应该对它有所了解,以便充分利用本指南。另外,我希望你知道Javascript。 为什么要开发去中心化投票应用? 从本质上讲,利用区块链技术的去中心化应用程序允许你在没有可信赖的第三方的情况下执行与今天相同的操作(如转移资金)。最好的dApp具有特定的真实世界的用例,以便利用区块链的独特特征。 从本质上讲,区块链是一个共享的,可编程的,加密安全的,可信赖的分类账本,没有任何一个用户可以控制,任何人都可以查询。- Klaus Schwab 即使投票应用对大家来说可能不是一个伟大的应用程序,但是我选择使用它作为本指南,这是因为区块链解决的主要问题:透明度,安全性,可访问性,可信任,是困扰当前民主选举的主要问题。

Pass webpack (environment) variable to scss file

社会主义新天地 提交于 2020-12-13 17:52:24
问题 Very new to webpack... I would like to be able to read a value, in this case specifically the value of env from webpack.config.js in a sass file, so I can have different css based on environment. For example: env = development, colour = green env = production, colour = blue So far I have focoused on sass-loader, trying to pass data, but has not worked, the $env variable is always undefined when i run npm run build:Debug (this runs webpack --app=all --env=development ). These are the files I