Browse Source

new project commit

csx 4 years ago
parent
commit
e02bc8adc6

+ 82 - 0
build/build-cdn.js View File

@@ -0,0 +1,82 @@
1
+'use strict'
2
+require('./check-versions')()
3
+
4
+process.env.NODE_ENV = 'production'
5
+
6
+const ora = require('ora')
7
+const rm = require('rimraf')
8
+const path = require('path')
9
+const chalk = require('chalk')
10
+const webpack = require('webpack')
11
+const config = require('../config')
12
+const webpackConfig = require('./webpack.prod-cdn.conf')
13
+const writeJson = require('write-json')
14
+const QiniuPlugin = require('qiniu-webpack-plugin')
15
+// const utils = require('./utils')
16
+
17
+const spinner = ora('building for production...')
18
+spinner.start()
19
+
20
+const cdn_ver = require('./cdn.json').version
21
+
22
+const addVer = (ver) => {
23
+  const ar = ver.split('.')
24
+  ar[2] = parseInt(ar[2]) + 1
25
+  return ar.join('.')
26
+}
27
+
28
+const verNow = addVer(cdn_ver)
29
+
30
+webpackConfig.plugins.push(new QiniuPlugin({
31
+  ACCESS_KEY: 'E5sYahBxp7RfMECLXhCUZJD3U_BTKYGsPDS4NLFd',
32
+  SECRET_KEY: 'mlO3FEmRX-S_9XPCf9WrkvzgnpZ8IlmHeiVrIDQF',
33
+  bucket: 'vue',
34
+  path: `king/${verNow}/`
35
+}))
36
+
37
+webpackConfig.output.publicPath = `//kuyi.shengws.com/king/${verNow}/`
38
+// webpackConfig.output.filename = utils.assetsPath('js/[name].js')
39
+// webpackConfig.output.chunkFilename = utils.assetsPath('js/[id].js')
40
+
41
+// console.log(webpackConfig.plugins)
42
+// console.log(typeof webpackConfig.plugins)
43
+// console.log(Object.keys(webpackConfig.plugins))
44
+// webpackConfig.plugins.filter((el)=>{
45
+//   console.log(el)
46
+// })
47
+// return
48
+
49
+rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => {
50
+  if (err) throw err
51
+  console.log('run build')
52
+  webpack(webpackConfig, (err, stats) => {
53
+    spinner.stop()
54
+    if (err) throw err
55
+    process.stdout.write(stats.toString({
56
+      colors: true,
57
+      modules: false,
58
+      children: false, // If you are using ts-loader, setting this to true will make TypeScript errors show up during build.
59
+      chunks: false,
60
+      chunkModules: false
61
+    }) + '\n\n')
62
+
63
+    if (stats.hasErrors()) {
64
+      console.log(chalk.red('  Build failed with errors.\n'))
65
+      process.exit(1)
66
+    }
67
+    console.log('verNow,', verNow)
68
+
69
+    writeJson.promise(path.join(__dirname, './cdn.json'), {
70
+      version: verNow
71
+    }).then(function() {
72
+      // do stuff
73
+      console.log('write cdn.json ok')
74
+    })
75
+
76
+    console.log(chalk.cyan('  Build complete.\n'))
77
+    console.log(chalk.yellow(
78
+      '  Tip: built files are meant to be served over an HTTP server.\n' +
79
+      '  Opening index.html over file:// won\'t work.\n'
80
+    ))
81
+  })
82
+})

+ 56 - 0
build/build.js View File

@@ -0,0 +1,56 @@
1
+'use strict'
2
+require('./check-versions')()
3
+
4
+const ora = require('ora')
5
+const rm = require('rimraf')
6
+const path = require('path')
7
+const chalk = require('chalk')
8
+const webpack = require('webpack')
9
+const config = require('../config')
10
+const webpackConfig = require('./webpack.prod.conf')
11
+var connect = require('connect');
12
+var serveStatic = require('serve-static')
13
+
14
+const spinner = ora('building for ' + process.env.env_config + ' environment...')
15
+spinner.start()
16
+
17
+rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => {
18
+  if (err) throw err
19
+  webpack(webpackConfig, (err, stats) => {
20
+    spinner.stop()
21
+    if (err) throw err
22
+    process.stdout.write(stats.toString({
23
+      colors: true,
24
+      modules: false,
25
+      children: false,
26
+      chunks: false,
27
+      chunkModules: false
28
+    }) + '\n\n')
29
+
30
+    if (stats.hasErrors()) {
31
+      console.log(chalk.red(' Build failed with errors.\n'))
32
+      process.exit(1)
33
+    }
34
+
35
+    console.log(chalk.cyan(' Build complete.\n'))
36
+    console.log(chalk.yellow(
37
+      ' Tip: built files are meant to be served over an HTTP server.\n' +
38
+      ' Opening index.html over file:// won\'t work.\n'
39
+    ))
40
+
41
+    if (process.env.npm_config_preview) {
42
+      const port = 9526
43
+      const host = "http://localhost:" + port
44
+      const basePath = config.build.assetsPublicPath
45
+      const app = connect()
46
+
47
+      app.use(basePath, serveStatic('./dist', {
48
+        'index': ['index.html', '/']
49
+      }))
50
+
51
+      app.listen(port, function () {
52
+        console.log(chalk.green(`> Listening at  http://localhost:${port}${basePath}`))
53
+      });
54
+    }
55
+  })
56
+})

+ 3 - 0
build/cdn.json View File

@@ -0,0 +1,3 @@
1
+{
2
+  "version": "1.0.5"
3
+}

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

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

BIN
build/logo.png View File


+ 111 - 0
build/utils.js View File

@@ -0,0 +1,111 @@
1
+'use strict'
2
+const path = require('path')
3
+const config = require('../config')
4
+const ExtractTextPlugin = require('extract-text-webpack-plugin')
5
+const packageConfig = require('../package.json')
6
+
7
+exports.assetsPath = function (_path) {
8
+  const assetsSubDirectory = process.env.NODE_ENV === 'production'
9
+    ? config.build.assetsSubDirectory
10
+    : config.dev.assetsSubDirectory
11
+
12
+  return path.posix.join(assetsSubDirectory, _path)
13
+}
14
+
15
+exports.cssLoaders = function (options) {
16
+  options = options || {}
17
+
18
+  const cssLoader = {
19
+    loader: 'css-loader',
20
+    options: {
21
+      sourceMap: options.sourceMap
22
+    }
23
+  }
24
+
25
+  const postcssLoader = {
26
+    loader: 'postcss-loader',
27
+    options: {
28
+      sourceMap: options.sourceMap
29
+    }
30
+  }
31
+
32
+  // generate loader string to be used with extract text plugin
33
+  function generateLoaders (loader, loaderOptions) {
34
+    const loaders = options.usePostCSS ? [cssLoader, postcssLoader] : [cssLoader]
35
+
36
+    if (loader) {
37
+      loaders.push({
38
+        loader: loader + '-loader',
39
+        options: Object.assign({}, loaderOptions, {
40
+          sourceMap: options.sourceMap
41
+        })
42
+      })
43
+    }
44
+
45
+    // Extract CSS when that option is specified
46
+    // (which is the case during production build)
47
+    if (options.extract) {
48
+      return ExtractTextPlugin.extract({
49
+        use: loaders,
50
+        fallback: 'vue-style-loader',
51
+        publicPath: '../../'
52
+      })
53
+    } else {
54
+      return ['vue-style-loader'].concat(loaders)
55
+    }
56
+  }
57
+
58
+  // https://vue-loader.vuejs.org/en/configurations/extract-css.html
59
+  return {
60
+    css: generateLoaders(),
61
+    postcss: generateLoaders(),
62
+    less: generateLoaders('less'),
63
+    sass: generateLoaders('sass', { indentedSyntax: true }),
64
+    scss: generateLoaders('sass').concat(
65
+      {
66
+        loader: 'sass-resources-loader',
67
+        options: {
68
+          resources: path.resolve(__dirname, '../src/styles/variables.scss')//这里按照你的文件路径填写
69
+        }
70
+      }
71
+    ),
72
+    // scss: generateLoaders('sass'),
73
+    stylus: generateLoaders('stylus'),
74
+    styl: generateLoaders('stylus')
75
+  }
76
+}
77
+
78
+
79
+// Generate loaders for standalone style files (outside of .vue)
80
+exports.styleLoaders = function (options) {
81
+  const output = []
82
+  const loaders = exports.cssLoaders(options)
83
+
84
+  for (const extension in loaders) {
85
+    const loader = loaders[extension]
86
+    output.push({
87
+      test: new RegExp('\\.' + extension + '$'),
88
+      use: loader
89
+    })
90
+  }
91
+
92
+  return output
93
+}
94
+
95
+exports.createNotifierCallback = () => {
96
+  const notifier = require('node-notifier')
97
+
98
+  return (severity, errors) => {
99
+    if (severity !== 'error') return
100
+
101
+    const error = errors[0]
102
+    const filename = error.file && error.file.split('!').pop()
103
+
104
+    notifier.notify({
105
+      title: packageConfig.name,
106
+      message: severity + ': ' + error.name,
107
+      subtitle: filename || '',
108
+      icon: path.join(__dirname, 'logo.png')
109
+    })
110
+  }
111
+}

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

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

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

@@ -0,0 +1,105 @@
1
+'use strict'
2
+const path = require('path')
3
+const utils = require('./utils')
4
+const config = require('../config')
5
+const vueLoaderConfig = require('./vue-loader.conf')
6
+
7
+function resolve (dir) {
8
+  return path.join(__dirname, '..', dir)
9
+}
10
+
11
+const createLintingRule = () => ({
12
+  test: /\.(js|vue)$/,
13
+  loader: 'eslint-loader',
14
+  enforce: 'pre',
15
+  include: [resolve('src'), resolve('test')],
16
+  options: {
17
+    formatter: require('eslint-friendly-formatter'),
18
+    emitWarning: !config.dev.showEslintErrorsInOverlay
19
+  }
20
+})
21
+
22
+module.exports = {
23
+  context: path.resolve(__dirname, '../'),
24
+  entry: {
25
+    app: './src/main.js'
26
+  },
27
+  output: {
28
+    path: config.build.assetsRoot,
29
+    filename: '[name].js',
30
+    publicPath: process.env.NODE_ENV === 'production'
31
+      ? config.build.assetsPublicPath
32
+      : config.dev.assetsPublicPath
33
+  },
34
+  resolve: {
35
+    extensions: ['.js', '.vue', '.json'],
36
+    alias: {
37
+      'vue$': 'vue/dist/vue.esm.js',
38
+      '@': resolve('src'),
39
+    }
40
+  },
41
+  module: {
42
+    rules: [
43
+      // ...(config.dev.useEslint ? [createLintingRule()] : []),
44
+      {
45
+        test: /\.vue$/,
46
+        loader: 'vue-loader',
47
+        options: vueLoaderConfig
48
+      },
49
+      {
50
+        test: /\.js$/,
51
+        loader: 'babel-loader?cacheDirectory',
52
+        include: [resolve('src'), resolve('test'), resolve('node_modules/webpack-dev-server/client')]
53
+      },
54
+      {
55
+        test: /\.svg$/,
56
+        loader: 'svg-sprite-loader',
57
+        include: [resolve('src/icons')],
58
+        options: {
59
+          symbolId: 'icon-[name]'
60
+        }
61
+      },
62
+      {
63
+        test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
64
+        loader: 'url-loader',
65
+        exclude: [resolve('src/icons')],
66
+        options: {
67
+          limit: 10000,
68
+          name: utils.assetsPath('img/[name].[hash:7].[ext]')
69
+        }
70
+      },
71
+      {
72
+        test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
73
+        loader: 'url-loader',
74
+        options: {
75
+          limit: 10000,
76
+          name: utils.assetsPath('media/[name].[hash:7].[ext]')
77
+        }
78
+      },
79
+      {
80
+        test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
81
+        loader: 'url-loader',
82
+        options: {
83
+          limit: 10000,
84
+          name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
85
+        }
86
+      },
87
+      {
88
+        test: /\.sass$/,
89
+        loaders: ['style', 'css', 'sass']
90
+      }
91
+    ]
92
+  },
93
+  node: {
94
+    // prevent webpack from injecting useless setImmediate polyfill because Vue
95
+    // source contains it (although only uses it if it's native).
96
+    setImmediate: false,
97
+    // prevent webpack from injecting mocks to Node native modules
98
+    // that does not make sense for the client
99
+    dgram: 'empty',
100
+    fs: 'empty',
101
+    net: 'empty',
102
+    tls: 'empty',
103
+    child_process: 'empty'
104
+  }
105
+}

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

@@ -0,0 +1,88 @@
1
+'use strict'
2
+const path = require('path')
3
+const utils = require('./utils')
4
+const webpack = require('webpack')
5
+const config = require('../config')
6
+const merge = require('webpack-merge')
7
+const baseWebpackConfig = require('./webpack.base.conf')
8
+const HtmlWebpackPlugin = require('html-webpack-plugin')
9
+const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin')
10
+const portfinder = require('portfinder')
11
+
12
+function resolve (dir) {
13
+  return path.join(__dirname, '..', dir)
14
+}
15
+
16
+const HOST = process.env.HOST
17
+const PORT = process.env.PORT && Number(process.env.PORT)
18
+
19
+const devWebpackConfig = merge(baseWebpackConfig, {
20
+  module: {
21
+    rules: utils.styleLoaders({ sourceMap: config.dev.cssSourceMap, usePostCSS: true })
22
+  },
23
+  // cheap-module-eval-source-map is faster for development
24
+  devtool: config.dev.devtool,
25
+
26
+  // these devServer options should be customized in /config/index.js
27
+  devServer: {
28
+    clientLogLevel: 'warning',
29
+    historyApiFallback: true,
30
+    hot: true,
31
+    compress: true,
32
+    host: HOST || config.dev.host,
33
+    port: PORT || config.dev.port,
34
+    open: config.dev.autoOpenBrowser,
35
+    overlay: config.dev.errorOverlay
36
+      ? { warnings: false, errors: true }
37
+      : false,
38
+    publicPath: config.dev.assetsPublicPath,
39
+    proxy: config.dev.proxyTable,
40
+    quiet: true, // necessary for FriendlyErrorsPlugin
41
+    watchOptions: {
42
+      poll: config.dev.poll,
43
+    }
44
+  },
45
+  plugins: [
46
+    new webpack.DefinePlugin({
47
+      'process.env': require('../config/dev.env')
48
+    }),
49
+    new webpack.HotModuleReplacementPlugin(),
50
+    new webpack.NamedModulesPlugin(), // HMR shows correct file names in console on update.
51
+    new webpack.NoEmitOnErrorsPlugin(),
52
+    // https://github.com/ampedandwired/html-webpack-plugin
53
+    new HtmlWebpackPlugin({
54
+      filename: 'index.html',
55
+      template: 'index.html',
56
+      inject: true,
57
+      favicon: resolve('favicon.ico'),
58
+      title: '血透系统',
59
+      path: config.dev.assetsPublicPath + config.dev.assetsSubDirectory
60
+    }),
61
+  ]
62
+})
63
+
64
+module.exports = new Promise((resolve, reject) => {
65
+  portfinder.basePort = process.env.PORT || config.dev.port
66
+  portfinder.getPort((err, port) => {
67
+    if (err) {
68
+      reject(err)
69
+    } else {
70
+      // publish the new Port, necessary for e2e tests
71
+      process.env.PORT = port
72
+      // add port to devServer config
73
+      devWebpackConfig.devServer.port = port
74
+
75
+      // Add FriendlyErrorsPlugin
76
+      devWebpackConfig.plugins.push(new FriendlyErrorsPlugin({
77
+        compilationSuccessInfo: {
78
+          messages: [`Your application is running here: http://${devWebpackConfig.devServer.host}:${port}`],
79
+        },
80
+        onErrors: config.dev.notifyOnErrors
81
+        ? utils.createNotifierCallback()
82
+        : undefined
83
+      }))
84
+
85
+      resolve(devWebpackConfig)
86
+    }
87
+  })
88
+})

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

@@ -0,0 +1,151 @@
1
+'use strict'
2
+const path = require('path')
3
+const utils = require('./utils')
4
+const webpack = require('webpack')
5
+const config = require('../config')
6
+const merge = require('webpack-merge')
7
+const baseWebpackConfig = require('./webpack.base.conf')
8
+const CopyWebpackPlugin = require('copy-webpack-plugin')
9
+const HtmlWebpackPlugin = require('html-webpack-plugin')
10
+const ExtractTextPlugin = require('extract-text-webpack-plugin')
11
+const OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin')
12
+const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
13
+
14
+const env = require('../config/prod.env')
15
+
16
+const webpackConfig = merge(baseWebpackConfig, {
17
+  module: {
18
+    rules: utils.styleLoaders({
19
+      sourceMap: config.build.productionSourceMap,
20
+      extract: true,
21
+      usePostCSS: true
22
+    })
23
+  },
24
+  devtool: config.build.productionSourceMap ? config.build.devtool : false,
25
+  output: {
26
+    path: config.build.assetsRoot,
27
+    filename: utils.assetsPath('js/[name].[chunkhash:6].js'), // .[chunkhash:6]
28
+    chunkFilename: utils.assetsPath('js/[id].[chunkhash:6].js') //.[chunkhash:6]
29
+  },
30
+  plugins: [
31
+    new webpack.DefinePlugin({
32
+      'process.env': env
33
+    }),
34
+    new UglifyJsPlugin({
35
+      uglifyOptions: {
36
+        compress: {
37
+          warnings: false
38
+        }
39
+      },
40
+      sourceMap: config.build.productionSourceMap,
41
+      parallel: true
42
+    }),
43
+    // extract css into its own file
44
+    new ExtractTextPlugin({
45
+      filename: utils.assetsPath('css/[name].[contenthash:6].css'), //
46
+      // Setting the following option to `false` will not extract CSS from codesplit chunks.
47
+      // Their CSS will instead be inserted dynamically with style-loader when the codesplit chunk has been loaded by webpack.
48
+      // It's currently set to `true` because we are seeing that sourcemaps are included in the codesplit bundle as well when it's `false`,
49
+      // increasing file size: https://github.com/vuejs-templates/webpack/issues/1110
50
+      allChunks: true,
51
+    }),
52
+    // Compress extracted CSS. We are using this plugin so that possible
53
+    // duplicated CSS from different components can be deduped.
54
+    new OptimizeCSSPlugin({
55
+      cssProcessorOptions: config.build.productionSourceMap
56
+        ? { safe: true, map: { inline: false } }
57
+        : { safe: true }
58
+    }),
59
+    // generate dist index.html with correct asset hash for caching.
60
+    // you can customize output by editing /index.html
61
+    // see https://github.com/ampedandwired/html-webpack-plugin
62
+    new HtmlWebpackPlugin({
63
+      filename: config.build.index,
64
+      template: 'index.html',
65
+      inject: true,
66
+      minify: {
67
+        removeComments: true,
68
+        collapseWhitespace: true,
69
+        removeAttributeQuotes: true
70
+        // more options:
71
+        // https://github.com/kangax/html-minifier#options-quick-reference
72
+      },
73
+      // 公共文件必须在自己引用的js文件之前引用 by vinceHuang
74
+      // chunks:['mainfest','vender','app'],
75
+      // necessary to consistently work with multiple chunks via CommonsChunkPlugin
76
+      // chunksSortMode: 'dependency'
77
+    }),
78
+    // keep module.id stable when vendor modules does not change
79
+    // new webpack.HashedModuleIdsPlugin(),
80
+    // enable scope hoisting
81
+    // new webpack.optimize.ModuleConcatenationPlugin(),
82
+    // split vendor js into its own file
83
+    // new webpack.optimize.CommonsChunkPlugin({
84
+    //   name: 'vendor',
85
+    //   minChunks (module) {
86
+    //     // any required modules inside node_modules are extracted to vendor
87
+    //     return (
88
+    //       module.resource &&
89
+    //       /\.js$/.test(module.resource) &&
90
+    //       module.resource.indexOf(
91
+    //         path.join(__dirname, '../node_modules')
92
+    //       ) === 0
93
+    //     )
94
+    //   }
95
+    // }),
96
+    // extract webpack runtime and module manifest to its own file in order to
97
+    // prevent vendor hash from being updated whenever app bundle is updated
98
+    // new webpack.optimize.CommonsChunkPlugin({
99
+    //   name: 'manifest',
100
+    //   minChunks: Infinity
101
+    // }),
102
+    // This instance extracts shared chunks from code splitted chunks and bundles them
103
+    // in a separate chunk, similar to the vendor chunk
104
+    // see: https://webpack.js.org/plugins/commons-chunk-plugin/#extra-async-commons-chunk
105
+    // new webpack.optimize.CommonsChunkPlugin({
106
+    //   name: 'app',
107
+    //   async: 'vendor-async',
108
+    //   children: true,
109
+    //   minChunks: 3
110
+    // }),
111
+
112
+    // copy custom static assets
113
+    new CopyWebpackPlugin([
114
+      {
115
+        from: path.resolve(__dirname, '../static'),
116
+        to: config.build.assetsSubDirectory,
117
+        ignore: ['.*']
118
+      }
119
+    ])
120
+  ]
121
+})
122
+
123
+if (config.build.productionGzip) {
124
+  const CompressionWebpackPlugin = require('compression-webpack-plugin')
125
+
126
+  webpackConfig.plugins.push(
127
+    new CompressionWebpackPlugin({
128
+      asset: '[path].gz[query]',
129
+      algorithm: 'gzip',
130
+      test: new RegExp(
131
+        '\\.(' +
132
+        config.build.productionGzipExtensions.join('|') +
133
+        ')$'
134
+      ),
135
+      threshold: 10240,
136
+      minRatio: 0.8
137
+    })
138
+  )
139
+}
140
+
141
+if (config.build.bundleAnalyzerReport) {
142
+  const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
143
+  webpackConfig.plugins.push(new BundleAnalyzerPlugin())
144
+}
145
+
146
+webpackConfig.plugins = webpackConfig.plugins || [];
147
+
148
+webpackConfig.devtool = "source-map"
149
+
150
+
151
+module.exports = webpackConfig

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

@@ -0,0 +1,175 @@
1
+'use strict'
2
+const path = require('path')
3
+const utils = require('./utils')
4
+const webpack = require('webpack')
5
+const config = require('../config')
6
+const merge = require('webpack-merge')
7
+const baseWebpackConfig = require('./webpack.base.conf')
8
+const CopyWebpackPlugin = require('copy-webpack-plugin')
9
+const HtmlWebpackPlugin = require('html-webpack-plugin')
10
+const ExtractTextPlugin = require('extract-text-webpack-plugin')
11
+const OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin')
12
+const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
13
+
14
+function resolve (dir) {
15
+  return path.join(__dirname, '..', dir)
16
+}
17
+
18
+const env = require('../config/'+process.env.env_config+'.env')
19
+
20
+const webpackConfig = merge(baseWebpackConfig, {
21
+  module: {
22
+    rules: utils.styleLoaders({
23
+      sourceMap: config.build.productionSourceMap,
24
+      extract: true,
25
+      usePostCSS: true
26
+    })
27
+  },
28
+  devtool: config.build.productionSourceMap ? config.build.devtool : false,
29
+  output: {
30
+    path: config.build.assetsRoot,
31
+    filename: utils.assetsPath('js/[name].[chunkhash].js'),
32
+    chunkFilename: utils.assetsPath('js/[id].[chunkhash].js')
33
+  },
34
+  plugins: [
35
+    // http://vuejs.github.io/vue-loader/en/workflow/production.html
36
+    new webpack.DefinePlugin({
37
+      'process.env': env
38
+    }),
39
+    new UglifyJsPlugin({
40
+      uglifyOptions: {
41
+        compress: {
42
+          warnings: false
43
+        }
44
+      },
45
+      sourceMap: config.build.productionSourceMap,
46
+      parallel: true
47
+    }),
48
+    // extract css into its own file
49
+    new ExtractTextPlugin({
50
+      filename: utils.assetsPath('css/[name].[contenthash].css'),
51
+      // Setting the following option to `false` will not extract CSS from codesplit chunks.
52
+      // Their CSS will instead be inserted dynamically with style-loader when the codesplit chunk has been loaded by webpack.
53
+      // increasing file size: https://github.com/vuejs-templates/webpack/issues/1110
54
+      allChunks: false,
55
+    }),
56
+    // Compress extracted CSS. We are using this plugin so that possible
57
+    // duplicated CSS from different components can be deduped.
58
+    new OptimizeCSSPlugin({
59
+      cssProcessorOptions: config.build.productionSourceMap
60
+        ? { safe: true, map: { inline: false } }
61
+        : { safe: true }
62
+    }),
63
+    // generate dist index.html with correct asset hash for caching.
64
+    // you can customize output by editing /index.html
65
+    // see https://github.com/ampedandwired/html-webpack-plugin
66
+    new HtmlWebpackPlugin({
67
+      filename: config.build.index,
68
+      template: 'index.html',
69
+      inject: true,
70
+      favicon: resolve('favicon.ico'),
71
+      title: 'vue-element-admin',
72
+      path: config.build.assetsPublicPath + config.build.assetsSubDirectory,
73
+      minify: {
74
+        removeComments: true,
75
+        collapseWhitespace: true,
76
+        removeAttributeQuotes: true
77
+        // more options:
78
+        // https://github.com/kangax/html-minifier#options-quick-reference
79
+      },
80
+      // necessary to consistently work with multiple chunks via CommonsChunkPlugin
81
+      chunksSortMode: 'dependency'
82
+    }),
83
+    // keep module.id stable when vender modules does not change
84
+    new webpack.HashedModuleIdsPlugin(),
85
+    // enable scope hoisting
86
+    new webpack.optimize.ModuleConcatenationPlugin(),
87
+    // split vendor js into its own file
88
+    new webpack.optimize.CommonsChunkPlugin({
89
+      name: 'vendor',
90
+      minChunks (module) {
91
+        // any required modules inside node_modules are extracted to vendor
92
+        return (
93
+          module.resource &&
94
+          /\.js$/.test(module.resource) &&
95
+          module.resource.indexOf(
96
+            path.join(__dirname, '../node_modules')
97
+          ) === 0
98
+        )
99
+      }
100
+    }),
101
+    // extract webpack runtime and module manifest to its own file in order to
102
+    // prevent vendor hash from being updated whenever app bundle is updated
103
+    new webpack.optimize.CommonsChunkPlugin({
104
+      name: 'manifest',
105
+      minChunks: Infinity
106
+    }),
107
+    // This instance extracts shared chunks from code splitted chunks and bundles them
108
+    // in a separate chunk, similar to the vendor chunk
109
+    // see: https://webpack.js.org/plugins/commons-chunk-plugin/#extra-async-commons-chunk
110
+    new webpack.optimize.CommonsChunkPlugin({
111
+      name: 'app',
112
+      async: 'vendor-async',
113
+      children: true,
114
+      minChunks: 3
115
+    }),
116
+    // split echarts into its own file
117
+    new webpack.optimize.CommonsChunkPlugin({
118
+      async: 'echarts',
119
+      minChunks(module) {
120
+        var context = module.context;
121
+        return context && (context.indexOf('echarts') >= 0 || context.indexOf('zrender') >= 0);
122
+      }
123
+    }),
124
+    // split xlsx into its own file
125
+    new webpack.optimize.CommonsChunkPlugin({
126
+      async: 'xlsx',
127
+      minChunks(module) {
128
+        var context = module.context;
129
+        return context && (context.indexOf('xlsx') >= 0);
130
+      }
131
+    }),
132
+     // split codemirror into its own file
133
+     new webpack.optimize.CommonsChunkPlugin({
134
+      async: 'codemirror',
135
+      minChunks(module) {
136
+        var context = module.context;
137
+        return context && (context.indexOf('codemirror') >= 0);
138
+      }
139
+    }),
140
+
141
+    // copy custom static assets
142
+    new CopyWebpackPlugin([
143
+      {
144
+        from: path.resolve(__dirname, '../static'),
145
+        to: config.build.assetsSubDirectory,
146
+        ignore: ['.*']
147
+      }
148
+    ])
149
+  ]
150
+})
151
+
152
+if (config.build.productionGzip) {
153
+  const CompressionWebpackPlugin = require('compression-webpack-plugin')
154
+
155
+  webpackConfig.plugins.push(
156
+    new CompressionWebpackPlugin({
157
+      asset: '[path].gz[query]',
158
+      algorithm: 'gzip',
159
+      test: new RegExp(
160
+        '\\.(' +
161
+        config.build.productionGzipExtensions.join('|') +
162
+        ')$'
163
+      ),
164
+      threshold: 10240,
165
+      minRatio: 0.8
166
+    })
167
+  )
168
+}
169
+
170
+if (config.build.bundleAnalyzerReport) {
171
+  const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
172
+  webpackConfig.plugins.push(new BundleAnalyzerPlugin())
173
+}
174
+
175
+module.exports = webpackConfig