├── .babelrc ├── .editorconfig ├── .eslintignore ├── .eslintrc.js ├── .gitignore ├── .postcssrc.js ├── README.md ├── build ├── build.js ├── check-versions.js ├── dev-client.js ├── dev-server.js ├── utils.js ├── vue-loader.conf.js ├── webpack.base.conf.js ├── webpack.dev.conf.js ├── webpack.prod.conf.js └── webpack.test.conf.js ├── config ├── dev.env.js ├── index.js ├── prod.env.js └── test.env.js ├── index.html ├── package.json ├── src ├── App.vue ├── assets │ └── logo.png ├── components │ ├── HelloWorld.vue │ └── renderComponent.vue ├── main.ts ├── mixins │ └── test-mixin.ts ├── router │ └── index.ts ├── store │ ├── index.ts │ └── modules │ │ └── user.ts └── vue-shim.d.ts ├── static └── .gitkeep ├── test ├── e2e │ ├── custom-assertions │ │ └── elementCount.js │ ├── nightwatch.conf.js │ ├── runner.js │ └── specs │ │ └── test.js └── unit │ ├── .eslintrc │ ├── index.js │ ├── karma.conf.js │ └── specs │ └── Hello.spec.js ├── tsconfig.json ├── tslint.json └── yarn.lock /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["env", { 4 | "modules": false, 5 | "targets": { 6 | "browsers": ["> 1%", "last 2 versions", "not ie <= 8"] 7 | } 8 | }], 9 | "stage-2" 10 | ], 11 | "plugins": [ 12 | "transform-vue-jsx", 13 | "transform-runtime" 14 | ], 15 | "env": { 16 | "test": { 17 | "presets": ["env", "stage-2"], 18 | "plugins": ["istanbul"] 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | indent_style = space 6 | indent_size = 2 7 | end_of_line = lf 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | build/*.js 2 | config/*.js 3 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | // https://eslint.org/docs/user-guide/configuring 2 | 3 | module.exports = { 4 | root: true, 5 | parser: 'babel-eslint', 6 | parserOptions: { 7 | sourceType: 'module' 8 | }, 9 | env: { 10 | browser: true, 11 | }, 12 | // https://github.com/standard/standard/blob/master/docs/RULES-en.md 13 | extends: 'standard', 14 | globals: { 15 | _: true 16 | }, 17 | // required to lint *.vue files 18 | plugins: [ 19 | 'html' 20 | ], 21 | // add your custom rules here 22 | 'rules': { 23 | // allow paren-less arrow functions 24 | 'arrow-parens': 0, 25 | // allow async-await 26 | 'generator-star-spacing': 0, 27 | // allow debugger during development 28 | 'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules/ 3 | dist/ 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | test/unit/coverage 8 | test/e2e/reports 9 | selenium-debug.log 10 | 11 | # Editor directories and files 12 | .idea 13 | .vscode 14 | *.suo 15 | *.ntvs* 16 | *.njsproj 17 | *.sln 18 | -------------------------------------------------------------------------------- /.postcssrc.js: -------------------------------------------------------------------------------- 1 | // https://github.com/michael-ciniawsky/postcss-load-config 2 | 3 | module.exports = { 4 | "plugins": { 5 | // to edit target browsers: use "browserslist" field in package.json 6 | "autoprefixer": {} 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vue-typescript-starter 2 | 3 | > 这个项目起始于在vue加入强类型的念头,目的是提供一个手脚架快速上手和开始, 主要是基于vue + typescript 使用 .vue 单文件开发脚手架,支持jsx 4 | 5 | ## 此repo是基于[Vue + TypeScript 新项目起手式](https://juejin.im/post/59f29d28518825549f7260b6)逐步实现的 6 | 7 | 如果你按照文章没有配出来的话,可以参考这个项目的代码,进行比较 8 | 9 | ## 特性 10 | - webpack4 11 | - vue 12 | - vue-router 13 | - vuex 14 | - typescript 15 | - jsx 16 | - tslint 17 | - 单vue文件开发 18 | - vue-cli 19 | - ~~eslint~~ 20 | 21 | ## 开始 22 | 23 | ``` bash 24 | 25 | # To create a new vue + typescript project, run: 26 | vue init ws456999/vue-typescript-starter#template `your project name` 27 | 28 | # then 29 | cd `your project name` 30 | 31 | # Install project dependencies 32 | npm install 33 | 34 | # serve with hot reload at localhost:8080 35 | npm run dev 36 | 37 | # build for production with minification 38 | npm run build 39 | 40 | ``` 41 | 42 | ## change log 43 | 44 | *2018-07-12* 45 | - support vue-cli 46 | 47 | > vue init ws456999/vue-typescript-starter#template `your project name` 48 | 49 | *2018-06-30* 50 | 51 | - upgrade dependencies 52 | - remove eslint 53 | - add script lint 54 | 55 | *2018-04-12* 56 | 57 | - upgrade webpack4 58 | -------------------------------------------------------------------------------- /build/build.js: -------------------------------------------------------------------------------- 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.conf') 13 | 14 | const spinner = ora('building for production...') 15 | spinner.start() 16 | 17 | rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => { 18 | if (err) throw err 19 | webpack(webpackConfig, function (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 | }) 42 | -------------------------------------------------------------------------------- /build/check-versions.js: -------------------------------------------------------------------------------- 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 | function exec (cmd) { 7 | return require('child_process').execSync(cmd).toString().trim() 8 | } 9 | 10 | const versionRequirements = [ 11 | { 12 | name: 'node', 13 | currentVersion: semver.clean(process.version), 14 | versionRequirement: packageConfig.engines.node 15 | } 16 | ] 17 | 18 | if (shell.which('npm')) { 19 | versionRequirements.push({ 20 | name: 'npm', 21 | currentVersion: exec('npm --version'), 22 | versionRequirement: packageConfig.engines.npm 23 | }) 24 | } 25 | 26 | module.exports = function () { 27 | const warnings = [] 28 | for (let i = 0; i < versionRequirements.length; i++) { 29 | const mod = versionRequirements[i] 30 | if (!semver.satisfies(mod.currentVersion, mod.versionRequirement)) { 31 | warnings.push(mod.name + ': ' + 32 | chalk.red(mod.currentVersion) + ' should be ' + 33 | chalk.green(mod.versionRequirement) 34 | ) 35 | } 36 | } 37 | 38 | if (warnings.length) { 39 | console.log('') 40 | console.log(chalk.yellow('To use this template, you must update following to modules:')) 41 | console.log() 42 | for (let i = 0; i < warnings.length; i++) { 43 | const warning = warnings[i] 44 | console.log(' ' + warning) 45 | } 46 | console.log() 47 | process.exit(1) 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /build/dev-client.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | 'use strict' 3 | require('eventsource-polyfill') 4 | var hotClient = require('webpack-hot-middleware/client?noInfo=true&reload=true') 5 | 6 | hotClient.subscribe(function (event) { 7 | if (event.action === 'reload') { 8 | window.location.reload() 9 | } 10 | }) 11 | -------------------------------------------------------------------------------- /build/dev-server.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | require('./check-versions')() 3 | 4 | const config = require('../config') 5 | if (!process.env.NODE_ENV) { 6 | process.env.NODE_ENV = JSON.parse(config.dev.env.NODE_ENV) 7 | } 8 | 9 | const opn = require('opn') 10 | const path = require('path') 11 | const express = require('express') 12 | const webpack = require('webpack') 13 | const proxyMiddleware = require('http-proxy-middleware') 14 | const webpackConfig = (process.env.NODE_ENV === 'testing' || process.env.NODE_ENV === 'production') 15 | ? require('./webpack.prod.conf') 16 | : require('./webpack.dev.conf') 17 | 18 | // default port where dev server listens for incoming traffic 19 | const port = process.env.PORT || config.dev.port 20 | // automatically open browser, if not set will be false 21 | const autoOpenBrowser = !!config.dev.autoOpenBrowser 22 | // Define HTTP proxies to your custom API backend 23 | // https://github.com/chimurai/http-proxy-middleware 24 | const proxyTable = config.dev.proxyTable 25 | 26 | const app = express() 27 | const compiler = webpack(webpackConfig) 28 | 29 | const devMiddleware = require('webpack-dev-middleware')(compiler, { 30 | publicPath: webpackConfig.output.publicPath, 31 | quiet: true 32 | }) 33 | 34 | const hotMiddleware = require('webpack-hot-middleware')(compiler, { 35 | log: false, 36 | heartbeat: 2000 37 | }) 38 | // force page reload when html-webpack-plugin template changes 39 | // currently disabled until this is resolved: 40 | // https://github.com/jantimon/html-webpack-plugin/issues/680 41 | // compiler.plugin('compilation', function (compilation) { 42 | // compilation.plugin('html-webpack-plugin-after-emit', function (data, cb) { 43 | // hotMiddleware.publish({ action: 'reload' }) 44 | // cb() 45 | // }) 46 | // }) 47 | 48 | // enable hot-reload and state-preserving 49 | // compilation error display 50 | app.use(hotMiddleware) 51 | 52 | // proxy api requests 53 | Object.keys(proxyTable).forEach(function (context) { 54 | let options = proxyTable[context] 55 | if (typeof options === 'string') { 56 | options = { target: options } 57 | } 58 | app.use(proxyMiddleware(options.filter || context, options)) 59 | }) 60 | 61 | // handle fallback for HTML5 history API 62 | app.use(require('connect-history-api-fallback')()) 63 | 64 | // serve webpack bundle output 65 | app.use(devMiddleware) 66 | 67 | // serve pure static assets 68 | const staticPath = path.posix.join(config.dev.assetsPublicPath, config.dev.assetsSubDirectory) 69 | app.use(staticPath, express.static('./static')) 70 | 71 | const uri = 'http://localhost:' + port 72 | 73 | var _resolve 74 | var _reject 75 | var readyPromise = new Promise((resolve, reject) => { 76 | _resolve = resolve 77 | _reject = reject 78 | }) 79 | 80 | var server 81 | var portfinder = require('portfinder') 82 | portfinder.basePort = port 83 | 84 | console.log('> Starting dev server...') 85 | devMiddleware.waitUntilValid(() => { 86 | portfinder.getPort((err, port) => { 87 | if (err) { 88 | _reject(err) 89 | } 90 | process.env.PORT = port 91 | var uri = 'http://localhost:' + port 92 | console.log('> Listening at ' + uri + '\n') 93 | // when env is testing, don't need open it 94 | if (autoOpenBrowser && process.env.NODE_ENV !== 'testing') { 95 | opn(uri) 96 | } 97 | server = app.listen(port) 98 | _resolve() 99 | }) 100 | }) 101 | 102 | module.exports = { 103 | ready: readyPromise, 104 | close: () => { 105 | server.close() 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /build/utils.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | const path = require('path') 3 | const config = require('../config') 4 | const ExtractTextPlugin = require('extract-text-webpack-plugin') 5 | 6 | exports.assetsPath = function (_path) { 7 | const assetsSubDirectory = process.env.NODE_ENV === 'production' 8 | ? config.build.assetsSubDirectory 9 | : config.dev.assetsSubDirectory 10 | return path.posix.join(assetsSubDirectory, _path) 11 | } 12 | 13 | exports.cssLoaders = function (options) { 14 | options = options || {} 15 | 16 | const cssLoader = { 17 | loader: 'css-loader', 18 | options: { 19 | minimize: process.env.NODE_ENV === 'production', 20 | sourceMap: options.sourceMap 21 | } 22 | } 23 | 24 | // generate loader string to be used with extract text plugin 25 | function generateLoaders (loader, loaderOptions) { 26 | const loaders = [cssLoader] 27 | if (loader) { 28 | loaders.push({ 29 | loader: loader + '-loader', 30 | options: Object.assign({}, loaderOptions, { 31 | sourceMap: options.sourceMap 32 | }) 33 | }) 34 | } 35 | 36 | // Extract CSS when that option is specified 37 | // (which is the case during production build) 38 | if (options.extract) { 39 | return ExtractTextPlugin.extract({ 40 | use: loaders, 41 | fallback: 'vue-style-loader' 42 | }) 43 | } else { 44 | return ['vue-style-loader'].concat(loaders) 45 | } 46 | } 47 | 48 | // https://vue-loader.vuejs.org/en/configurations/extract-css.html 49 | return { 50 | css: generateLoaders(), 51 | postcss: generateLoaders(), 52 | less: generateLoaders('less'), 53 | sass: generateLoaders('sass', { indentedSyntax: true }), 54 | scss: generateLoaders('sass'), 55 | stylus: generateLoaders('stylus'), 56 | styl: generateLoaders('stylus') 57 | } 58 | } 59 | 60 | // Generate loaders for standalone style files (outside of .vue) 61 | exports.styleLoaders = function (options) { 62 | const output = [] 63 | const loaders = exports.cssLoaders(options) 64 | for (const extension in loaders) { 65 | const loader = loaders[extension] 66 | output.push({ 67 | test: new RegExp('\\.' + extension + '$'), 68 | use: loader 69 | }) 70 | } 71 | return output 72 | } 73 | -------------------------------------------------------------------------------- /build/vue-loader.conf.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | const utils = require('./utils') 3 | const config = require('../config') 4 | const isProduction = process.env.NODE_ENV === 'production' 5 | 6 | module.exports = { 7 | loaders: Object.assign(utils.cssLoaders({ 8 | sourceMap: isProduction 9 | ? config.build.productionSourceMap 10 | : config.dev.cssSourceMap, 11 | extract: isProduction 12 | }),{ 13 | ts: "ts-loader", 14 | tsx: "babel-loader!ts-loader" 15 | }), 16 | transformToRequire: { 17 | video: 'src', 18 | source: 'src', 19 | img: 'src', 20 | image: 'xlink:href' 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /build/webpack.base.conf.js: -------------------------------------------------------------------------------- 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 | const webpack = require('webpack') 7 | const { VueLoaderPlugin } = require('vue-loader') 8 | // const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin') 9 | 10 | function resolve (dir) { 11 | return path.join(__dirname, '..', dir) 12 | } 13 | 14 | module.exports = { 15 | entry: { 16 | app: './src/main.ts', 17 | vendor: [ 18 | "lodash" 19 | ] 20 | }, 21 | output: { 22 | path: config.build.assetsRoot, 23 | filename: '[name].js', 24 | publicPath: process.env.NODE_ENV === 'production' 25 | ? config.build.assetsPublicPath 26 | : config.dev.assetsPublicPath 27 | }, 28 | resolve: { 29 | extensions: ['.js', '.vue', '.json', '.ts', '.tsx'], 30 | alias: { 31 | '@': resolve('src'), 32 | } 33 | }, 34 | module: { 35 | rules: [ 36 | // { 37 | // test: /\.(js|vue)$/, 38 | // loader: 'eslint-loader', 39 | // enforce: 'pre', 40 | // include: [resolve('src'), resolve('test')], 41 | // options: { 42 | // formatter: require('eslint-friendly-formatter') 43 | // } 44 | // }, 45 | // { 46 | // test: /\.tsx?$/, 47 | // exclude: /node_modules/, 48 | // enforce: 'pre', 49 | // use: [ 50 | // { 51 | // loader: 'tslint-loader', 52 | // options: { 53 | // configFile: 'tslint.json' 54 | // } 55 | // } 56 | // ] 57 | // }, 58 | { 59 | test: /\.vue$/, 60 | loader: 'vue-loader' 61 | // options: vueLoaderConfig 62 | }, 63 | { 64 | test: /\.tsx?$/, 65 | exclude: /node_modules/, 66 | // loader: 'ts-loader', 67 | use: [ 68 | "babel-loader", 69 | { 70 | loader: "ts-loader", 71 | options: { appendTsxSuffixTo: [/\.vue$/] } 72 | }, 73 | { 74 | loader: 'tslint-loader' 75 | } 76 | ] 77 | }, 78 | { 79 | test: /\.js$/, 80 | loader: 'babel-loader', 81 | include: [resolve('src'), resolve('test')] 82 | }, 83 | { 84 | test: /\.(png|jpe?g|gif|svg)(\?.*)?$/, 85 | loader: 'url-loader', 86 | options: { 87 | limit: 10000, 88 | name: utils.assetsPath('img/[name].[hash:7].[ext]') 89 | } 90 | }, 91 | { 92 | test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/, 93 | loader: 'url-loader', 94 | options: { 95 | limit: 10000, 96 | name: utils.assetsPath('media/[name].[hash:7].[ext]') 97 | } 98 | }, 99 | { 100 | test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/, 101 | loader: 'url-loader', 102 | options: { 103 | limit: 10000, 104 | name: utils.assetsPath('fonts/[name].[hash:7].[ext]') 105 | } 106 | } 107 | ] 108 | }, 109 | plugins: [ 110 | // new ForkTsCheckerWebpackPlugin({ 111 | // tslint: true, 112 | // vue: true 113 | // }), 114 | new VueLoaderPlugin(), 115 | new webpack.ProvidePlugin({ 116 | _: 'lodash' 117 | }) 118 | ] 119 | } 120 | -------------------------------------------------------------------------------- /build/webpack.dev.conf.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | const utils = require('./utils') 3 | const webpack = require('webpack') 4 | const config = require('../config') 5 | const merge = require('webpack-merge') 6 | const baseWebpackConfig = require('./webpack.base.conf') 7 | const HtmlWebpackPlugin = require('html-webpack-plugin') 8 | const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin') 9 | 10 | // add hot-reload related code to entry chunks 11 | Object.keys(baseWebpackConfig.entry).forEach(function (name) { 12 | baseWebpackConfig.entry[name] = ['./build/dev-client'].concat(baseWebpackConfig.entry[name]) 13 | }) 14 | 15 | module.exports = merge(baseWebpackConfig, { 16 | mode: 'development', 17 | module: { 18 | rules: utils.styleLoaders({ sourceMap: config.dev.cssSourceMap }) 19 | }, 20 | // cheap-module-eval-source-map is faster for development 21 | devtool: '#cheap-module-eval-source-map', 22 | plugins: [ 23 | new webpack.DefinePlugin({ 24 | 'process.env': config.dev.env 25 | }), 26 | // https://github.com/glenjamin/webpack-hot-middleware#installation--usage 27 | new webpack.HotModuleReplacementPlugin(), 28 | new webpack.NoEmitOnErrorsPlugin(), 29 | // https://github.com/ampedandwired/html-webpack-plugin 30 | new HtmlWebpackPlugin({ 31 | filename: 'index.html', 32 | template: 'index.html', 33 | inject: true 34 | }), 35 | new FriendlyErrorsPlugin() 36 | ] 37 | }) 38 | -------------------------------------------------------------------------------- /build/webpack.prod.conf.js: -------------------------------------------------------------------------------- 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 = 15 | process.env.NODE_ENV === 'testing' 16 | ? require('../config/test.env') 17 | : config.build.env 18 | 19 | const webpackConfig = merge(baseWebpackConfig, { 20 | mode: 'production', 21 | module: { 22 | rules: utils.styleLoaders({ 23 | sourceMap: config.build.productionSourceMap, 24 | extract: true 25 | }) 26 | }, 27 | devtool: config.build.productionSourceMap ? '#source-map' : false, 28 | output: { 29 | path: config.build.assetsRoot, 30 | filename: utils.assetsPath('js/[name].[chunkhash].js'), 31 | chunkFilename: utils.assetsPath('js/[id].[chunkhash].js') 32 | }, 33 | optimization: { 34 | // chunk for the webpack runtime code and chunk manifest 35 | runtimeChunk: { 36 | name: 'manifest' 37 | }, 38 | // https://gist.github.com/sokra/1522d586b8e5c0f5072d7565c2bee693 39 | splitChunks: { 40 | cacheGroups: { 41 | vendor: { 42 | test: /[\\/]node_modules[\\/]/, 43 | name: 'vendor', 44 | priority: -20, 45 | chunks: 'all' 46 | } 47 | } 48 | } 49 | }, 50 | plugins: [ 51 | // http://vuejs.github.io/vue-loader/en/workflow/production.html 52 | new webpack.DefinePlugin({ 53 | 'process.env': env 54 | }), 55 | // UglifyJs do not support ES6+, you can also use babel-minify for better treeshaking: https://github.com/babel/minify 56 | new UglifyJsPlugin({ 57 | parallel: true, 58 | cache: true, 59 | sourceMap: true, 60 | uglifyOptions: { 61 | compress: { 62 | warnings: true, 63 | /* eslint-disable */ 64 | drop_debugger: true, 65 | drop_console: true 66 | }, 67 | mangle: true 68 | } 69 | }), 70 | // extract css into its own file 71 | new ExtractTextPlugin({ 72 | filename: utils.assetsPath('css/[name].[hash].css') 73 | }), 74 | // Compress extracted CSS. We are using this plugin so that possible 75 | // duplicated CSS from different components can be deduped. 76 | new OptimizeCSSPlugin({ 77 | cssProcessorOptions: { 78 | safe: true 79 | } 80 | }), 81 | // generate dist index.html with correct asset hash for caching. 82 | // you can customize output by editing /index.html 83 | // see https://github.com/ampedandwired/html-webpack-plugin 84 | new HtmlWebpackPlugin({ 85 | filename: 86 | process.env.NODE_ENV === 'testing' ? 'index.html' : config.build.index, 87 | template: 'index.html', 88 | inject: true, 89 | minify: { 90 | removeComments: true, 91 | collapseWhitespace: true, 92 | removeAttributeQuotes: true 93 | // more options: 94 | // https://github.com/kangax/html-minifier#options-quick-reference 95 | }, 96 | // necessary to consistently work with multiple chunks via CommonsChunkPlugin 97 | chunksSortMode: 'dependency' 98 | }), 99 | // keep module.id stable when vender modules does not change 100 | new webpack.HashedModuleIdsPlugin(), 101 | // split vendor js into its own file 102 | // new webpack.optimize.CommonsChunkPlugin({ 103 | // name: 'vendor', 104 | // minChunks: function (module) { 105 | // // any required modules inside node_modules are extracted to vendor 106 | // return ( 107 | // module.resource && 108 | // /\.js$/.test(module.resource) && 109 | // module.resource.indexOf( 110 | // path.join(__dirname, '../node_modules') 111 | // ) === 0 112 | // ) 113 | // } 114 | // }), 115 | // // extract webpack runtime and module manifest to its own file in order to 116 | // // prevent vendor hash from being updated whenever app bundle is updated 117 | // new webpack.optimize.CommonsChunkPlugin({ 118 | // name: 'manifest', 119 | // chunks: ['vendor'] 120 | // }), 121 | // copy custom static assets 122 | new CopyWebpackPlugin([ 123 | { 124 | from: path.resolve(__dirname, '../static'), 125 | to: config.build.assetsSubDirectory, 126 | ignore: ['.*'] 127 | } 128 | ]) 129 | ] 130 | }) 131 | 132 | if (config.build.productionGzip) { 133 | const CompressionWebpackPlugin = require('compression-webpack-plugin') 134 | 135 | webpackConfig.plugins.push( 136 | new CompressionWebpackPlugin({ 137 | asset: '[path].gz[query]', 138 | algorithm: 'gzip', 139 | test: new RegExp( 140 | '\\.(' + config.build.productionGzipExtensions.join('|') + ')$' 141 | ), 142 | threshold: 10240, 143 | minRatio: 0.8 144 | }) 145 | ) 146 | } 147 | 148 | if (config.build.bundleAnalyzerReport) { 149 | const BundleAnalyzerPlugin = require('webpack-bundle-analyzer') 150 | .BundleAnalyzerPlugin 151 | webpackConfig.plugins.push(new BundleAnalyzerPlugin()) 152 | } 153 | 154 | module.exports = webpackConfig 155 | -------------------------------------------------------------------------------- /build/webpack.test.conf.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | // This is the webpack config used for unit tests. 3 | 4 | const utils = require('./utils') 5 | const webpack = require('webpack') 6 | const merge = require('webpack-merge') 7 | const baseWebpackConfig = require('./webpack.base.conf') 8 | 9 | const webpackConfig = merge(baseWebpackConfig, { 10 | // use inline sourcemap for karma-sourcemap-loader 11 | module: { 12 | rules: utils.styleLoaders() 13 | }, 14 | devtool: '#inline-source-map', 15 | resolveLoader: { 16 | alias: { 17 | // necessary to to make lang="scss" work in test when using vue-loader's ?inject option 18 | // see discussion at https://github.com/vuejs/vue-loader/issues/724 19 | 'scss-loader': 'sass-loader' 20 | } 21 | }, 22 | plugins: [ 23 | new webpack.DefinePlugin({ 24 | 'process.env': require('../config/test.env') 25 | }) 26 | ] 27 | }) 28 | 29 | // no need for app entry during tests 30 | delete webpackConfig.entry 31 | 32 | module.exports = webpackConfig 33 | -------------------------------------------------------------------------------- /config/dev.env.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | const merge = require('webpack-merge') 3 | const prodEnv = require('./prod.env') 4 | 5 | module.exports = merge(prodEnv, { 6 | NODE_ENV: '"development"' 7 | }) 8 | -------------------------------------------------------------------------------- /config/index.js: -------------------------------------------------------------------------------- 1 | 2 | 'use strict' 3 | // Template version: 1.1.3 4 | // see http://vuejs-templates.github.io/webpack for documentation. 5 | 6 | const path = require('path') 7 | 8 | module.exports = { 9 | build: { 10 | env: require('./prod.env'), 11 | index: path.resolve(__dirname, '../dist/index.html'), 12 | assetsRoot: path.resolve(__dirname, '../dist'), 13 | assetsSubDirectory: 'static', 14 | assetsPublicPath: '/', 15 | productionSourceMap: true, 16 | // Gzip off by default as many popular static hosts such as 17 | // Surge or Netlify already gzip all static assets for you. 18 | // Before setting to `true`, make sure to: 19 | // npm install --save-dev compression-webpack-plugin 20 | productionGzip: false, 21 | productionGzipExtensions: ['js', 'css'], 22 | // Run the build command with an extra argument to 23 | // View the bundle analyzer report after build finishes: 24 | // `npm run build --report` 25 | // Set to `true` or `false` to always turn it on or off 26 | bundleAnalyzerReport: process.env.npm_config_report 27 | }, 28 | dev: { 29 | env: require('./dev.env'), 30 | port: process.env.PORT || 8080, 31 | autoOpenBrowser: true, 32 | assetsSubDirectory: 'static', 33 | assetsPublicPath: '/', 34 | proxyTable: {}, 35 | // CSS Sourcemaps off by default because relative paths are "buggy" 36 | // with this option, according to the CSS-Loader README 37 | // (https://github.com/webpack/css-loader#sourcemaps) 38 | // In our experience, they generally work as expected, 39 | // just be aware of this issue when enabling this option. 40 | cssSourceMap: false 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /config/prod.env.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | module.exports = { 3 | NODE_ENV: '"production"' 4 | } 5 | -------------------------------------------------------------------------------- /config/test.env.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | const merge = require('webpack-merge') 3 | const devEnv = require('./dev.env') 4 | 5 | module.exports = merge(devEnv, { 6 | NODE_ENV: '"testing"' 7 | }) 8 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 |mixin 数据 :{{ testMixinArg }}
6 |store 数据 :{{ info.data }}
7 |