Skip to content

Commit 26697b6

Browse files
committed
update webpack config. Closed #231
1 parent c3fda09 commit 26697b6

File tree

8 files changed

+61
-27
lines changed

8 files changed

+61
-27
lines changed

Vue_Full_Project/build/utils.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ exports.cssLoaders = function (options) {
1616
loader: 'css-loader',
1717
options: {
1818
minimize: process.env.NODE_ENV === 'production',
19-
sourceMap: options.sourceMap
19+
sourceMap: options.sourceMap,
20+
alias: { '../img': '../static/img' }
2021
}
2122
}
2223

Vue_Full_Project/build/webpack.base.conf.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,24 @@ module.exports = {
4848
},
4949
{
5050
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
51-
loader: 'url-loader',
52-
options: {
53-
limit: 10000,
54-
name: utils.assetsPath('img/[name].[hash:7].[ext]')
51+
use: {
52+
loader: 'file-loader',
53+
options: {
54+
name: '[name].[hash:7].[ext]',
55+
publicPath: '../../',
56+
outputPath: utils.assetsPath('img/')
57+
}
5558
}
5659
},
5760
{
58-
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
59-
loader: 'url-loader',
60-
options: {
61-
limit: 10000,
62-
name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
61+
test: /\.(woff2?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
62+
use: {
63+
loader: 'file-loader',
64+
options: {
65+
name: '[name].[hash:7].[ext]',
66+
publicPath: '../../',
67+
outputPath: utils.assetsPath('fonts/')
68+
}
6369
}
6470
}
6571
]

Vue_Full_Project/build/webpack.dev.conf.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
var path = require('path')
12
var utils = require('./utils')
23
var webpack = require('webpack')
34
var config = require('../config')
45
var merge = require('webpack-merge')
56
var baseWebpackConfig = require('./webpack.base.conf')
7+
var CopyWebpackPlugin = require('copy-webpack-plugin')
68
var HtmlWebpackPlugin = require('html-webpack-plugin')
79
var FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin')
810

@@ -30,6 +32,14 @@ module.exports = merge(baseWebpackConfig, {
3032
template: 'index.html',
3133
inject: true
3234
}),
33-
new FriendlyErrorsPlugin()
35+
new FriendlyErrorsPlugin(),
36+
// copy custom static assets
37+
new CopyWebpackPlugin([
38+
{
39+
from: path.resolve(__dirname, '../static'),
40+
to: config.build.assetsSubDirectory,
41+
ignore: ['.*']
42+
}
43+
])
3444
]
3545
})

Vue_Full_Project/config/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module.exports = {
77
index: path.resolve(__dirname, '../dist/index.html'),
88
assetsRoot: path.resolve(__dirname, '../dist'),
99
assetsSubDirectory: 'static',
10-
assetsPublicPath: '/',
10+
assetsPublicPath: './',
1111
productionSourceMap: true,
1212
// Gzip off by default as many popular static hosts such as
1313
// Surge or Netlify already gzip all static assets for you.
@@ -26,7 +26,7 @@ module.exports = {
2626
port: 8080,
2727
autoOpenBrowser: true,
2828
assetsSubDirectory: 'static',
29-
assetsPublicPath: '/',
29+
assetsPublicPath: '',
3030
proxyTable: {},
3131
// CSS Sourcemaps off by default because relative paths are "buggy"
3232
// with this option, according to the CSS-Loader README

Vue_Starter/build/utils.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ exports.cssLoaders = function (options) {
1616
loader: 'css-loader',
1717
options: {
1818
minimize: process.env.NODE_ENV === 'production',
19-
sourceMap: options.sourceMap
19+
sourceMap: options.sourceMap,
20+
alias: { '../img': '../static/img' }
2021
}
2122
}
2223

@@ -50,7 +51,7 @@ exports.cssLoaders = function (options) {
5051
postcss: generateLoaders(),
5152
less: generateLoaders('less'),
5253
sass: generateLoaders('sass', { indentedSyntax: true }),
53-
scss: generateLoaders('sass'),
54+
scss: generateLoaders('sass'),
5455
stylus: generateLoaders('stylus'),
5556
styl: generateLoaders('stylus')
5657
}

Vue_Starter/build/webpack.base.conf.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,24 @@ module.exports = {
4848
},
4949
{
5050
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
51-
loader: 'url-loader',
52-
options: {
53-
limit: 10000,
54-
name: utils.assetsPath('img/[name].[hash:7].[ext]')
51+
use: {
52+
loader: 'file-loader',
53+
options: {
54+
name: '[name].[hash:7].[ext]',
55+
publicPath: '../../',
56+
outputPath: utils.assetsPath('img/')
57+
}
5558
}
5659
},
5760
{
58-
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
59-
loader: 'url-loader',
60-
options: {
61-
limit: 10000,
62-
name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
61+
test: /\.(woff2?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
62+
use: {
63+
loader: 'file-loader',
64+
options: {
65+
name: '[name].[hash:7].[ext]',
66+
publicPath: '../../',
67+
outputPath: utils.assetsPath('fonts/')
68+
}
6369
}
6470
}
6571
]

Vue_Starter/build/webpack.dev.conf.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
var path = require('path')
12
var utils = require('./utils')
23
var webpack = require('webpack')
34
var config = require('../config')
45
var merge = require('webpack-merge')
56
var baseWebpackConfig = require('./webpack.base.conf')
7+
var CopyWebpackPlugin = require('copy-webpack-plugin')
68
var HtmlWebpackPlugin = require('html-webpack-plugin')
79
var FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin')
810

@@ -30,6 +32,14 @@ module.exports = merge(baseWebpackConfig, {
3032
template: 'index.html',
3133
inject: true
3234
}),
33-
new FriendlyErrorsPlugin()
35+
new FriendlyErrorsPlugin(),
36+
// copy custom static assets
37+
new CopyWebpackPlugin([
38+
{
39+
from: path.resolve(__dirname, '../static'),
40+
to: config.build.assetsSubDirectory,
41+
ignore: ['.*']
42+
}
43+
])
3444
]
3545
})

Vue_Starter/config/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module.exports = {
77
index: path.resolve(__dirname, '../dist/index.html'),
88
assetsRoot: path.resolve(__dirname, '../dist'),
99
assetsSubDirectory: 'static',
10-
assetsPublicPath: '/',
10+
assetsPublicPath: './',
1111
productionSourceMap: true,
1212
// Gzip off by default as many popular static hosts such as
1313
// Surge or Netlify already gzip all static assets for you.
@@ -26,7 +26,7 @@ module.exports = {
2626
port: 8080,
2727
autoOpenBrowser: true,
2828
assetsSubDirectory: 'static',
29-
assetsPublicPath: '/',
29+
assetsPublicPath: '',
3030
proxyTable: {},
3131
// CSS Sourcemaps off by default because relative paths are "buggy"
3232
// with this option, according to the CSS-Loader README

0 commit comments

Comments
 (0)