Webpack不捆绑我的HTML文件
问题描述:
由于某些原因,我目前不明白,webpack不会将我的HTML文件捆绑到它生成的捆绑包中。它捆绑了其他所有东西,但遗憾的不是我的HTML文件。Webpack不捆绑我的HTML文件
我使用角2,已包括的依赖关系:
"html-loader": "^0.4.4",
"html-webpack-plugin": "^2.22.0",
的webpack.config:
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var helpers = require('./helpers');
module.exports = {
entry: {
app: 'app/main.ts'
},
output: {
path: helpers.root('dist'),
publicPath: 'http://localhost:8080/',
filename: 'bundle.js'
},
externals: [
{
'./node_modules/core-js/client/shim.min.js': 'shim',
'./node_modules/zone.js/dist/zone.js': 'zone',
'./node_modules/reflect-metadata/Reflect.js': 'reflect',
'./node_modules/x2js/x2js.js': 'x2js'
}
]
}
的webpack.common:
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var helpers = require('./helpers');
module.exports = {
entry: {
'app': './app/main.ts'
},
resolve: {
extensions: ['', '.js', '.ts', '.html']
},
module: {
loaders: [
{test: /\.ts$/, loaders: ['awesome-typescript-loader', 'angular2-template-loader']},
{test: /\.html$/, loader: 'raw-loader' },
{
test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico)$/,
loader: 'file?name=assets/[name].[hash].[ext]'
},
{
test: /\.css$/,
exclude: helpers.root('app'),
loader: ExtractTextPlugin.extract('style', 'css?sourceMap')
},
{
test: /\.css$/,
include: helpers.root('app'),
loader: 'raw'
}
]
},
plugins: [
new webpack.optimize.CommonsChunkPlugin({
name: ['app', 'vendor', 'polyfills']
}),
new HtmlWebpackPlugin({
template: 'index.html',
chunksSortMode: 'dependency'
})
]
};
而且webpack.prod:
var webpack = require('webpack');
var webpackMerge = require('webpack-merge');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var commonConfig = require('./webpack.common.js');
var helpers = require('./helpers');
module.exports = webpackMerge(commonConfig, {
devtool: 'source-map',
output: {
path: helpers.root('dist'),
publicPath: '/',
filename: '[name].[hash].js',
chunkFilename: '[id].[hash].chunk.js'
},
htmlLoader: {
minimize: false // workaround for ng2
},
plugins: [
new webpack.NoErrorsPlugin(),
new webpack.optimize.DedupePlugin(),
new ExtractTextPlugin('[name].[hash].css')
]
});
而且我通过拉在我的HTML在我的组件:
@Component({
....
template: require('app/customer-client/customer-client.html'),
....
)}
就从docs我所知,这应该是足够的,我认为,但我仍然失去了一些东西。
请注意,我也尝试使用raw-loader,这也未能捆绑HTML文件。我想知道导入的格式是否需要更接近“require(”html!./ file.html“);”所以我也尝试过,没有成功。我没有得到任何错误或任何调试信息,不幸的是我所有的都缺少HTML文件。有任何想法吗?
答
在您的webpack配置中,您是否也向resolve.extensions
阵列添加了“.html”?
resolve: {
extensions: ['.html', '.js', ....]
}
我没有,但不幸的是没有解决问题。我将编辑我的文章,以包含完整的webpack配置,尽管如此可以帮助:-)。 – jeeves90