Skip to content

Commit 9263298

Browse files
committed
Initital commit
0 parents  commit 9263298

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+14860
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
dist/
2+
.idea/
3+
node_modules

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# VueJS Typescript Demo
2+
3+
> Example of how to build a VueJs app with typescript, webpack, Single File Components and Materialize CSS
4+
5+
6+
7+
8+

build/build.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
})

build/check-versions.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
}

build/logo.png

6.69 KB
Loading

build/utils.js

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
'use strict'
2+
const path = require('path')
3+
const config = require('../config')
4+
const ExtractTextPlugin = require('extract-text-webpack-plugin')
5+
const pkg = 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+
return path.posix.join(assetsSubDirectory, _path)
12+
}
13+
14+
exports.cssLoaders = function (options) {
15+
options = options || {}
16+
17+
const cssLoader = {
18+
loader: 'css-loader',
19+
options: {
20+
sourceMap: options.sourceMap
21+
}
22+
}
23+
24+
var postcssLoader = {
25+
loader: 'postcss-loader',
26+
options: {
27+
sourceMap: options.sourceMap
28+
}
29+
}
30+
31+
// generate loader string to be used with extract text plugin
32+
function generateLoaders (loader, loaderOptions) {
33+
const loaders = options.usePostCSS ? [cssLoader, postcssLoader] : [cssLoader]
34+
if (loader) {
35+
loaders.push({
36+
loader: loader + '-loader',
37+
options: Object.assign({}, loaderOptions, {
38+
sourceMap: options.sourceMap
39+
})
40+
})
41+
}
42+
43+
// Extract CSS when that option is specified
44+
// (which is the case during production build)
45+
if (options.extract) {
46+
return ExtractTextPlugin.extract({
47+
use: loaders,
48+
fallback: 'vue-style-loader'
49+
})
50+
} else {
51+
return ['vue-style-loader'].concat(loaders)
52+
}
53+
}
54+
55+
// https://vue-loader.vuejs.org/en/configurations/extract-css.html
56+
return {
57+
css: generateLoaders(),
58+
postcss: generateLoaders(),
59+
less: generateLoaders('less'),
60+
sass: generateLoaders('sass', { indentedSyntax: true }),
61+
scss: generateLoaders('sass'),
62+
stylus: generateLoaders('stylus'),
63+
styl: generateLoaders('stylus')
64+
}
65+
}
66+
67+
// Generate loaders for standalone style files (outside of .vue)
68+
exports.styleLoaders = function (options) {
69+
const output = []
70+
const loaders = exports.cssLoaders(options)
71+
for (const extension in loaders) {
72+
const loader = loaders[extension]
73+
output.push({
74+
test: new RegExp('\\.' + extension + '$'),
75+
use: loader
76+
})
77+
}
78+
return output
79+
}
80+
81+
exports.createNotifierCallback = function () {
82+
const notifier = require('node-notifier')
83+
84+
return (severity, errors) => {
85+
if (severity !== 'error') {
86+
return
87+
}
88+
const error = errors[0]
89+
90+
const filename = error.file.split('!').pop()
91+
notifier.notify({
92+
title: pkg.name,
93+
message: severity + ': ' + error.name,
94+
subtitle: filename || '',
95+
icon: path.join(__dirname, 'logo.png')
96+
})
97+
}
98+
}

build/vue-loader.conf.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
10+
module.exports = {
11+
loaders: utils.cssLoaders({
12+
sourceMap: sourceMapEnabled,
13+
extract: isProduction
14+
}),
15+
cssSourceMap: sourceMapEnabled,
16+
transformToRequire: {
17+
video: 'src',
18+
source: 'src',
19+
img: 'src',
20+
image: 'xlink:href'
21+
}
22+
}

build/webpack.base.conf.js

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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 ExtractTextPlugin = require('extract-text-webpack-plugin');
7+
// const CleanWebpackPlugin = require('clean-webpack-plugin');
8+
const CopyWebpackPlugin = require('copy-webpack-plugin');
9+
function resolve (dir) {
10+
return path.join(__dirname, '..', dir)
11+
}
12+
13+
const publicPath=process.env.NODE_ENV === 'production'
14+
? config.build.assetsPublicPath
15+
: config.dev.assetsPublicPath;
16+
17+
module.exports = {
18+
context: path.resolve(__dirname, '../'),
19+
entry: {
20+
app: './src/index.ts'
21+
},
22+
output: {
23+
path: config.build.assetsRoot,
24+
filename: '[name].js',
25+
publicPath
26+
},
27+
resolve: {
28+
extensions: ['.js','ts'],//, '.json', '.html','.scss'
29+
alias: {
30+
'vue$': 'vue/dist/vue.esm.js',
31+
'@': resolve('src'),
32+
}
33+
},
34+
module: {
35+
rules: [
36+
{
37+
test: /\.ts$/,
38+
loader: 'ts-loader',
39+
exclude: /node_modules/,
40+
options: {
41+
appendTsSuffixTo: [/\.vue$/],
42+
}
43+
},
44+
{
45+
test: /\.vue$/,
46+
loader: 'vue-loader',
47+
options: {
48+
49+
esModule: true,
50+
}
51+
},
52+
53+
{
54+
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
55+
loader: 'url-loader',
56+
options: {
57+
limit: 10000,
58+
name: utils.assetsPath('img/[name].[hash:7].[ext]')
59+
}
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+
plugins: [
80+
new ExtractTextPlugin({
81+
filename: path.join(publicPath,'styles.css'),
82+
allChunks: true
83+
}),
84+
],
85+
86+
}

build/webpack.dev.conf.js

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

0 commit comments

Comments
 (0)