Browse Source

Revert ignoring build directory, actually required

Phyks (Lucas Verney) 2 years ago
parent
commit
d5fdaa6b67

+ 0
- 1
.gitignore View File

@@ -15,5 +15,4 @@ selenium-debug.log
15 15
 *.njsproj
16 16
 *.sln
17 17
 
18
-build/
19 18
 package-lock.json

+ 40
- 0
build/build.js View File

@@ -0,0 +1,40 @@
1
+require('./check-versions')()
2
+
3
+process.env.NODE_ENV = 'production'
4
+
5
+var ora = require('ora')
6
+var rm = require('rimraf')
7
+var path = require('path')
8
+var chalk = require('chalk')
9
+var webpack = require('webpack')
10
+var config = require('../config')
11
+var webpackConfig = require('./webpack.prod.conf')
12
+
13
+var spinner = ora('building for production...')
14
+spinner.start()
15
+
16
+rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => {
17
+  if (err) throw err
18
+  webpack(webpackConfig, function (err, stats) {
19
+    spinner.stop()
20
+    if (err) throw err
21
+    process.stdout.write(stats.toString({
22
+      colors: true,
23
+      modules: false,
24
+      children: false,
25
+      chunks: false,
26
+      chunkModules: false
27
+    }) + '\n\n')
28
+
29
+    if (stats.hasErrors()) {
30
+      console.log(chalk.red('  Build failed with errors.\n'))
31
+      process.exit(1)
32
+    }
33
+
34
+    console.log(chalk.cyan('  Build complete.\n'))
35
+    console.log(chalk.yellow(
36
+      '  Tip: built files are meant to be served over an HTTP server.\n' +
37
+      '  Opening index.html over file:// won\'t work.\n'
38
+    ))
39
+  })
40
+})

+ 48
- 0
build/check-versions.js View File

@@ -0,0 +1,48 @@
1
+var chalk = require('chalk')
2
+var semver = require('semver')
3
+var packageConfig = require('../package.json')
4
+var shell = require('shelljs')
5
+function exec (cmd) {
6
+  return require('child_process').execSync(cmd).toString().trim()
7
+}
8
+
9
+var versionRequirements = [
10
+  {
11
+    name: 'node',
12
+    currentVersion: semver.clean(process.version),
13
+    versionRequirement: packageConfig.engines.node
14
+  }
15
+]
16
+
17
+if (shell.which('npm')) {
18
+  versionRequirements.push({
19
+    name: 'npm',
20
+    currentVersion: exec('npm --version'),
21
+    versionRequirement: packageConfig.engines.npm
22
+  })
23
+}
24
+
25
+module.exports = function () {
26
+  var warnings = []
27
+  for (var i = 0; i < versionRequirements.length; i++) {
28
+    var mod = versionRequirements[i]
29
+    if (!semver.satisfies(mod.currentVersion, mod.versionRequirement)) {
30
+      warnings.push(mod.name + ': ' +
31
+        chalk.red(mod.currentVersion) + ' should be ' +
32
+        chalk.green(mod.versionRequirement)
33
+      )
34
+    }
35
+  }
36
+
37
+  if (warnings.length) {
38
+    console.log('')
39
+    console.log(chalk.yellow('To use this template, you must update following to modules:'))
40
+    console.log()
41
+    for (var i = 0; i < warnings.length; i++) {
42
+      var warning = warnings[i]
43
+      console.log('  ' + warning)
44
+    }
45
+    console.log()
46
+    process.exit(1)
47
+  }
48
+}

+ 9
- 0
build/dev-client.js View File

@@ -0,0 +1,9 @@
1
+/* eslint-disable */
2
+require('eventsource-polyfill')
3
+var hotClient = require('webpack-hot-middleware/client?noInfo=true&reload=true')
4
+
5
+hotClient.subscribe(function (event) {
6
+  if (event.action === 'reload') {
7
+    window.location.reload()
8
+  }
9
+})

+ 92
- 0
build/dev-server.js View File

