refine build

This commit is contained in:
Pan 2017-08-07 16:11:10 +08:00
parent cdebb5c012
commit 2e9a3a849b
5 changed files with 213 additions and 213 deletions

View file

@ -1,12 +1,11 @@
var path = require('path'); var path = require('path')
var utils = require('./utils'); var utils = require('./utils')
var config = require('../config'); var config = require('../config')
var vueLoaderConfig = require('./vue-loader.conf'); var vueLoaderConfig = require('./vue-loader.conf')
function resolve(dir) { function resolve(dir) {
return path.join(__dirname, '..', dir) return path.join(__dirname, '..', dir)
} }
var src = path.resolve(__dirname, '../src');
module.exports = { module.exports = {
entry: { entry: {
@ -15,7 +14,7 @@ module.exports = {
output: { output: {
path: config.build.assetsRoot, path: config.build.assetsRoot,
filename: '[name].js', filename: '[name].js',
publicPath: process.env.NODE_ENV !== 'development' ? config.build.assetsPublicPath: config.dev.assetsPublicPath publicPath: process.env.NODE_ENV !== 'development' ? config.build.assetsPublicPath : config.dev.assetsPublicPath
}, },
resolve: { resolve: {
extensions: ['.js', '.vue', '.json'], extensions: ['.js', '.vue', '.json'],
@ -50,7 +49,8 @@ module.exports = {
// formatter: require('eslint-friendly-formatter') // formatter: require('eslint-friendly-formatter')
// } // }
// }, // },
{ test: /\.vue$/, {
test: /\.vue$/,
loader: 'vue-loader', loader: 'vue-loader',
options: vueLoaderConfig options: vueLoaderConfig
}, },
@ -83,3 +83,4 @@ module.exports = {
// data: path.join(__dirname, '../src/styles/index.scss') // data: path.join(__dirname, '../src/styles/index.scss')
// }, // },
} }

View file

@ -18,7 +18,9 @@ function resolveApp(relativePath) {
module.exports = merge(baseWebpackConfig, { module.exports = merge(baseWebpackConfig, {
module: { module: {
rules: utils.styleLoaders({sourceMap: config.dev.cssSourceMap}) rules: utils.styleLoaders({
sourceMap: config.dev.cssSourceMap
})
}, },
// cheap-source-map is faster for development // cheap-source-map is faster for development
devtool: '#cheap-source-map', devtool: '#cheap-source-map',
@ -40,8 +42,9 @@ module.exports = merge(baseWebpackConfig, {
template: 'index.html', template: 'index.html',
favicon: resolveApp('favicon.ico'), favicon: resolveApp('favicon.ico'),
inject: true, inject: true,
path:config.dev.staticPath path: config.dev.assetsPublicPath + config.dev.assetsSubDirectory
}), }),
new FriendlyErrorsPlugin() new FriendlyErrorsPlugin()
] ]
}) })

View file

@ -26,7 +26,8 @@ var webpackConfig = merge(baseWebpackConfig, {
output: { output: {
path: config.build.assetsRoot, path: config.build.assetsRoot,
filename: utils.assetsPath('js/[name].[chunkhash].js'), filename: utils.assetsPath('js/[name].[chunkhash].js'),
chunkFilename: utils.assetsPath('js/[id].[chunkhash].js') chunkFilename: utils.assetsPath('js/[id].[chunkhash].js'),
publicPath: config.build.assetsPublicPath
}, },
plugins: [ plugins: [
// http://vuejs.github.io/vue-loader/en/workflow/production.html // http://vuejs.github.io/vue-loader/en/workflow/production.html
@ -50,9 +51,7 @@ var webpackConfig = merge(baseWebpackConfig, {
// you can customize output by editing /index.html // you can customize output by editing /index.html
// see https://github.com/ampedandwired/html-webpack-plugin // see https://github.com/ampedandwired/html-webpack-plugin
new HtmlWebpackPlugin({ new HtmlWebpackPlugin({
filename: process.env.NODE_ENV === 'testing' filename: 'index.html',
? 'index.html'
: config.build.index,
template: 'index.html', template: 'index.html',
inject: true, inject: true,
favicon: resolveApp('favicon.ico'), favicon: resolveApp('favicon.ico'),
@ -68,7 +67,7 @@ var webpackConfig = merge(baseWebpackConfig, {
minifyCSS: true, minifyCSS: true,
minifyURLs: true minifyURLs: true
}, },
path:config.build.staticPath, path: config.build.assetsPublicPath + config.build.assetsSubDirectory,
// necessary to consistently work with multiple chunks via CommonsChunkPlugin // necessary to consistently work with multiple chunks via CommonsChunkPlugin
chunksSortMode: 'dependency' chunksSortMode: 'dependency'
}), }),
@ -90,7 +89,7 @@ var webpackConfig = merge(baseWebpackConfig, {
}), }),
// split echarts into its own file // split echarts into its own file
new webpack.optimize.CommonsChunkPlugin({ new webpack.optimize.CommonsChunkPlugin({
async:'echarts', async: 'echarts',
minChunks(module) { minChunks(module) {
var context = module.context; var context = module.context;
return context && (context.indexOf('echarts') >= 0 || context.indexOf('zrender') >= 0); return context && (context.indexOf('echarts') >= 0 || context.indexOf('zrender') >= 0);
@ -103,13 +102,11 @@ var webpackConfig = merge(baseWebpackConfig, {
chunks: ['vendor'] chunks: ['vendor']
}), }),
// copy custom static assets // copy custom static assets
new CopyWebpackPlugin([ new CopyWebpackPlugin([{
{
from: path.resolve(__dirname, '../static'), from: path.resolve(__dirname, '../static'),
to: config.build.assetsSubDirectory, to: config.build.assetsSubDirectory,
ignore: ['.*'] ignore: ['.*']
} }]),
]),
new webpack.ProvidePlugin({ new webpack.ProvidePlugin({
$: 'jquery', $: 'jquery',
'jQuery': 'jquery' 'jQuery': 'jquery'
@ -121,3 +118,4 @@ if (config.build.bundleAnalyzerReport) {
webpackConfig.plugins.push(new BundleAnalyzerPlugin()) webpackConfig.plugins.push(new BundleAnalyzerPlugin())
} }
module.exports = webpackConfig module.exports = webpackConfig

View file

@ -9,7 +9,6 @@ module.exports = {
assetsRoot: path.resolve(__dirname, '../dist'), assetsRoot: path.resolve(__dirname, '../dist'),
assetsSubDirectory: 'static', assetsSubDirectory: 'static',
assetsPublicPath: './', //请根据自己路径配置更改 assetsPublicPath: './', //请根据自己路径配置更改
staticPath:'./static/', //请根据自己路径配置更改
productionSourceMap: false, productionSourceMap: false,
// Gzip off by default as many popular static hosts such as // Gzip off by default as many popular static hosts such as
// Surge or Netlify already gzip all static assets for you. // Surge or Netlify already gzip all static assets for you.
@ -29,7 +28,6 @@ module.exports = {
autoOpenBrowser: true, autoOpenBrowser: true,
assetsSubDirectory: 'static', assetsSubDirectory: 'static',
assetsPublicPath: '/', assetsPublicPath: '/',
staticPath:'/static/',
proxyTable: {}, proxyTable: {},
// CSS Sourcemaps off by default because relative paths are "buggy" // CSS Sourcemaps off by default because relative paths are "buggy"
// with this option, according to the CSS-Loader README // with this option, according to the CSS-Loader README

View file

@ -8,8 +8,8 @@
<title>Juicy</title> <title>Juicy</title>
</head> </head>
<body> <body>
<script src=<%= htmlWebpackPlugin.options.path %>jquery.min.js></script> <script src=<%= htmlWebpackPlugin.options.path %>/jquery.min.js></script>
<script src=<%= htmlWebpackPlugin.options.path %>tinymce/tinymce.min.js></script> <script src=<%= htmlWebpackPlugin.options.path %>/tinymce/tinymce.min.js></script>
<div id="app"></div> <div id="app"></div>
<!-- built files will be auto injected --> <!-- built files will be auto injected -->
</body> </body>