-
UglifyJsPlugin 現在預設內建在 webpack 了,但沒有 export, 如果只需要調整設定值,設定
.optimization.minimize
和.optimization.minimizer
即可, 如果需要加上 OptimizeCssAssetsPlugin,要另外npm install
+require
再塞回minimizer
-
CommonsChunkPlugin 不能用了,由
.optimization.splitChunks
取代。預設應該不錯用... 最簡單的自定就是寫test: /vendors|node_modules/
。如果有多個 entry 的話,可以先把 maxInitialRequests 調到 10,避免看不出效果,然後再視效果調整。如果有用mini-css-extracting-webpack-plugin
(下稱 MCE) 的話,要注意使用 function 型式的 test, 因為這個 plugin 會把module.resource
拔掉,請參考 webpack 裡的lib/optimize/SplitChunksPlugin.js
的checkTest
。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
plugins: [ | |
new CleanWebpackPlugin(), | |
new CopyWebpackPlugin([{ from: './src/components/', to: './components/' }]), | |
new CopyWebpackPlugin([{ from: './public/', to: './' }]), | |
new CopyWebpackPlugin([ | |
{ from: './node_modules/@fortawesome/fontawesome-free/webfonts/', to: './assets/webfonts/' }, | |
]), | |
new MiniCssExtractPlugin({ | |
filename: 'assets/styles/[name].[hash:8].css', | |
chunkFilename: 'assets/styles/[id].[hash:8].css', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo apt install libnss3 libxcomposite1 libxrender1 libx11-xcb1 libxcursor1 libxdamage1 libxi6 \ | |
libxtst6 libxss1 libasound2 libpangocairo-1.0-0 libpango-1.0-0 libpangocairo-1.0-0 libpango-1.0-0 libatk1.0-0 libatk-bridge2.0-0 \ | |
libcups2 libxrandr2 libgtk-3.0 libgdk-pixbuf2.0-0 \ | |
fonts-noto-cjk # for cjk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Suite = require('benchmark').Suite | |
const suite = new Suite() | |
const spaces = new Array(10000).fill(' ').join('') | |
const s = 'foo' + spaces + 'bar' + spaces + 'baz' | |
suite.add('regular expression', () => { | |
/(foo).*(bar).*(baz)/.test('foo bar baz') | |
}) | |
.add('look-ahead expresssion', () => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Suite = require('benchmark').Suite | |
const suite = new Suite() | |
suite.add('regular expression', () => { | |
/(foo).*(bar).*(baz)/.test('foo bar baz') | |
}) | |
.add('look-ahead expresssion', () => { | |
/(?=.*foo)(?=.*bar)(?=.*baz)/.test('foo bar baz') | |
}) | |
.add('multiple indexOf', () => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(() => { | |
const headers = document.querySelectorAll('h2'); | |
for (const el of headers) { | |
el.id = el.textContent; | |
} | |
const links = Array.from(headers, el => el.textContent) | |
.map(t => `<li><a href="#${t}">${t}</a></li>`) | |
.join(''); | |
document.body.insertAdjacentHTML('afterbegin', `<ul>${links}</ul>`); | |
})(); |
I hereby claim:
- I am redeyes2015 on github.
- I am redeyes2015 (https://keybase.io/redeyes2015) on keybase.
- I have a public key whose fingerprint is 8BDA AB44 68DC 6465 F931 E373 ECD3 066F 0B0F 2D8B
To claim this, I am signing this object:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Promise.all([ | |
frag1, | |
frag2 | |
]) | |
.then(function (results) { | |
return results.map(function (htmlFrag) { | |
return document.createNodeIterator(htmlFrag, NodeFilter.SHOW_ALL, { | |
acceptNode: function (node) { | |
// TEXT_NODE && only_space | |
if (node.nodeType === 3 && /^\s*$/.test(node.data)) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// JavaScript is a prototype-based language which contains no class statement | |
function makeAddressWith(streetno, streetaddress, city, state, country, pincode) { | |
return { | |
streetno: streetno , | |
streetaddress: streetaddress, | |
city: city, | |
state: state, | |
country: country, | |
pincode: pincode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(){ | |
var a = { rein: true } | |
var foo = function(){ | |
if(this.rein) console.log('!') | |
else console.log('fooo') | |
}; | |
var bar = function(){ | |
console.log(this.rein); | |
foo() | |
}; |