@@ -0,0 +1,92 @@
1
+require('./check-versions')()
2
+
3
+var config = require('../config')
4
+if (!process.env.NODE_ENV) {
5
+  process.env.NODE_ENV = JSON.parse(config.dev.env.NODE_ENV)
6
+}
7
+
8
+var opn = require('opn')
9
+var path = require('path')
10
+var express = require('express')
11
+var webpack = require('webpack')
12
+var proxyMiddleware = require('http-proxy-middleware')
13
+var webpackConfig = (process.env.NODE_ENV === 'testing' || process.env.NODE_ENV === 'production')
14
+  ? require('./webpack.prod.conf')
15
+  : require('./webpack.dev.conf')
16
+
17
+// default port where dev server listens for incoming traffic
18
+var port = process.env.PORT || config.dev.port
19
+// automatically open browser, if not set will be false
20
+var autoOpenBrowser = !!config.dev.autoOpenBrowser
21
+// Define HTTP proxies to your custom API backend
22
+// https://github.com/chimurai/http-proxy-middleware
23
+var proxyTable = config.dev.proxyTable
24
+
25
+var app = express()
26
+var compiler = webpack(webpackConfig)
27
+
28
+var devMiddleware = require('webpack-dev-middleware')(compiler, {
29
+  publicPath: webpackConfig.output.publicPath,
30
+  quiet: true
31
+})
32
+
33
+var hotMiddleware = require('webpack-hot-middleware')(compiler, {
34
+  log: false,
35
+  heartbeat: 2000
36
+})
37
+// force page reload when html-webpack-plugin template changes
38
+compiler.plugin('compilation', function (compilation) {
39
+  compilation.plugin('html-webpack-plugin-after-emit', function (data, cb) {
40
+    hotMiddleware.publish({ action: 'reload' })
41
+    cb()
42
+  })
43
+})
44
+
45
+// proxy api requests
46
+Object.keys(proxyTable).forEach(function (context) {
47
+  var options = proxyTable[context]
48
+  if (typeof options === 'string') {
49
+    options = { target: options }
50
+  }
51
+  app.use(proxyMiddleware(options.filter || context, options))
52
+})
53
+
54
+// handle fallback for HTML5 history API
55
+app.use(require('connect-history-api-fallback')())
56
+
57
+// serve webpack bundle output
58
+app.use(devMiddleware)
59
+
60
+// enable hot-reload and state-preserving
61
+// compilation error display
62
+app.use(hotMiddleware)
63
+
64
+// serve pure static assets
65
+var staticPath = path.posix.join(config.dev.assetsPublicPath, config.dev.assetsSubDirectory)
66
+app.use(staticPath, express.static('./static'))
67
+
68
+var uri = 'http://localhost:' + port
69
+
70
+var _resolve
71
+var readyPromise = new Promise(resolve => {
72
+  _resolve = resolve
73
+})
74
+
75
+console.log('> Starting dev server...')
76
+devMiddleware.waitUntilValid(() => {
77
+  console.log('> Listening at ' + uri + '\n')
78
+  // when env is testing, don't need open it
79
+  if (autoOpenBrowser && process.env.NODE_ENV !== 'testing') {
80
+    opn(uri)
81
+  }
82
+  _resolve()
83
+})
84
+
85
+var server = app.listen(port)
86
+
87
+module.exports = {
88
+  ready: readyPromise,
89
+  close: () => {
90
+    server.close()
91
+  }
92
+}

+ 71
- 0
build/utils.js View File

@@ -0,0 +1,71 @@
1
+var path = require('path')
2
+var config = require('../config')
3
+var ExtractTextPlugin = require('extract-text-webpack-plugin')
4
+
5
+exports.assetsPath = function (_path) {
6
+  var assetsSubDirectory = process.env.NODE_ENV === 'production'
7
+    ? config.build.assetsSubDirectory
8
+    : config.dev.assetsSubDirectory
9
+  return path.posix.join(assetsSubDirectory, _path)
10
+}
11
+
12
+exports.cssLoaders = function (options) {
13
+  options = options || {}
14
+
15
+  var cssLoader = {
16
+    loader: 'css-loader',
17
+    options: {
18
+      minimize: process.env.NODE_ENV === 'production',
19
+      sourceMap: options.sourceMap
20
+    }
21
+  }
22
+
23
+  // generate loader string to be used with extract text plugin
24
+  function generateLoaders (loader, loaderOptions) {
25
+    var loaders = [cssLoader]
26
+    if (loader) {
27
+      loaders.push({
28
+        loader: loader + '-loader',
29
+        options: Object.assign({}, loaderOptions, {
30
+          sourceMap: options.sourceMap
31
+        })
32
+      })
33
+    }
34
+
35
+    // Extract CSS when that option is specified
36
+    // (which is the case during production build)
37
+    if (options.extract) {
38
+      return ExtractTextPlugin.extract({
39
+        use: loaders,
40
+        fallback: 'vue-style-loader'
41
+      })
42
+    } else {
43
+      return ['vue-style-loader'].concat(loaders)
44
+    }
45
+  }
46
+
47
+  // https://vue-loader.vuejs.org/en/configurations/extract-css.html
48
+  return {
49
+    css: generateLoaders(),
50
+    postcss: generateLoaders(),
51
+    less: generateLoaders('less'),
52
+    sass: generateLoaders('sass', { indentedSyntax: true }),
53
+    scss: generateLoaders('sass'),
54
+    stylus: generateLoaders('stylus'),
55
+    styl: generateLoaders('stylus')
56
+  }
57
+}
58
+
59
+// Generate loaders for standalone style files (outside of .vue)
60
+exports.styleLoaders = function (options) {
61
+  var output = []
62
+  var loaders = exports.cssLoaders(options)
63
+  for (var extension in loaders) {
64
+    var loader = loaders[extension]
65
+    output.push({
66
+      test: new RegExp('\\.' + extension + '$'),
67
+      use: loader
68
+    })
69
+  }
70
+  return output
71
+}

+ 18
- 0
build/vue-loader.conf.js View File

@@ -0,0 +1,18 @@
1
+var utils = require('./utils')
2
+var config = require('../config')
3
+var isProduction = process.env.NODE_ENV === 'production'
4
+
5
+module.exports = {
6
+  loaders: utils.cssLoaders({
7
+    sourceMap: isProduction
8
+      ? config.build.productionSourceMap
9
+      : config.dev.cssSourceMap,
10
+    extract: isProduction
11
+  }),
12
+  transformToRequire: {
13
+    video: 'src',
14
+    source: 'src',
15
+    img: 'src',
16
+    image: 'xlink:href'
17
+  }
18
+}

+ 79
- 0
build/webpack.base.conf.js View File

@@ -0,0 +1,79 @@
1
+var path = require('path')
2
+var utils = require('./utils')
3
+var config = require('../config')
4
+var vueLoaderConfig = require('./vue-loader.conf')
5
+
6
+function resolve (dir) {
7
+  return path.join(__dirname, '..', dir)
8
+}
9
+
10
+module.exports = {
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 === 'production'
18
+      ? config.build.assetsPublicPath
19
+      : config.dev.assetsPublicPath
20
+  },
21
+  resolve: {
22
+    extensions: ['.js', '.vue', '.json'],
23
+    alias: {
24
+      'vue$': 'vue/dist/vue.esm.js',
25
+      '@': resolve('src'),
26
+    }
27
+  },
28
+  module: {
29
+    rules: [
30
+      {
31
+        test: /\.(js|vue)$/,
32
+        loader: 'eslint-loader',
33
+        enforce: 'pre',
34
+        include: [resolve('src'), resolve('test')],
35
+        options: {
36
+          formatter: require('eslint-friendly-formatter')
37
+        }
38
+      },
39
+      {
40
+        test: /\.vue$/,
41
+        loader: 'vue-loader',
42
+        options: vueLoaderConfig
43
+      },
44
+      {
45
+        test: /\.js$/,
46
+        loader: 'babel-loader',
47
+        include: [resolve('src'), resolve('test')]
48
+      },
49
+      {
50
+        test: /\.(png|jpe?g|gif)(\?.*)?$/,
51
+        loader: 'url-loader',
52
+        options: {
53
+          limit: 10000,
54
+          name: utils.assetsPath('img/[name].[hash:7].[ext]')
55
+        }
56
+      },
57
+      {
58
+        test: /\.svg$/,
59
+        loader: 'svg-inline-loader'
60
+      },
61
+      {
62
+        test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
63
+        loader: 'url-loader',
64
+        options: {
65
+          limit: 10000,
66
+          name: utils.assetsPath('media/[name].[hash:7].[ext]')
67
+        }
68
+      },
69
+      {
70
+        test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
71
+        loader: 'url-loader',
72
+        options: {
73
+          limit: 10000,
74
+          name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
75
+        }
76
+      }
77
+    ]
78
+  }
79
+}

+ 35
- 0
build/webpack.dev.conf.js View File

@@ -0,0 +1,35 @@
1
+var utils = require('./utils')
2
+var webpack = require('webpack')
3
+var config = require('../config')
4
+var merge = require('webpack-merge')
5
+var baseWebpackConfig = require('./webpack.base.conf')
6
+var HtmlWebpackPlugin = require('html-webpack-plugin')
7
+var FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin')
8
+
9
+// add hot-reload related code to entry chunks
10
+Object.keys(baseWebpackConfig.entry).forEach(function (name) {
11
+  baseWebpackConfig.entry[name] = ['./build/dev-client'].concat(baseWebpackConfig.entry[name])
12
+})
13
+
14
+module.exports = merge(baseWebpackConfig, {
15
+  module: {
16
+    rules: utils.styleLoaders({ sourceMap: config.dev.cssSourceMap })
17
+  },
18
+  // cheap-module-eval-source-map is faster for development
19
+  devtool: '#cheap-module-eval-source-map',
20
+  plugins: [
21
+    new webpack.DefinePlugin({
22
+      'process.env': config.dev.env
23
+    }),
24
+    // https://github.com/glenjamin/webpack-hot-middleware#installation--usage
25
+    new webpack.HotModuleReplacementPlugin(),
26
+    new webpack.NoEmitOnErrorsPlugin(),
27
+    // https://github.com/ampedandwired/html-webpack-plugin
28
+    new HtmlWebpackPlugin({
29
+      filename: 'index.html',
30
+      template: 'index.html',
31
+      inject: true
32
+    }),
33
+    new FriendlyErrorsPlugin()
34
+  ]
35
+})

+ 126
- 0
build/webpack.prod.conf.js View File

