-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
111 lines (106 loc) · 2.74 KB
/
webpack.config.js
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
110
111
const webpack = require('webpack')
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const merge = require('webpack-merge')
const validate = require('webpack-validator')
import { parts, utils } from './client/webpack'
const projectRoot = __dirname
const PATHS = {
app: path.resolve(__dirname, './client/entry.js'),
build: path.join(__dirname, './public')
};
const common = {
entry: {
app: PATHS.app,
vendor: ['vue', 'vue-router', 'vuex']
},
output: {
path: PATHS.build,
publicPath: '/',
filename: 'assets/js/[name].js'
},
resolve: {
extensions: ['.js', '.vue', '.json', '.css'],
alias: {
// https://github.com/vuejs/vue/wiki/Vue-2.0-RC-Starter-Resources
// vue: 'vue/dist/vue',
src: path.resolve(__dirname, '../client'),
libs: path.resolve(__dirname, '../client/libs'),
views: path.resolve(__dirname, '../client/views'),
package: path.resolve(__dirname, '../package.json'),
assets: path.resolve(__dirname, '../client/assets'),
components: path.resolve(__dirname, '../client/components'),
// vue-addon
'vuex-store': path.resolve(__dirname, '../client/store')
}
},
module: {
// loaders: [
// { test: /\.css$/, loader: 'style-loader!css-loader' }
// ],
rules: [{
test: /\.css$/,
use: [
'style-loader',
'css-loader'
]
},
{
test: /\.vue$/,
loader: 'vue-loader'
},
{
test: /\.json$/,
loader: 'json-loader'
},
{
test: /\.js$/,
loader: 'babel-loader',
include: projectRoot,
exclude: /node_modules/
},
{
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 10000,
//name: utils.assetsPath('img/[name].[hash:7].[ext]')
name: 'assets/img/[name].[hash:7].[ext]'
}
},
{
test: /\.(woff2?|eot|svg|ttf|otf)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 10000,
name: 'assets/fonts/[name].[hash:7].[ext]'
}
}
]
},
plugins: [
new webpack.BannerPlugin('This file is created by zjl'),
new HtmlWebpackPlugin({ title: 'mywiki' }),
new webpack.LoaderOptionsPlugin({
vue: {
loaders: utils.cssLoaders({
sourceMap: false,
extract: false
})
}
}),
]
};
let config;
// Detect how npm is run and branch based on that
switch (process.env.npm_lifecycle_event) {
case 'build':
config = merge(common, {});
break;
default:
config = merge(common, parts.devServer({
host: process.env.HOST,
port: process.env.PORT
}));
}
module.exports = validate(config);