Permalink
Browse files

refactored all

- fancy build chain
- vue2
- component files
  • Loading branch information...
rashfael committed Nov 22, 2016
1 parent 65b8ef6 commit 1be8e186c153a583bc6d3f8d11099054ec1e6ad4
View
@@ -0,0 +1,31 @@
module.exports = {
root: true,
parser: 'babel-eslint',
parserOptions: {
sourceType: 'module'
},
extends: 'standard',
// required to lint *.vue files
plugins: [
'html'
],
// add your custom rules here
rules: {
// allow paren-less arrow functions
'arrow-parens': 0,
// allow async-await
'generator-star-spacing': 0,
// allow debugger during development
'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0,
// OWN RULES
'indent': [2, 'tab'],
'no-tabs': 0,
'comma-dangle': 0, //perhaps always?
'curly': 0,
'no-return-assign': 0
},
globals: {
localStorage: false
}
}
View
@@ -0,0 +1,35 @@
// TODO REMOVE SHELLJS
require('shelljs/global')
var fs = require('fs-extra')
env.NODE_ENV = 'production'
var path = require('path')
var ora = require('ora')
var webpack = require('webpack')
var webpackConfig = require('./webpack.prod.conf')
var spinner = ora('building for production...')
spinner.start()
var assetsPath = path.resolve(__dirname, '../dist')
fs.removeSync(assetsPath)
fs.mkdirsSync(assetsPath)
// fs.copy('src/assets/images/favicon.ico', 'dist/static/img/favicon.ico')
webpack(webpackConfig, function (err, stats) {
spinner.stop()
// catches only fatal errors
if(err) {
process.stderr.write(err)
process.exit(1)
}
process.stdout.write(stats.toString({
colors: true,
modules: false,
children: false,
chunks: false,
chunkModules: false
}) + '\n')
if(stats.hasErrors())
process.exit(1)
})
View
@@ -0,0 +1,62 @@
var path = require('path')
var express = require('express')
var webpack = require('webpack')
var config = {
assetsPublicPath: '/',
assetsSubDirectory: 'static'
}
var proxyMiddleware = require('http-proxy-middleware')
var webpackConfig = require('./webpack.dev.conf')
var port = process.env.PORT || 8880
var app = express()
var compiler = webpack(webpackConfig)
var devMiddleware = require('webpack-dev-middleware')(compiler, {
publicPath: webpackConfig.output.publicPath,
stats: {
colors: true,
chunks: false
}
})
var hotMiddleware = require('webpack-hot-middleware')(compiler)
// force page reload when html-webpack-plugin template changes
compiler.plugin('compilation', function(compilation) {
compilation.plugin('html-webpack-plugin-after-emit', function(data, cb) {
hotMiddleware.publish({
action: 'reload'
})
cb()
})
})
// proxy api requests
// Object.keys(proxyTable).forEach(function (context) {
// var options = proxyTable[context]
// if (typeof options === 'string') {
// options = { target: options }
// }
// app.use(proxyMiddleware(context, options))
// })
// handle fallback for HTML5 history API
app.use(require('connect-history-api-fallback')())
// serve webpack bundle output
app.use(devMiddleware)
// enable hot-reload and state-preserving
// compilation error display
app.use(hotMiddleware)
var staticPath = path.posix.join(config.assetsPublicPath, config.assetsSubDirectory)
app.use(staticPath, express.static('./static'))
module.exports = app.listen(port, function(err) {
if (err) {
console.log(err)
return
}
console.log('Listening at http://localhost:' + port + '\n')
})
View
@@ -0,0 +1,8 @@
/* eslint-disable */
var hotClient = require('webpack-hot-middleware/client?noInfo=true&reload=true')
hotClient.subscribe(function (event) {
if (event.action === 'reload') {
window.location.reload()
}
})
View
@@ -0,0 +1,11 @@
var ghpages = require('gh-pages')
var path = require('path')
var distPath = path.resolve(__dirname, '../dist')
ghpages.publish(distPath, {
}, function (err) {
if (err)
console.error('ghpages failed', err)
else
console.log('ghpages successfully deployed')
})
View
@@ -0,0 +1,56 @@
var path = require('path')
var ExtractTextPlugin = require('extract-text-webpack-plugin')
exports.assetsPath = function (_path) {
return path.posix.join('static', _path)
}
exports.cssLoaders = function (options) {
options = options || {}
// generate loader string to be used with extract text plugin
function generateLoaders (loaders) {
var sourceLoader = loaders.map(function (loader) {
var extraParamChar
if (/\?/.test(loader)) {
loader = loader.replace(/\?/, '-loader?')
extraParamChar = '&'
} else {
loader = loader + '-loader'
extraParamChar = '?'
}
return loader + (options.sourceMap ? extraParamChar + 'sourceMap' : '')
}).join('!')
if (options.extract) {
// return ExtractTextPlugin.extract({loader: ['vue-style-loader', sourceLoader]})
return ExtractTextPlugin.extract({fallbackLoader: 'vue-style-loader', loader: sourceLoader})
} else {
return ['vue-style-loader', sourceLoader].join('!')
}
}
// http://vuejs.github.io/vue-loader/configurations/extract-css.html
return {
css: generateLoaders(['css']),
postcss: generateLoaders(['css']),
less: generateLoaders(['css', 'less']),
sass: generateLoaders(['css', 'sass?indentedSyntax']),
scss: generateLoaders(['css', 'sass']),
stylus: generateLoaders(['css', 'stylus']),
styl: generateLoaders(['css', 'stylus'])
}
}
// Generate loaders for standalone style files (outside of .vue)
exports.styleLoaders = function (options) {
var output = []
var loaders = exports.cssLoaders(options)
for (var extension in loaders) {
var loader = loaders[extension]
output.push({
test: new RegExp('\\.' + extension + '$'),
loader: loader
})
}
return output
}
View
@@ -0,0 +1,48 @@
var path = require('path')
var utils = require('./utils')
var projectRoot = path.resolve(__dirname, '../')
module.exports = {
entry: {
app: './src/main.js'
},
output: {
path: path.resolve(__dirname, '../dist'),
publicPath: '/',
filename: '[name].js'
},
resolve: {
extensions: ['', '.js', '.json', '.vue'],
modules: [path.resolve(__dirname, "../src"), path.resolve('src/styles'), path.join(__dirname, '../node_modules')]
},
module: {
loaders: [
{ test: /\.vue$/, loader: 'vue' },
{ test: /\.js$/, loader: 'babel', include: projectRoot, exclude: /node_modules\/(?!buntpapier)/ },
{ test: /\.json$/, loader: 'json' },
{ test: /\.html$/, loader: 'vue-html' },
{test: /\.svg(\?.*)?/, loader: 'svg-url',
query: {
noquotes: true,
limit: 10000,
name: utils.assetsPath('img/[name].[hash:7].[ext]')
}},
{ test: /\.(png|jpe?g|gif)(\?.*)?$/, loader: 'url',
query: {
limit: 10000,
name: utils.assetsPath('img/[name].[hash:7].[ext]')
}},
{ test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/, loader: 'url',
query: {
limit: 10000,
name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
}}
]
},
vue: {
loaders: utils.cssLoaders()
},
stylus: {
use: [require('nib')(), require('rupture')(), require('autoprefixer-stylus')(), require('buntpapier/stylus')()]
}
}
View
@@ -0,0 +1,37 @@
var webpack = require('webpack')
var merge = require('webpack-merge')
var path = require('path')
var projectRoot = path.resolve(__dirname, '../')
var utils = require('./utils')
var baseWebpackConfig = require('./webpack.base.conf')
var HtmlWebpackPlugin = require('html-webpack-plugin')
// add hot-reload related code to entry chunks
Object.keys(baseWebpackConfig.entry).forEach(function (name) {
baseWebpackConfig.entry[name] = ['./build/dev-shim'].concat(baseWebpackConfig.entry[name])
})
module.exports = merge(baseWebpackConfig, {
module: {
loaders: utils.styleLoaders()
},
resolve: {
alias: {
'config': path.resolve(projectRoot, 'config.js'),
}
},
// eval-source-map is faster for development
devtool: '#source-map',
plugins: [
new webpack.DefinePlugin({
'process.env': '"development"',
}),
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin(),
new HtmlWebpackPlugin({
filename: 'index.html',
template: 'index.html',
inject: true
})
]
})
View
@@ -0,0 +1,91 @@
var path = require('path')
var webpack = require('webpack')
var merge = require('webpack-merge')
var utils = require('./utils')
var path = require('path')
var projectRoot = path.resolve(__dirname, '../')
var baseWebpackConfig = require('./webpack.base.conf')
var ExtractTextPlugin = require('extract-text-webpack-plugin')
var HtmlWebpackPlugin = require('html-webpack-plugin')
var CompressionWebpackPlugin = require('compression-webpack-plugin')
var CleanWebpackPlugin = require('clean-webpack-plugin')
var webpackConfig = merge(baseWebpackConfig, {
resolve: {
alias: {
'config': path.resolve(projectRoot, 'config.js')
}
},
module: {
loaders: utils.styleLoaders({ sourceMap: true, extract: true })
},
output: {
filename: utils.assetsPath('js/[name].[chunkhash].js'),
chunkFilename: utils.assetsPath('js/[id].[chunkhash].js')
},
vue: {
loaders: utils.cssLoaders({
sourceMap: true,
extract: true
})
},
plugins: [
new webpack.DefinePlugin({
'process.env': '"production"',
}),
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
}
}),
// extract css into its own file
new ExtractTextPlugin(utils.assetsPath('css/[name].[contenthash].css')),
// generate dist index.html with correct asset hash for caching.
// you can customize output by editing /index.html
// see https://github.com/ampedandwired/html-webpack-plugin
new HtmlWebpackPlugin({
template: 'index.html',
inject: true,
minify: {
removeComments: true,
collapseWhitespace: true,
removeAttributeQuotes: true
// more options:
// https://github.com/kangax/html-minifier#options-quick-reference
},
// necessary to consistently work with multiple chunks via CommonsChunkPlugin
chunksSortMode: 'dependency'
}),
// split vendor js into its own file
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
minChunks: function (module, count) {
// any required modules inside node_modules are extracted to vendor
return (
module.resource &&
/\.js$/.test(module.resource) &&
module.resource.indexOf(
path.join(__dirname, '../node_modules')
) === 0
)
}
}),
// extract webpack runtime and module manifest to its own file in order to
// prevent vendor hash from being updated whenever app bundle is updated
new webpack.optimize.CommonsChunkPlugin({
name: 'manifest',
chunks: ['vendor']
}),
new CompressionWebpackPlugin({
asset: '[path].gz[query]',
algorithm: 'gzip',
test: new RegExp(
'\\.(js|css)$'
),
threshold: 10240,
minRatio: 0.8
})
]
})
module.exports = webpackConfig
Oops, something went wrong.

0 comments on commit 1be8e18

Please sign in to comment.