Skip to content

Commit 768fda6

Browse files
committed
test: test compatibility with Vue CLI 2
1 parent 9c620e2 commit 768fda6

26 files changed

+14878
-0
lines changed

demo/vue-cli2/.babelrc__

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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": ["transform-vue-jsx", "transform-runtime"]
12+
}

demo/vue-cli2/.editorconfig

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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

demo/vue-cli2/.gitignore

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.DS_Store
2+
node_modules/
3+
/dist/
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
8+
# Editor directories and files
9+
.idea
10+
.vscode
11+
*.suo
12+
*.ntvs*
13+
*.njsproj
14+
*.sln

demo/vue-cli2/.node-version

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
14

demo/vue-cli2/.postcssrc.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// https://github.com/michael-ciniawsky/postcss-load-config
2+
3+
module.exports = {
4+
"plugins": {
5+
"postcss-import": {},
6+
"postcss-url": {},
7+
// to edit target browsers: use "browserslist" field in package.json
8+
"autoprefixer": {}
9+
}
10+
}

demo/vue-cli2/README.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# vue-cli2
2+
3+
> A Vue.js project
4+
5+
## Build Setup
6+
7+
``` bash
8+
# install dependencies
9+
npm install
10+
11+
# serve with hot reload at localhost:8080
12+
npm run dev
13+
14+
# build for production with minification
15+
npm run build
16+
17+
# build for production and view the bundle analyzer report
18+
npm run build --report
19+
```
20+
21+
For a detailed explanation on how things work, check out the [guide](http://vuejs-templates.github.io/webpack/) and [docs for vue-loader](http://vuejs.github.io/vue-loader).

demo/vue-cli2/babel.config.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
presets: [
3+
'@babel/preset-env',
4+
],
5+
}

demo/vue-cli2/build/build.js

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
'use strict'
2+
require('./check-versions')()
3+
4+
process.env.NODE_ENV = 'production'
5+
6+
const path = require('path')
7+
const ora = require('ora')
8+
const rm = require('rimraf')
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)
19+
throw err
20+
webpack(webpackConfig, (err, stats) => {
21+
spinner.stop()
22+
if (err)
23+
throw err
24+
process.stdout.write(`${stats.toString({
25+
colors: true,
26+
modules: false,
27+
children: false, // If you are using ts-loader, setting this to true will make TypeScript errors show up during build.
28+
chunks: false,
29+
chunkModules: false,
30+
})}\n\n`)
31+
32+
if (stats.hasErrors()) {
33+
console.log(chalk.red(' Build failed with errors.\n'))
34+
process.exit(1)
35+
}
36+
37+
console.log(chalk.cyan(' Build complete.\n'))
38+
console.log(chalk.yellow(
39+
' Tip: built files are meant to be served over an HTTP server.\n'
40+
+ ' Opening index.html over file:// won\'t work.\n',
41+
))
42+
})
43+
})

demo/vue-cli2/build/check-versions.js

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
'use strict'
2+
const chalk = require('chalk')
3+
const semver = require('semver')
4+
const shell = require('shelljs')
5+
const packageConfig = require('../package.json')
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+
}

demo/vue-cli2/build/logo.png

6.69 KB
Loading

demo/vue-cli2/build/utils.js

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
'use strict'
2+
const path = require('path')
3+
const ExtractTextPlugin = require('extract-text-webpack-plugin')
4+
const config = require('../config')
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+
})
52+
} else {
53+
return ['vue-style-loader'].concat(loaders)
54+
}
55+
}
56+
57+
// https://vue-loader.vuejs.org/en/configurations/extract-css.html
58+
return {
59+
css: generateLoaders(),
60+
postcss: generateLoaders(),
61+
less: generateLoaders('less'),
62+
sass: generateLoaders('sass', { indentedSyntax: true }),
63+
scss: generateLoaders('sass'),
64+
stylus: generateLoaders('stylus'),
65+
styl: generateLoaders('stylus'),
66+
}
67+
}
68+
69+
// Generate loaders for standalone style files (outside of .vue)
70+
exports.styleLoaders = function (options) {
71+
const output = []
72+
const loaders = exports.cssLoaders(options)
73+
74+
for (const extension in loaders) {
75+
const loader = loaders[extension]
76+
output.push({
77+
test: new RegExp(`\\.${extension}$`),
78+
use: loader,
79+
})
80+
}
81+
82+
return output
83+
}
84+
85+
exports.createNotifierCallback = () => {
86+
const notifier = require('node-notifier')
87+
88+
return (severity, errors) => {
89+
if (severity !== 'error')
90+
return
91+
92+
const error = errors[0]
93+
const filename = error.file && error.file.split('!').pop()
94+
95+
notifier.notify({
96+
title: packageConfig.name,
97+
message: `${severity}: ${error.name}`,
98+
subtitle: filename || '',
99+
icon: path.join(__dirname, 'logo.png'),
100+
})
101+
}
102+
}
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'use strict'
2+
const config = require('../config')
3+
const utils = require('./utils')
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+
}
+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
'use strict'
2+
const path = require('path')
3+
const config = require('../config')
4+
const utils = require('./utils')
5+
const vueLoaderConfig = require('./vue-loader.conf')
6+
7+
function resolve(dir) {
8+
return path.join(__dirname, '..', dir)
9+
}
10+
11+
module.exports = {
12+
context: path.resolve(__dirname, '../'),
13+
entry: {
14+
app: './src/main.js',
15+
},
16+
output: {
17+
path: config.build.assetsRoot,
18+
filename: '[name].js',
19+
publicPath: process.env.NODE_ENV === 'production'
20+
? config.build.assetsPublicPath
21+
: config.dev.assetsPublicPath,
22+
},
23+
resolve: {
24+
extensions: ['.js', '.vue', '.json'],
25+
alias: {
26+
'vue$': 'vue/dist/vue.esm.js',
27+
'@': resolve('src'),
28+
},
29+
},
30+
module: {
31+
rules: [
32+
{
33+
test: /\.vue$/,
34+
loader: 'vue-loader',
35+
options: vueLoaderConfig,
36+
},
37+
{
38+
test: /\.js$/,
39+
loader: 'babel-loader',
40+
include: [resolve('src'), resolve('test'), resolve('node_modules/webpack-dev-server/client')],
41+
},
42+
{
43+
test: /\.mjs$/,
44+
loader: 'babel-loader',
45+
include: [resolve('src'), resolve('test'), resolve('node_modules/json-editor-vue')],
46+
},
47+
{
48+
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
49+
loader: 'url-loader',
50+
options: {
51+
limit: 10000,
52+
name: utils.assetsPath('img/[name].[hash:7].[ext]'),
53+
},
54+
},
55+
{
56+
test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
57+
loader: 'url-loader',
58+
options: {
59+
limit: 10000,
60+
name: utils.assetsPath('media/[name].[hash:7].[ext]'),
61+
},
62+
},
63+
{
64+
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
65+
loader: 'url-loader',
66+
options: {
67+
limit: 10000,
68+
name: utils.assetsPath('fonts/[name].[hash:7].[ext]'),
69+
},
70+
},
71+
],
72+
},
73+
node: {
74+
// prevent webpack from injecting useless setImmediate polyfill because Vue
75+
// source contains it (although only uses it if it's native).
76+
setImmediate: false,
77+
// prevent webpack from injecting mocks to Node native modules
78+
// that does not make sense for the client
79+
dgram: 'empty',
80+
fs: 'empty',
81+
net: 'empty',
82+
tls: 'empty',
83+
child_process: 'empty',
84+
},
85+
}

0 commit comments

Comments
 (0)