From bd341f3ffc0224145ffd6a573682378f0d32ee6f Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Thu, 6 Jul 2017 09:04:10 +0100 Subject: [PATCH] Clean build folder Former-commit-id: e47639684bbb1b4d0a15ac8c39dbb0040ae86226 [formerly 3343000db072beb88cec31bb52b139313469f612] [formerly 062dd709613b5784dc8e9b2f327df3cd4c95dc75 [formerly 69d8cd63433f1a56a258a0fb604355a66fe3d20e]] Former-commit-id: 1c0ebd340266b2020ffba94d2370dbf7c98d1aa6 [formerly fcf840509a0f782b8460fb354aed513dbaa10aa2] Former-commit-id: bd4e275034627c7ff9c8b60c1405ce6aed912761 --- assets/build/build.js | 6 +----- assets/build/config.js | 18 ++++-------------- assets/build/dev.js | 2 +- assets/build/utils.js | 4 +--- assets/build/vue-loader.conf.js | 2 +- assets/build/webpack.base.conf.js | 6 ++---- assets/build/webpack.dev.conf.js | 6 +++--- assets/build/webpack.prod.conf.js | 26 ++++---------------------- 8 files changed, 17 insertions(+), 53 deletions(-) diff --git a/assets/build/build.js b/assets/build/build.js index 7588bd93..c7c0fbdb 100644 --- a/assets/build/build.js +++ b/assets/build/build.js @@ -13,7 +13,7 @@ var webpackConfig = require('./webpack.prod.conf') var spinner = ora('building for production...') spinner.start() -rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => { +rm(path.join(config.assetsRoot, config.assetsSubDirectory), err => { if (err) throw err webpack(webpackConfig, function (err, stats) { spinner.stop() @@ -27,9 +27,5 @@ rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => { }) + '\n\n') console.log(chalk.cyan(' Build complete.\n')) - console.log(chalk.yellow( - ' Tip: built files are meant to be served over an HTTP server.\n' + - ' Opening index.html over file:// won\'t work.\n' - )) }) }) diff --git a/assets/build/config.js b/assets/build/config.js index 8f6190f2..885ac29d 100644 --- a/assets/build/config.js +++ b/assets/build/config.js @@ -2,21 +2,15 @@ var path = require('path') module.exports = { + index: path.resolve(__dirname, '../dist/index.html'), + assetsRoot: path.resolve(__dirname, '../dist'), + assetsSubDirectory: 'static', + assetsPublicPath: '{{ .BaseURL }}/', build: { env: { NODE_ENV: '"production"' }, - index: path.resolve(__dirname, '../dist/index.html'), - assetsRoot: path.resolve(__dirname, '../dist'), - assetsSubDirectory: 'static', - assetsPublicPath: '{{ .BaseURL }}/', productionSourceMap: true, - // Gzip off by default as many popular static hosts such as - // Surge or Netlify already gzip all static assets for you. - // Before setting to `true`, make sure to: - // npm install --save-dev compression-webpack-plugin - productionGzip: false, - productionGzipExtensions: ['js', 'css'], // Run the build command with an extra argument to // View the bundle analyzer report after build finishes: // `npm run build --report` @@ -27,10 +21,6 @@ module.exports = { env: { NODE_ENV: '"development"' }, - index: path.resolve(__dirname, '../dist/index.html'), - assetsRoot: path.resolve(__dirname, '../dist/'), - assetsSubDirectory: 'static', - assetsPublicPath: '{{ .BaseURL }}/', produceSourceMap: true } } diff --git a/assets/build/dev.js b/assets/build/dev.js index 8532c366..e00be9e7 100644 --- a/assets/build/dev.js +++ b/assets/build/dev.js @@ -9,7 +9,7 @@ var webpack = require('webpack') var config = require('./config') var webpackConfig = require('./webpack.dev.conf') -rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => { +rm(path.join(config.assetsRoot, config.assetsSubDirectory), err => { if (err) throw err webpack(webpackConfig, function (err, stats) { if (err) throw err diff --git a/assets/build/utils.js b/assets/build/utils.js index 9062bbfa..616ceb3a 100644 --- a/assets/build/utils.js +++ b/assets/build/utils.js @@ -3,9 +3,7 @@ var config = require('./config') var ExtractTextPlugin = require('extract-text-webpack-plugin') exports.assetsPath = function (_path) { - var assetsSubDirectory = process.env.NODE_ENV === 'production' - ? config.build.assetsSubDirectory - : config.dev.assetsSubDirectory + var assetsSubDirectory = config.assetsSubDirectory return path.posix.join(assetsSubDirectory, _path) } diff --git a/assets/build/vue-loader.conf.js b/assets/build/vue-loader.conf.js index 03dde95e..a17529fc 100644 --- a/assets/build/vue-loader.conf.js +++ b/assets/build/vue-loader.conf.js @@ -6,7 +6,7 @@ module.exports = { loaders: utils.cssLoaders({ sourceMap: isProduction ? config.build.productionSourceMap - : config.dev.cssSourceMap, + : config.dev.produceSourceMap, extract: isProduction }) } diff --git a/assets/build/webpack.base.conf.js b/assets/build/webpack.base.conf.js index 35e74822..5016698b 100644 --- a/assets/build/webpack.base.conf.js +++ b/assets/build/webpack.base.conf.js @@ -12,11 +12,9 @@ module.exports = { app: './assets/src/main.js' }, output: { - path: config.build.assetsRoot, + path: config.assetsRoot, filename: '[name].js', - publicPath: process.env.NODE_ENV === 'production' - ? config.build.assetsPublicPath - : config.dev.assetsPublicPath + publicPath: config.assetsPublicPath }, resolve: { extensions: ['.js', '.vue', '.json'], diff --git a/assets/build/webpack.dev.conf.js b/assets/build/webpack.dev.conf.js index 9aca8cff..71269886 100644 --- a/assets/build/webpack.dev.conf.js +++ b/assets/build/webpack.dev.conf.js @@ -39,7 +39,7 @@ module.exports = merge(baseWebpackConfig, { // see https://github.com/ampedandwired/html-webpack-plugin new HtmlWebpackPlugin({ filename: config.dev.index, - template: 'index.html', + template: 'assets/index.html', inject: true, // necessary to consistently work with multiple chunks via CommonsChunkPlugin chunksSortMode: 'dependency', @@ -69,12 +69,12 @@ module.exports = merge(baseWebpackConfig, { new CopyWebpackPlugin([ { from: path.resolve(__dirname, '../static'), - to: config.dev.assetsSubDirectory, + to: config.assetsSubDirectory, ignore: ['.*'] }, { from: path.resolve(__dirname, '../node_modules/codemirror/mode/*/*'), - to: path.join(config.build.assetsSubDirectory, 'js/codemirror/mode/[name]/[name].js') + to: path.join(config.assetsSubDirectory, 'js/codemirror/mode/[name]/[name].js') } ]) ] diff --git a/assets/build/webpack.prod.conf.js b/assets/build/webpack.prod.conf.js index f19b2aa6..71851a6f 100644 --- a/assets/build/webpack.prod.conf.js +++ b/assets/build/webpack.prod.conf.js @@ -23,7 +23,7 @@ var webpackConfig = merge(baseWebpackConfig, { }, devtool: config.build.productionSourceMap ? '#source-map' : false, output: { - path: config.build.assetsRoot, + path: config.assetsRoot, filename: utils.assetsPath('js/[name].[chunkhash].js'), chunkFilename: utils.assetsPath('js/[id].[chunkhash].js') }, @@ -31,12 +31,12 @@ var webpackConfig = merge(baseWebpackConfig, { new CopyWebpackPlugin([ { from: path.resolve(__dirname, '../static'), - to: config.dev.assetsSubDirectory, + to: config.assetsSubDirectory, ignore: ['.*'] }, { from: path.resolve(__dirname, '../node_modules/codemirror/mode/*/*'), - to: path.join(config.build.assetsSubDirectory, 'js/codemirror/mode/[name]/[name].js'), + to: path.join(config.assetsSubDirectory, 'js/codemirror/mode/[name]/[name].js'), transform: function (source, path) { let result = UglifyJS.minify(source.toString('utf8')) if (result.error !== undefined) { @@ -71,7 +71,7 @@ var webpackConfig = merge(baseWebpackConfig, { // you can customize output by editing /index.html // see https://github.com/ampedandwired/html-webpack-plugin new HtmlWebpackPlugin({ - filename: config.build.index, + filename: config.index, template: 'assets/index.html', inject: true, minify: { @@ -119,24 +119,6 @@ var webpackConfig = merge(baseWebpackConfig, { ] }) -if (config.build.productionGzip) { - var CompressionWebpackPlugin = require('compression-webpack-plugin') - - webpackConfig.plugins.push( - new CompressionWebpackPlugin({ - asset: '[path].gz[query]', - algorithm: 'gzip', - test: new RegExp( - '\\.(' + - config.build.productionGzipExtensions.join('|') + - ')$' - ), - threshold: 10240, - minRatio: 0.8 - }) - ) -} - if (config.build.bundleAnalyzerReport) { var BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin webpackConfig.plugins.push(new BundleAnalyzerPlugin())