Skip to content

Instantly share code, notes, and snippets.

@SunKing2
Created May 18, 2017 19:30
Show Gist options
  • Save SunKing2/8b23efb06d3396aaf1a27f9fc3c0ac89 to your computer and use it in GitHub Desktop.
Save SunKing2/8b23efb06d3396aaf1a27f9fc3c0ac89 to your computer and use it in GitHub Desktop.
# custom loaders for webpack : taken from chriserin at:
# https://til.hashrocket.com/posts/6750cdfffd-custom-loaders-for-webpack
mkdir tmp
cd tmp
cat > index.html <<EOL
<body>
<script src="bundle.js"></script>
</body>
EOL
cat > main.js <<EOL
document.write('<h2>written by my dumb program main.js</h2>')
EOL
cat > smart-loader.js<<EOL
module.exports = function(source) {
return source.replace('dumb', 'smart')
}
EOL
cat > webpack.config.js<<EOL
module.exports = {
entry: './main.js',
output: {
filename: 'bundle.js'
},
module: {
rules: [
{
test: /\.js$/,
use: './smart-loader'
}
]
}
}
EOL
webpack
firefox index.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment