From: Eduardo San Martin Morote Date: Wed, 16 Oct 2019 10:11:35 +0000 (+0200) Subject: test(e2e): dev server by files X-Git-Tag: v4.0.0-alpha.0~189 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5e1fb2f239ab141c01995303279f66f873352b61;p=thirdparty%2Fvuejs%2Frouter.git test(e2e): dev server by files --- diff --git a/examples/encoding/index.html b/examples/encoding/index.html new file mode 100644 index 00000000..f8982d24 --- /dev/null +++ b/examples/encoding/index.html @@ -0,0 +1,80 @@ + + + + + + + Vue Router Examples - Encoding + + + + +
+
+ Name: +
{{ $route.name }}
+
+ +
+ Params: +
{{ $route.params }}
+
+ +
+ Query: +
{{ $route.query }}
+
+ +
+ Hash: +
{{ $route.hash }}
+
+ +
+ FullPath: +
{{ $route.fullPath }}
+
+ +
+ path: +
{{ $route.path }}
+
+ +
+ + + + +
+ + diff --git a/examples/encoding/index.ts b/examples/encoding/index.ts new file mode 100644 index 00000000..8cc50cf9 --- /dev/null +++ b/examples/encoding/index.ts @@ -0,0 +1,36 @@ +import { Router, plugin, createHistory } from '../../src' +import { RouteComponent } from '../../src/types' +import Vue from 'vue' + +const component: RouteComponent = { + template: `
A component
`, +} + +const Home: RouteComponent = { + template: `
Home
`, +} + +const Document: RouteComponent = { + template: `
Document: {{ $route.params.id }}
`, +} + +console.log('/' + __dirname) + +const router = new Router({ + history: createHistory('/' + __dirname), + routes: [ + { path: '/', component: Home, name: 'home' }, + { path: '/documents/:id', name: 'docs', component: Document }, + { path: encodeURI('/n/€'), name: 'euro', component }, + ], +}) + +// use the router +Vue.use(plugin) + +// @ts-ignore +window.vm = new Vue({ + el: '#app', + // @ts-ignore + router, +}) diff --git a/examples/tsconfig.json b/examples/tsconfig.json new file mode 100644 index 00000000..6cbbe090 --- /dev/null +++ b/examples/tsconfig.json @@ -0,0 +1,23 @@ +{ + "include": ["*/*ts"], + "compilerOptions": { + "target": "es5", + "module": "commonjs", + // "lib": ["es2017.object"] /* Specify library files to be included in the compilation. */, + "declaration": true, + // "declarationMap": true, + "sourceMap": true, + "outDir": "./dist", + "removeComments": false, + "noEmit": false, + + "strict": true, + + "noUnusedLocals": true, + // "noUnusedParameters": true, + "noImplicitReturns": true, + + "moduleResolution": "node", + "esModuleInterop": true + } +} diff --git a/examples/webpack.config.js b/examples/webpack.config.js new file mode 100644 index 00000000..9ac41218 --- /dev/null +++ b/examples/webpack.config.js @@ -0,0 +1,76 @@ +const fs = require('fs') +const { resolve, join } = require('path') +const HtmlWebpackPlugin = require('html-webpack-plugin') +const webpack = require('webpack') + +const outputPath = resolve(__dirname, '__build__') + +module.exports = { + // Expose __dirname to allow automatically setting basename. + context: __dirname, + node: { + __dirname: true, + }, + + mode: process.env.NODE_ENV || 'development', + + // devtool: 'inline-source-map', + devServer: { + // contentBase: outputPath, + historyApiFallback: { + rewrites: [{ from: /^\/encoding(?:\/?|\/.*)$/, to: '/encoding.html' }], + }, + // hot: true, + }, + + entry: { + encoding: resolve(__dirname, 'encoding/index.ts'), + }, + // entry: fs.readdirSync(__dirname).reduce((entries, dir) => { + // const fullDir = path.join(__dirname, dir) + // const entry = path.join(fullDir, 'index.ts') + // if (fs.statSync(fullDir).isDirectory() && fs.existsSync(entry)) { + // entries[dir] = ['es6-promise/auto', entry] + // } + + // return entries + // }, {}), + + output: { + path: join(__dirname, '__build__'), + filename: '[name].js', + chunkFilename: '[id].chunk.js', + publicPath: '/', + }, + + module: { + rules: [ + { + test: /\.ts$/, + use: 'ts-loader', + }, + ], + }, + resolve: { + alias: { + vue: resolve(__dirname, '../node_modules/vue/dist/vue.esm.js'), + 'vue-router': join(__dirname, '..', 'src'), + }, + // Add `.ts` and `.tsx` as a resolvable extension. + extensions: ['.ts', '.tsx', '.js'], + }, + plugins: [ + new HtmlWebpackPlugin({ + // inject: false, + // chunks: ['encoding'], + filename: 'encoding.html', + title: 'Vue Router Examples - encoding', + template: resolve(__dirname, 'encoding/index.html'), + }), + new webpack.DefinePlugin({ + 'process.env': { + NODE_ENV: JSON.stringify(process.env.NODE_ENV), + }, + }), + ], +}