Skip to content

Instantly share code, notes, and snippets.

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',
@redeyes2015
redeyes2015 / apt.sh
Created December 18, 2018 06:46
Dependencies for Chromium headless (609904)
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
@redeyes2015
redeyes2015 / index2.js
Created November 27, 2018 03:11
Matching several things (in no particular order) against longer string
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', () => {
@redeyes2015
redeyes2015 / index.js
Created November 27, 2018 03:04
Matching several things (in no particular order)
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', () => {
(() => {
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>`);
})();
@redeyes2015
redeyes2015 / webpack3-to-4.md
Last active September 13, 2018 06:37
Webpack 3 to 4
  • 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.jscheckTest

Keybase proof

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:

@redeyes2015
redeyes2015 / gist:361e355a685ba2e5a6cac9badf4659bc
Last active September 22, 2016 07:22
Compare two documentFragment with NodeIterator
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)) {
// 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
(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()
};