Skip to content

Commit 2e9a3a8

Browse files
committed
refine build
1 parent cdebb5c commit 2e9a3a8

File tree

5 files changed

+213
-213
lines changed

5 files changed

+213
-213
lines changed

build/webpack.base.conf.js

Lines changed: 79 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,86 @@
1-
var path = require('path');
2-
var utils = require('./utils');
3-
var config = require('../config');
4-
var vueLoaderConfig = require('./vue-loader.conf');
1+
var path = require('path')
2+
var utils = require('./utils')
3+
var config = require('../config')
4+
var vueLoaderConfig = require('./vue-loader.conf')
55

66
function resolve(dir) {
7-
return path.join(__dirname, '..', dir)
7+
return path.join(__dirname, '..', dir)
88
}
9-
var src = path.resolve(__dirname, '../src');
109

1110
module.exports = {
12-
entry: {
13-
app: './src/main.js'
14-
},
15-
output: {
16-
path: config.build.assetsRoot,
17-
filename: '[name].js',
18-
publicPath: process.env.NODE_ENV !== 'development' ? config.build.assetsPublicPath: config.dev.assetsPublicPath
19-
},
20-
resolve: {
21-
extensions: ['.js', '.vue', '.json'],
22-
alias: {
23-
'vue$': 'vue/dist/vue.esm.js',
24-
'@': resolve('src'),
25-
'src': path.resolve(__dirname, '../src'),
26-
'assets': path.resolve(__dirname, '../src/assets'),
27-
'components': path.resolve(__dirname, '../src/components'),
28-
'views': path.resolve(__dirname, '../src/views'),
29-
'styles': path.resolve(__dirname, '../src/styles'),
30-
'api': path.resolve(__dirname, '../src/api'),
31-
'utils': path.resolve(__dirname, '../src/utils'),
32-
'store': path.resolve(__dirname, '../src/store'),
33-
'router': path.resolve(__dirname, '../src/router'),
34-
'mock': path.resolve(__dirname, '../src/mock'),
35-
'vendor': path.resolve(__dirname, '../src/vendor'),
36-
'static': path.resolve(__dirname, '../static')
11+
entry: {
12+
app: './src/main.js'
13+
},
14+
output: {
15+
path: config.build.assetsRoot,
16+
filename: '[name].js',
17+
publicPath: process.env.NODE_ENV !== 'development' ? config.build.assetsPublicPath : config.dev.assetsPublicPath
18+
},
19+
resolve: {
20+
extensions: ['.js', '.vue', '.json'],
21+
alias: {
22+
'vue$': 'vue/dist/vue.esm.js',
23+
'@': resolve('src'),
24+
'src': path.resolve(__dirname, '../src'),
25+
'assets': path.resolve(__dirname, '../src/assets'),
26+
'components': path.resolve(__dirname, '../src/components'),
27+
'views': path.resolve(__dirname, '../src/views'),
28+
'styles': path.resolve(__dirname, '../src/styles'),
29+
'api': path.resolve(__dirname, '../src/api'),
30+
'utils': path.resolve(__dirname, '../src/utils'),
31+
'store': path.resolve(__dirname, '../src/store'),
32+
'router': path.resolve(__dirname, '../src/router'),
33+
'mock': path.resolve(__dirname, '../src/mock'),
34+
'vendor': path.resolve(__dirname, '../src/vendor'),
35+
'static': path.resolve(__dirname, '../static')
36+
}
37+
},
38+
externals: {
39+
jquery: 'jQuery'
40+
},
41+
module: {
42+
rules: [
43+
// {
44+
// test: /\.(js|vue)$/,
45+
// loader: 'eslint-loader',
46+
// enforce: "pre",
47+
// include: [resolve('src'), resolve('test')],
48+
// options: {
49+
// formatter: require('eslint-friendly-formatter')
50+
// }
51+
// },
52+
{
53+
test: /\.vue$/,
54+
loader: 'vue-loader',
55+
options: vueLoaderConfig
56+
},
57+
{
58+
test: /\.js$/,
59+
loader: 'babel-loader?cacheDirectory',
60+
include: [resolve('src'), resolve('test')]
61+
},
62+
{
63+
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
64+
loader: 'url-loader',
65+
query: {
66+
limit: 10000,
67+
name: utils.assetsPath('img/[name].[hash:7].[ext]')
3768
}
38-
},
39-
externals: {
40-
jquery: 'jQuery'
41-
},
42-
module: {
43-
rules: [
44-
// {
45-
// test: /\.(js|vue)$/,
46-
// loader: 'eslint-loader',
47-
// enforce: "pre",
48-
// include: [resolve('src'), resolve('test')],
49-
// options: {
50-
// formatter: require('eslint-friendly-formatter')
51-
// }
52-
// },
53-
{ test: /\.vue$/,
54-
loader: 'vue-loader',
55-
options: vueLoaderConfig
56-
},
57-
{
58-
test: /\.js$/,
59-
loader: 'babel-loader?cacheDirectory',
60-
include: [resolve('src'), resolve('test')]
61-
},
62-
{
63-
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
64-
loader: 'url-loader',
65-
query: {
66-
limit: 10000,
67-
name: utils.assetsPath('img/[name].[hash:7].[ext]')
68-
}
69-
},
70-
{
71-
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
72-
loader: 'url-loader',
73-
query: {
74-
limit: 10000,
75-
name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
76-
}
77-
}
78-
]
79-
},
80-
//注入全局mixin
81-
// sassResources: path.join(__dirname, '../src/styles/mixin.scss'),
82-
// sassLoader: {
83-
// data: path.join(__dirname, '../src/styles/index.scss')
84-
// },
69+
},
70+
{
71+
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
72+
loader: 'url-loader',
73+
query: {
74+
limit: 10000,
75+
name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
76+
}
77+
}
78+
]
79+
},
80+
//注入全局mixin
81+
// sassResources: path.join(__dirname, '../src/styles/mixin.scss'),
82+
// sassLoader: {
83+
// data: path.join(__dirname, '../src/styles/index.scss')
84+
// },
8585
}
86+

build/webpack.dev.conf.js

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,39 +9,42 @@ var FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin')
99

1010
// add hot-reload related code to entry chunks
1111
Object.keys(baseWebpackConfig.entry).forEach(function (name) {
12-
baseWebpackConfig.entry[name] = ['./build/dev-client'].concat(baseWebpackConfig.entry[name])
12+
baseWebpackConfig.entry[name] = ['./build/dev-client'].concat(baseWebpackConfig.entry[name])
1313
})
1414

1515
function resolveApp(relativePath) {
16-
return path.resolve(relativePath);
16+
return path.resolve(relativePath);
1717
}
1818

1919
module.exports = merge(baseWebpackConfig, {
20-
module: {
21-
rules: utils.styleLoaders({sourceMap: config.dev.cssSourceMap})
22-
},
23-
// cheap-source-map is faster for development
24-
devtool: '#cheap-source-map',
25-
cache: true,
26-
plugins: [
27-
new webpack.DefinePlugin({
28-
'process.env': config.dev.env
29-
}),
30-
new webpack.ProvidePlugin({
31-
$: 'jquery',
32-
'jQuery': 'jquery'
33-
}),
34-
// https://github.com/glenjamin/webpack-hot-middleware#installation--usage
35-
new webpack.HotModuleReplacementPlugin(),
36-
new webpack.NoEmitOnErrorsPlugin(),
37-
// https://github.com/ampedandwired/html-webpack-plugin
38-
new HtmlWebpackPlugin({
39-
filename: 'index.html',
40-
template: 'index.html',
41-
favicon: resolveApp('favicon.ico'),
42-
inject: true,
43-
path:config.dev.staticPath
44-
}),
45-
new FriendlyErrorsPlugin()
46-
]
20+
module: {
21+
rules: utils.styleLoaders({
22+
sourceMap: config.dev.cssSourceMap
23+
})
24+
},
25+
// cheap-source-map is faster for development
26+
devtool: '#cheap-source-map',
27+
cache: true,
28+
plugins: [
29+
new webpack.DefinePlugin({
30+
'process.env': config.dev.env
31+
}),
32+
new webpack.ProvidePlugin({
33+
$: 'jquery',
34+
'jQuery': 'jquery'
35+
}),
36+
// https://github.com/glenjamin/webpack-hot-middleware#installation--usage
37+
new webpack.HotModuleReplacementPlugin(),
38+
new webpack.NoEmitOnErrorsPlugin(),
39+
// https://github.com/ampedandwired/html-webpack-plugin
40+
new HtmlWebpackPlugin({
41+
filename: 'index.html',
42+
template: 'index.html',
43+
favicon: resolveApp('favicon.ico'),
44+
inject: true,
45+
path: config.dev.assetsPublicPath + config.dev.assetsSubDirectory
46+
}),
47+
new FriendlyErrorsPlugin()
48+
]
4749
})
50+

0 commit comments

Comments
 (0)