Created
May 18, 2017 19:30
-
-
Save SunKing2/8b23efb06d3396aaf1a27f9fc3c0ac89 to your computer and use it in GitHub Desktop.
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
# 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