Last active
March 16, 2020 03:15
-
-
Save fstanis/773110b12d91f42d3c3a22b71cbf6c42 to your computer and use it in GitHub Desktop.
Webpack HTML entry
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title></title> | |
<link rel="stylesheet" href="./style.css"> | |
</head> | |
<body> | |
<img src="./img/icon.png"> | |
<button id="test">Test</button> | |
<!-- this file must be named index.js for the spawn-loader with the current config --> | |
<script src="./index.js"></script> | |
<!-- | |
alternative for extra files: | |
<script src="${require('spawn-loader!other.js')}"></script> | |
make sure interpolate: true is set in the config | |
--> | |
</body> | |
</html> |
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 path = require('path'); | |
const ExtractTextPlugin = require('extract-text-webpack-plugin'); | |
module.exports = { | |
output: { | |
filename: 'index.html', | |
path: path.resolve(__dirname, 'dist') | |
}, | |
entry: ['./src/index.html'], | |
module: { | |
rules: [ | |
{ | |
test: /\.html$/, | |
use: ExtractTextPlugin.extract({ | |
loader: 'html-loader', | |
options: { | |
// uncomment this if you want files other than index.js to be entries via ${require(spawn-loader!...)} | |
//interpolate: true, | |
attrs: [ | |
'link:href', | |
'script:src', | |
'img:src' | |
] | |
} | |
}) | |
}, | |
{ | |
test: /\.css$/, | |
use: [ | |
'file-loader', | |
'extract-loader', | |
'css-loader' | |
] | |
}, | |
{ | |
test: /\/index\.js$/, | |
exclude: /(node_modules|bower_components)/, | |
use: { | |
loader: 'spawn-loader', | |
options: { | |
name: '[hash].js' | |
} | |
} | |
}, | |
{ | |
test: /\.(jpg|png)$/, | |
use: 'file-loader' | |
} | |
] | |
}, | |
plugins: [ | |
new ExtractTextPlugin('index.html') | |
] | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment