Dưới đây là cấu hình webpack của tôi:html-webpack-plugin không tiêm js nộp vào index.html khi sử dụng webpack-dev-server
var path = require('path');
var webpack = require('webpack')
var HtmlWebpackPlugin = require('html-webpack-plugin')
var fs = require('fs'),buildPath='./dist/';
var folder_exists = fs.existsSync(buildPath);
if(folder_exists == true)
{
require('shelljs/global')
rm('-rf', 'dist')
};
module.exports = {
entry: './src/main',
output: {
path: path.join(__dirname, './dist'),
filename: '[name].js',
publicPath: '/dist/'
},
devServer: {
historyApiFallback: true,
hot: false,
inline: true,
grogress: true,
},
// "vue-hot-reload-api": "^1.2.2",
module: {
loaders: [
{ test: /\.vue$/, loader: 'vue' },
{ test: /\.js$/, loader: 'babel', exclude: /node_modules/ },
{ test: /\.css$/, loader: 'style-loader!css-loader'},
//install css-loader style-loader sass-loader node-sass --save-dev
{ test: /\.scss$/, loader: 'style!css!sass?sourceMap'},
{ test: /\.(png|jpg|gif)$/, loader: 'url-loader?limit=8192&name=images/[name].[ext]'},
{ test: /\.(html|tpl)$/, loader: 'html-loader' },
]
},
vue: {
loaders: {
js:'babel',
css: 'style-loader!css-loader',
sass:'style!css!sass?sourceMap'
}
},
babel: {
presets: ['es2015'],
plugins: ['transform-runtime']
},
plugins:[
new HtmlWebpackPlugin({
template: 'index.html',
filename: './index.html',
inject:true
}),
],
resolve: {
extensions: ['', '.js', '.vue'],
alias: {
filter: path.join(__dirname, './src/filters'),
components: path.join(__dirname, './src/components')
}
},
devtool: 'eval-source-map'
};
Và trong package.json:
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "webpack-dev-server --inline",
"build": "webpack --config webpack.config.prod.js"
},
Khi Tôi chạy npm bắt đầu, trong localhost file js không được tiêm trong index.html
. Nếu tôi chạy webpack hoặc npm run build, tệp js được tiêm thành công. Có thể html-webpack-plugin
cũng đưa tệp js vào index.html
khi tôi đang ở trong máy chủ cục bộ không?
Sẽ https://github.com/jantimon/html-webpack-harddisk-plugin giúp đỡ ? – jantimon
Cảm ơn @jantimon trường hợp sử dụng của tôi là khá chuyên biệt kể từ khi tôi chạy tất cả mọi thứ bên trong container docker (webpack vv vv). đang sử dụng webpack để xây dựng dự án Vuejs của tôi mà không cần phải cài đặt nút vv trên môi trường cục bộ của tôi. Tôi đã không thử các plugin như vấn đề của tôi đã kết thúc nói chung là một vấn đề khái niệm về những gì tôi mong đợi từ WDS vv – Necevil