@@ -0,0 +1,126 @@
1
+var path = require('path')
2
+var utils = require('./utils')
3
+var webpack = require('webpack')
4
+var config = require('../config')
5
+var merge = require('webpack-merge')
6
+var baseWebpackConfig = require('./webpack.base.conf')
7
+var CopyWebpackPlugin = require('copy-webpack-plugin')
8
+var HtmlWebpackPlugin = require('html-webpack-plugin')
9
+var ExtractTextPlugin = require('extract-text-webpack-plugin')
10
+var OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin')
11
+
12
+var env = process.env.NODE_ENV === 'testing'
13
+  ? require('../config/test.env')
14
+  : config.build.env
15
+
16
+var webpackConfig = merge(baseWebpackConfig, {
17
+  module: {
18
+    rules: utils.styleLoaders({
19
+      sourceMap: config.build.productionSourceMap,
20
+      extract: true
21
+    })
22
+  },
23
+  devtool: config.build.productionSourceMap ? '#source-map' : false,
24
+  output: {
25
+    path: config.build.assetsRoot,
26
+    filename: utils.assetsPath('js/[name].[chunkhash].js'),
27
+    chunkFilename: utils.assetsPath('js/[id].[chunkhash].js')
28
+  },
29
+  plugins: [
30
+    // http://vuejs.github.io/vue-loader/en/workflow/production.html
31
+    new webpack.DefinePlugin({
32
+      'process.env': env
33
+    }),
34
+    new webpack.optimize.UglifyJsPlugin({
35
+      compress: {
36
+        warnings: false
37
+      },
38
+      sourceMap: true
39
+    }),
40
+    // extract css into its own file
41
+    new ExtractTextPlugin({
42
+      filename: utils.assetsPath('css/[name].[contenthash].css')
43
+    }),
44
+    // Compress extracted CSS. We are using this plugin so that possible
45
+    // duplicated CSS from different components can be deduped.
46
+    new OptimizeCSSPlugin({
47
+      cssProcessorOptions: {
48
+        safe: true
49
+      }
50
+    }),
51
+    // generate dist index.html with correct asset hash for caching.
52
+    // you can customize output by editing /index.html
53
+    // see https://github.com/ampedandwired/html-webpack-plugin
54
+    new HtmlWebpackPlugin({
55
+      filename: process.env.NODE_ENV === 'testing'
56
+        ? 'index.html'
57
+        : config.build.index,
58
+      template: 'index.html',
59
+      inject: true,
60
+      minify: {
61
+        removeComments: true,
62
+        collapseWhitespace: true,
63
+        removeAttributeQuotes: true
64
+        // more options:
65
+        // https://github.com/kangax/html-minifier#options-quick-reference
66
+      },
67
+      // necessary to consistently work with multiple chunks via CommonsChunkPlugin
68
+      chunksSortMode: 'dependency'
69
+    }),
70
+    // keep module.id stable when vender modules does not change
71
+    new webpack.HashedModuleIdsPlugin(),
72
+    // split vendor js into its own file
73
+    new webpack.optimize.CommonsChunkPlugin({
74
+      name: 'vendor',
75
+      minChunks: function (module, count) {
76
+        // any required modules inside node_modules are extracted to vendor
77
+        return (
78
+          module.resource &&
79
+          /\.js$/.test(module.resource) &&
80
+          module.resource.indexOf(
81
+            path.join(__dirname, '../node_modules')
82
+          ) === 0
83
+        )
84
+      }
85
+    }),
86
+    // extract webpack runtime and module manifest to its own file in order to
87
+    // prevent vendor hash from being updated whenever app bundle is updated
88
+    new webpack.optimize.CommonsChunkPlugin({
89
+      name: 'manifest',
90
+      chunks: ['vendor']
91
+    }),
92
+    // copy custom static assets
93
+    new CopyWebpackPlugin([
94
+      {
95
+        from: path.resolve(__dirname, '../static'),
96
+        to: config.build.assetsSubDirectory,
97
+        ignore: ['.*']
98
+      }
99
+    ])
100
+  ]
101
+})
102
+
103
+if (config.build.productionGzip) {
104
+  var CompressionWebpackPlugin = require('compression-webpack-plugin')
105
+
106
+  webpackConfig.plugins.push(
107
+    new CompressionWebpackPlugin({
108
+      asset: '[path].gz[query]',
109
+      algorithm: 'gzip',
110
+      test: new RegExp(
111
+        '\\.(' +
112
+        config.build.productionGzipExtensions.join('|') +
113
+        ')$'
114
+      ),
115
+      threshold: 10240,
116
+      minRatio: 0.8
117
+    })
118
+  )
119
+}
120
+
121
+if (config.build.bundleAnalyzerReport) {
122
+  var BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
123
+  webpackConfig.plugins.push(new BundleAnalyzerPlugin())
124
+}
125
+
126
+module.exports = webpackConfig

+ 31
- 0
build/webpack.test.conf.js View File

@@ -0,0 +1,31 @@
1
+// This is the webpack config used for unit tests.
2
+
3
+var utils = require('./utils')
4
+var webpack = require('webpack')
5
+var merge = require('webpack-merge')
6
+var baseConfig = require('./webpack.base.conf')
7
+
8
+var webpackConfig = merge(baseConfig, {
9
+  // use inline sourcemap for karma-sourcemap-loader
10
+  module: {
11
+    rules: utils.styleLoaders()
12
+  },
13
+  devtool: '#inline-source-map',
14
+  resolveLoader: {
15
+    alias: {
16
+      // necessary to to make lang="scss" work in test when using vue-loader's ?inject option
17
+      // see discussion at https://github.com/vuejs/vue-loader/issues/724
18
+      'scss-loader': 'sass-loader'
19
+    }
20
+  },
21
+  plugins: [
22
+    new webpack.DefinePlugin({
23
+      'process.env': require('../config/test.env')
24
+    })
25
+  ]
26
+})
27
+
28
+// no need for app entry during tests
29
+delete webpackConfig.entry
30
+
31
+module.exports = webpackConfig

+ 0
- 1
src/components/NavigationDrawer.vue View File

@@ -44,7 +44,6 @@
44 44
 
45 45
 <script>
46 46
 /**
47
- * TODO: Do not open drawer on route change nor on resize.
48 47
  * TODO: Should stick to the toolbar on xs screens. Should be fixed by Vuetify 0.16.
49 48
  */
50 49
 export default {