2016-09-09 14:29:19 +08:00
|
|
|
|
/**
|
|
|
|
|
* 本地预览
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
var path = require('path');
|
|
|
|
|
var webpack = require('webpack');
|
2017-03-01 13:11:58 +08:00
|
|
|
|
var ExtractTextPlugin = require('extract-text-webpack-plugin');
|
2017-03-01 13:56:01 +08:00
|
|
|
|
var HtmlWebpackPlugin = require('html-webpack-plugin');
|
2016-09-09 14:29:19 +08:00
|
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
|
// 入口
|
|
|
|
|
entry: {
|
2016-10-28 10:09:07 +08:00
|
|
|
|
main: './test/main',
|
2016-09-09 14:29:19 +08:00
|
|
|
|
vendors: ['vue', 'vue-router']
|
|
|
|
|
},
|
|
|
|
|
// 输出
|
|
|
|
|
output: {
|
2016-10-28 10:27:44 +08:00
|
|
|
|
path: path.join(__dirname, '../test/dist'),
|
2017-03-01 13:56:01 +08:00
|
|
|
|
publicPath: '',
|
2016-09-09 14:29:19 +08:00
|
|
|
|
filename: '[name].js',
|
|
|
|
|
chunkFilename: '[name].chunk.js'
|
|
|
|
|
},
|
|
|
|
|
// 加载器
|
|
|
|
|
module: {
|
2017-03-01 10:31:17 +08:00
|
|
|
|
// https://doc.webpack-china.org/guides/migrating/#module-loaders-module-rules
|
|
|
|
|
rules: [
|
|
|
|
|
{
|
|
|
|
|
// https://vue-loader.vuejs.org/en/configurations/extract-css.html
|
|
|
|
|
test: /\.vue$/,
|
|
|
|
|
loader: 'vue-loader',
|
|
|
|
|
options: {
|
|
|
|
|
loaders: {
|
2017-03-01 11:35:00 +08:00
|
|
|
|
css: 'vue-style-loader!css-loader',
|
|
|
|
|
less: 'vue-style-loader!css-loader!less-loader'
|
2017-03-01 10:31:17 +08:00
|
|
|
|
},
|
|
|
|
|
postLoaders: {
|
|
|
|
|
html: 'babel-loader'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
// { test: /\.vue$/, loader: 'vue' },
|
|
|
|
|
// Module build failed: Error: The node API for `babel` has been moved to `babel-core`.
|
|
|
|
|
// https://github.com/babel/babel-loader/blob/master/README.md#the-node-api-for-babel-has-been-moved-to-babel-core
|
|
|
|
|
{
|
|
|
|
|
test: /\.js$/,
|
|
|
|
|
loader: 'babel-loader', exclude: /node_modules/
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
test: /\.css$/,
|
|
|
|
|
use: [
|
|
|
|
|
'style-loader',
|
|
|
|
|
'css-loader',
|
|
|
|
|
'autoprefixer-loader'
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
test: /\.less$/,
|
|
|
|
|
use: [
|
|
|
|
|
'style-loader',
|
|
|
|
|
'css-loader',
|
|
|
|
|
'less-loader'
|
|
|
|
|
]
|
|
|
|
|
// loader: 'style!css!less'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
test: /\.scss$/,
|
|
|
|
|
use: [
|
|
|
|
|
'style-loader',
|
|
|
|
|
'css-loader',
|
|
|
|
|
'sass-loader?sourceMap'
|
|
|
|
|
]
|
|
|
|
|
// loader: 'style!css!sass?sourceMap'
|
|
|
|
|
},
|
2016-09-09 14:29:19 +08:00
|
|
|
|
{ test: /\.(gif|jpg|png|woff|svg|eot|ttf)\??.*$/, loader: 'url-loader?limit=8192'},
|
|
|
|
|
{ test: /\.(html|tpl)$/, loader: 'html-loader' }
|
|
|
|
|
]
|
|
|
|
|
},
|
2017-03-01 10:31:17 +08:00
|
|
|
|
// vue: {
|
|
|
|
|
// loaders: {
|
|
|
|
|
// css: ExtractTextPlugin.extract(
|
|
|
|
|
// "style-loader",
|
|
|
|
|
// "css-loader?sourceMap",
|
|
|
|
|
// {
|
|
|
|
|
// publicPath: "/test/dist/"
|
|
|
|
|
// }
|
|
|
|
|
// ),
|
|
|
|
|
// less: ExtractTextPlugin.extract(
|
|
|
|
|
// 'vue-style-loader',
|
|
|
|
|
// 'css-loader!less-loader'
|
|
|
|
|
// ),
|
|
|
|
|
// js: 'babel'
|
|
|
|
|
// }
|
|
|
|
|
// },
|
2016-09-09 14:29:19 +08:00
|
|
|
|
resolve: {
|
|
|
|
|
// require时省略的扩展名,如:require('module') 不需要module.js
|
2017-03-01 10:31:17 +08:00
|
|
|
|
extensions: ['.js', '.vue'],
|
2016-09-09 14:29:19 +08:00
|
|
|
|
alias: {
|
2017-03-01 10:31:17 +08:00
|
|
|
|
iview: '../../src/index',
|
|
|
|
|
vue: 'vue/dist/vue.js'
|
2016-09-09 14:29:19 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
plugins: [
|
2017-03-01 13:56:01 +08:00
|
|
|
|
// new ExtractTextPlugin({ filename: '[name].css', disable: false, allChunks: true }),
|
|
|
|
|
// new ExtractTextPlugin("[name].css",{ allChunks : true,resolve : ['modules'] }), // 提取CSS
|
2017-03-01 10:31:17 +08:00
|
|
|
|
// https://doc.webpack-china.org/plugins/commons-chunk-plugin/
|
2017-03-01 13:56:01 +08:00
|
|
|
|
new webpack.optimize.CommonsChunkPlugin({ name: 'vendors', filename: 'vendor.bundle.js' }),
|
|
|
|
|
new HtmlWebpackPlugin({
|
|
|
|
|
inject: true,
|
|
|
|
|
filename: path.join(__dirname, '../test/dist/index.html'),
|
|
|
|
|
template: path.join(__dirname, '../test/index.html') // 模版文件
|
|
|
|
|
})
|
|
|
|
|
// new webpack.optimize.CommonsChunkPlugin('vendors', 'vendors.js'), // 提取第三方库
|
2016-09-09 14:29:19 +08:00
|
|
|
|
]
|
2016-10-28 10:27:44 +08:00
|
|
|
|
};
|