webpack.base.conf.js
3.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
var path = require('path');
var config = require('../config');
var utils = require('./utils');
var projectRoot = path.resolve(__dirname, '../');
var webpack = require('webpack');
var env = process.env.NODE_ENV
// check env & config/index.js to decide weither to enable CSS Sourcemaps for the
// various preprocessor loaders added to vue-loader at the end of this file
var cssSourceMapDev = (env === 'development' && config.dev.cssSourceMap)
var cssSourceMapProd = (env === 'production' && config.build.productionSourceMap)
var useCssSourceMap = cssSourceMapDev || cssSourceMapProd
module.exports = {
entry: {
main : config.build.entry,
},
output: {
path: config.build.assetsRoot,
publicPath: process.env.NODE_ENV === 'production' ? config.build.assetsPublicPath : config.dev.assetsPublicPath,
filename: '[name].js'
},
resolve: {
extensions: ['', '.js', '.vue'],
fallback: [path.join(__dirname, '../node_modules')],
alias: {
'vue$': 'vue/dist/vue.common.js',
'src': path.resolve(__dirname, '../src'),
'assets': path.resolve(__dirname, '../src/assets'),
'components': path.resolve(__dirname, '../src/components')
},
modulesDirectories: ["web_modules", "node_modules", "bower_components"],
},
resolveLoader: {
fallback: [path.join(__dirname, '../node_modules')]
},
module: {
preLoaders: [
// {
// test: /\.vue$/,
// loader: 'eslint',
// include: projectRoot,
// exclude: /node_modules/
// },
// {
// test: /\.js$/,
// loader: 'babel-loader!eslint-loader',
// include: projectRoot,
// exclude: /node_modules/
// }
],
loaders: [
{ test: /\.js$/, loader: 'babel',include: projectRoot, exclude: /node_modules/ },
{ test: /\.json$/, loader: 'json' },
// less语法转化
{ test: /\.less$/, loader: 'style!css!less' },
// stylus语法转化
{ test: /\.styl$/, loader: 'style-loader!css-loader!stylus-loader' },
// 编译css并自动添加css前缀
{ test: /\.css$/, loader: "style!css" },
{ test: /\.vue$/, loader: 'vue' },
{ test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
loader: 'url',
query: {
limit: 10000,
name: utils.assetsPath('img/[name].[hash:7].[ext]')
}
},
{
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
loader: 'url',
query: {
limit: 10000,
name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
}
}
]
},
eslint: {
// formatter: require('eslint-friendly-formatter')
},
vue: {
//loaders: utils.cssLoaders({ sourceMap: useCssSourceMap }),
postcss: [
require('autoprefixer')({
browsers: ['last 2 versions']
})
],
loaders: [
// less语法转化
{ test: /\.less$/, loader: 'vue-style-loader!css-loader!less-loader' },
// stylus语法转化
{ test: /\.styl$/, loader: 'vue-style-loader!css-loader!stylus-loader' },
// 编译css并自动添加css前缀
{ test: /\.css$/, loader: "vue-style-loader!css-loader" },
// postcss转化
{ test: /\.postcss$/, loader: "vue-style-loader!css-loader" },
{ test: /\.sass$/, loader: "vue-style!css!sass" }
]
},
plugins : [
//new webpack.ResolverPlugin.DirectoryDescriptionFilePlugin(".bower.json", ["main"])
],
babel: {
presets: ['es2015'],
plugins: ['transform-runtime']
}
}