webpack配置上線地址
阿新 • • 發佈:2017-09-12
fig webpack blog round entry plugin web npm param
webpack配置上線地址主要使用output配置項下的publicPath。
webpack.config.js配置文件為:
var htmlWebpackPlugin = require(‘html-webpack-plugin‘);
module.exports = {
//打包入口
entry: {
main: ‘./src/js/main.js‘,
a: ‘./src/js/a.js‘
},
//打包後的文件
output: {
//不加__dirname 會報錯
path: __dirname + ‘/dist‘,
//註意:使用[name]確保每個文件名都不重復
filename: ‘js/[name]-[chunkhash].js‘,
//線上地址配置
publicPath:‘http://cdn.com/‘
},
plugins: [
new htmlWebpackPlugin({
template: ‘index.html‘,
filename: ‘index-[hash].html‘,
title: ‘test parameter‘
})
]
}
執行命令:
npm run webpack
效果:
(1)項目目錄輸出結構:
(2)html 引用地址為線上地址:
webpack配置上線地址