rosen老師,我用webpack-dev-server啟動后訪問頁面,index.html 頁面引入的公共模塊都無法解析,<!DOCTYPE?html>
<html>
????<head>?
????????<%=?require('html-loader!./layout/head-common.html')%>
????????<title><%=?htmlWebpackPlugin.options.title%>?-?happymmall電商平臺</title>
????</head>
????<body>
????????<%=?require('html-loader!./layout/nav.html')??%>
????????<%=?require('html-loader!./layout/header.html')??%>
????????<%=?require('html-loader!./layout/footer.html')??%>
????????
????</body>
</html>在通過webpack打包到dist目錄下后,這些文件是可以被解析的,我的webpack配置是var?webpack?????????????=?require('webpack');
var?ExtractTextPlugin???=?require('extract-text-webpack-plugin');
var?HtmlWebpackPlugin???=?require('html-webpack-plugin');
//?環(huán)境變量配置,dev?/?online
var?WEBPACK_ENV?????????=?process.env.WEBPACK_ENV?||?'dev';
//?獲取html-webpack-plugin參數(shù)的方法?
var?getHtmlConfig?=?function(name){
????return?{
????????template????:?'./src/view/'?+?name?+?'.html',
????????filename????:?'view/'?+?name?+?'.html',
????????//?title???????:?title,
????????inject??????:?true,
????????hash????????:?true,
????????chunks??????:?['common',?name]
????};
};
//?webpack?config
var?config?=?{
????devtool:?'eval-source-map',
????entry:?{
????????'common'????????????:?['./src/page/common/index.js'],
????????'index'?????????????:?['./src/page/index/index.js'],
????????'user-login'????????:?['./src/page/user-login/index.js'],
???????
????},
????output:?{
????????path:?'./dist',
????????publicPath?:?'/dist',
????????filename:?'js/[name].js'
????},
????externals?:?{
????????'jquery'?:?'window.jQuery'
????},
????module:?{
????????loaders:?[
????????????{?test:?/\.css$/,?loader:?ExtractTextPlugin.extract("style-loader","css-loader")?},
????????????{?test:?/\.(gif|png|jpg|woff|svg|eot|ttf)\??.*$/,?loader:?'url-loader?limit=100&name=/resource/[name].[ext]'?},
????????????{?test:?/\.string$/,?loader:?'html-loader'}
????????]
????},
????//?resolve?:?{
????//?????alias?:?{
????//?????????node_modules????:?__dirname?+?'/node_modules',
????//?????????util????????????:?__dirname?+?'/src/util',
????//?????????page????????????:?__dirname?+?'/src/page',
????//?????????service?????????:?__dirname?+?'/src/service',
????//?????????image???????????:?__dirname?+?'/src/image'
????//?????}
????//?},
????plugins:?[
????????//?獨立通用模塊到j(luò)s/base.js
????????new?webpack.optimize.CommonsChunkPlugin({
????????????name?:?'common',
????????????filename?:?'js/base.js'
????????}),
????????//?把css單獨打包到文件里
????????new?ExtractTextPlugin("css/[name].css"),
????????//?html模板的處理
????????new?HtmlWebpackPlugin(getHtmlConfig('index')),
????????new?HtmlWebpackPlugin(getHtmlConfig('login')),
????]
};
if('dev'?===?WEBPACK_ENV){
????config.entry.common.push('webpack-dev-server/client?http://localhost:8088/');
}
module.exports?=?config;packge.json 配置文件是? "dependencies": {? ? "font-awesome": "^4.7.0",? ? "hogan": "^1.0.2",? ? "html-webpack-plugin": "^2.28.0"? },? "devDependencies": {? ? "css-loader": "^0.28.1",? ? "extract-text-webpack-plugin": "^1.0.1",? ? "file-loader": "^0.11.1",? ? "html-loader": "^0.4.5",? ? "style-loader": "^0.17.0",? ? "url-loader": "^0.5.8",? ? "webpack": "^1.15.0",? ? "webpack-dev-server": "^1.16.5"? }麻煩老師看下
webpack-dev-server啟動后,頁面無法解析公共模塊頁面
rrbaby520
2017-08-30 22:27:57