Skip to content

Commit a4ca7a4

Browse files
committed
remove build folder from .gitignore
1 parent dcd1125 commit a4ca7a4

File tree

11 files changed

+499
-1
lines changed

11 files changed

+499
-1
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ __pycache__/
99
# Distribution / packaging
1010
.Python
1111
env/
12-
build/
12+
# build/
1313
develop-eggs/
1414
dist/
1515
downloads/

my_project/frontend/build/build.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// https://github.com/shelljs/shelljs
2+
require('./check-versions')()
3+
4+
process.env.NODE_ENV = 'production'
5+
6+
var ora = require('ora')
7+
var path = require('path')
8+
var chalk = require('chalk')
9+
var shell = require('shelljs')
10+
var webpack = require('webpack')
11+
var config = require('../config')
12+
var webpackConfig = require('./webpack.prod.conf')
13+
14+
var spinner = ora('building for production...')
15+
spinner.start()
16+
17+
var assetsPath = path.join(config.build.assetsRoot, config.build.assetsSubDirectory)
18+
shell.rm('-rf', assetsPath)
19+
shell.mkdir('-p', assetsPath)
20+
shell.config.silent = true
21+
shell.cp('-R', 'static/*', assetsPath)
22+
shell.config.silent = false
23+
24+
webpack(webpackConfig, function (err, stats) {
25+
spinner.stop()
26+
if (err) throw err
27+
process.stdout.write(stats.toString({
28+
colors: true,
29+
modules: false,
30+
children: false,
31+
chunks: false,
32+
chunkModules: false
33+
}) + '\n\n')
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+
})
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
var chalk = require('chalk')
2+
var semver = require('semver')
3+
var packageConfig = require('../package.json')
4+
5+
function exec (cmd) {
6+
return require('child_process').execSync(cmd).toString().trim()
7+
}
8+
9+
var versionRequirements = [
10+
{
11+
name: 'node',
12+
currentVersion: semver.clean(process.version),
13+
versionRequirement: packageConfig.engines.node
14+
},
15+
{
16+
name: 'npm',
17+
currentVersion: exec('npm --version'),
18+
versionRequirement: packageConfig.engines.npm
19+
}
20+
]
21+
22+
module.exports = function () {
23+
var warnings = []
24+
for (var i = 0; i < versionRequirements.length; i++) {
25+
var mod = versionRequirements[i]
26+
if (!semver.satisfies(mod.currentVersion, mod.versionRequirement)) {
27+
warnings.push(mod.name + ': ' +
28+
chalk.red(mod.currentVersion) + ' should be ' +
29+
chalk.green(mod.versionRequirement)
30+
)
31+
}
32+
}
33+
34+
if (warnings.length) {
35+
console.log('')
36+
console.log(chalk.yellow('To use this template, you must update following to modules:'))
37+
console.log()
38+
for (var i = 0; i < warnings.length; i++) {
39+
var warning = warnings[i]
40+
console.log(' ' + warning)
41+
}
42+
console.log()
43+
process.exit(1)
44+
}
45+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/* eslint-disable */
2+
require('eventsource-polyfill')
3+
var hotClient = require('webpack-hot-middleware/client?noInfo=true&reload=true')
4+
5+
hotClient.subscribe(function (event) {
6+
if (event.action === 'reload') {
7+
window.location.reload()
8+
}
9+
})
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
require('./check-versions')()
2+
3+
var config = require('../config')
4+
if (!process.env.NODE_ENV) {
5+
process.env.NODE_ENV = JSON.parse(config.dev.env.NODE_ENV)
6+
}
7+
8+
var opn = require('opn')
9+
var path = require('path')
10+
var express = require('express')
11+
var webpack = require('webpack')
12+
var proxyMiddleware = require('http-proxy-middleware')
13+
var webpackConfig = process.env.NODE_ENV === 'testing'
14+
? require('./webpack.prod.conf')
15+
: require('./webpack.dev.conf')
16+
17+
// default port where dev server listens for incoming traffic
18+
var port = process.env.PORT || config.dev.port
19+
// automatically open browser, if not set will be false
20+
var autoOpenBrowser = !!config.dev.autoOpenBrowser
21+
// Define HTTP proxies to your custom API backend
22+
// https://github.com/chimurai/http-proxy-middleware
23+
var proxyTable = config.dev.proxyTable
24+
25+
var app = express()
26+
var compiler = webpack(webpackConfig)
27+
28+
var devMiddleware = require('webpack-dev-middleware')(compiler, {
29+
publicPath: webpackConfig.output.publicPath,
30+
quiet: true
31+
})
32+
33+
var hotMiddleware = require('webpack-hot-middleware')(compiler, {
34+
log: () => {}
35+
})
36+
// force page reload when html-webpack-plugin template changes
37+
compiler.plugin('compilation', function (compilation) {
38+
compilation.plugin('html-webpack-plugin-after-emit', function (data, cb) {
39+
hotMiddleware.publish({ action: 'reload' })
40+
cb()
41+
})
42+
})
43+
44+
// proxy api requests
45+
Object.keys(proxyTable).forEach(function (context) {
46+
var options = proxyTable[context]
47+
if (typeof options === 'string') {
48+
options = { target: options }
49+
}
50+
app.use(proxyMiddleware(options.filter || context, options))
51+
})
52+
53+
// handle fallback for HTML5 history API
54+
app.use(require('connect-history-api-fallback')())
55+
56+
// serve webpack bundle output
57+
app.use(devMiddleware)
58+
59+
// enable hot-reload and state-preserving
60+
// compilation error display
61+
app.use(hotMiddleware)
62+
63+
// serve pure static assets
64+
var staticPath = path.posix.join(config.dev.assetsPublicPath, config.dev.assetsSubDirectory)
65+
app.use(staticPath, express.static('./static'))
66+
67+
var uri = 'http://localhost:' + port
68+
69+
devMiddleware.waitUntilValid(function () {
70+
console.log('> Listening at ' + uri + '\n')
71+
})
72+
73+
module.exports = app.listen(port, function (err) {
74+
if (err) {
75+
console.log(err)
76+
return
77+
}
78+
79+
// when env is testing, don't need open it
80+
if (autoOpenBrowser && process.env.NODE_ENV !== 'testing') {
81+
opn(uri)
82+
}
83+
})

my_project/frontend/build/utils.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
var path = require('path')
2+
var config = require('../config')
3+
var ExtractTextPlugin = require('extract-text-webpack-plugin')
4+
5+
exports.assetsPath = function (_path) {
6+
var assetsSubDirectory = process.env.NODE_ENV === 'production'
7+
? config.build.assetsSubDirectory
8+
: config.dev.assetsSubDirectory
9+
return path.posix.join(assetsSubDirectory, _path)
10+
}
11+
12+
exports.cssLoaders = function (options) {
13+
options = options || {}
14+
// generate loader string to be used with extract text plugin
15+
function generateLoaders (loaders) {
16+
var sourceLoader = loaders.map(function (loader) {
17+
var extraParamChar
18+
if (/\?/.test(loader)) {
19+
loader = loader.replace(/\?/, '-loader?')
20+
extraParamChar = '&'
21+
} else {
22+
loader = loader + '-loader'
23+
extraParamChar = '?'
24+
}
25+
return loader + (options.sourceMap ? extraParamChar + 'sourceMap' : '')
26+
}).join('!')
27+
28+
// Extract CSS when that option is specified
29+
// (which is the case during production build)
30+
if (options.extract) {
31+
return ExtractTextPlugin.extract({
32+
loader: sourceLoader,
33+
fallbackLoader: 'vue-style-loader'
34+
})
35+
} else {
36+
return ['vue-style-loader', sourceLoader].join('!')
37+
}
38+
}
39+
40+
// http://vuejs.github.io/vue-loader/en/configurations/extract-css.html
41+
return {
42+
css: generateLoaders(['css']),
43+
postcss: generateLoaders(['css']),
44+
less: generateLoaders(['css', 'less']),
45+
sass: generateLoaders(['css', 'sass?indentedSyntax']),
46+
scss: generateLoaders(['css', 'sass']),
47+
stylus: generateLoaders(['css', 'stylus']),
48+
styl: generateLoaders(['css', 'stylus'])
49+
}
50+
}
51+
52+
// Generate loaders for standalone style files (outside of .vue)
53+
exports.styleLoaders = function (options) {
54+
var output = []
55+
var loaders = exports.cssLoaders(options)
56+
for (var extension in loaders) {
57+
var loader = loaders[extension]
58+
output.push({
59+
test: new RegExp('\\.' + extension + '$'),
60+
loader: loader
61+
})
62+
}
63+
return output
64+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
var utils = require('./utils')
2+
var config = require('../config')
3+
var isProduction = process.env.NODE_ENV === 'production'
4+
5+
module.exports = {
6+
loaders: utils.cssLoaders({
7+
sourceMap: isProduction
8+
? config.build.productionSourceMap
9+
: config.dev.cssSourceMap,
10+
extract: isProduction
11+
}),
12+
postcss: [
13+
require('autoprefixer')({
14+
browsers: ['last 2 versions']
15+
})
16+
]
17+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
var path = require('path')
2+
var utils = require('./utils')
3+
var config = require('../config')
4+
var vueLoaderConfig = require('./vue-loader.conf')
5+
var eslintFriendlyFormatter = require('eslint-friendly-formatter')
6+
7+
function resolve (dir) {
8+
return path.join(__dirname, '..', dir)
9+
}
10+
11+
module.exports = {
12+
entry: {
13+
app: './src/main.js'
14+
},
15+
output: {
16+
path: config.build.assetsRoot,
17+
filename: '[name].js',
18+
publicPath: process.env.NODE_ENV === 'production'
19+
? config.build.assetsPublicPath
20+
: config.dev.assetsPublicPath
21+
},
22+
resolve: {
23+
extensions: ['.js', '.vue', '.json'],
24+
modules: [
25+
resolve('src'),
26+
resolve('node_modules')
27+
],
28+
alias: {
29+
'vue$': 'vue/dist/vue.common.js',
30+
'src': resolve('src'),
31+
'assets': resolve('src/assets'),
32+
'components': resolve('src/components')
33+
}
34+
},
35+
module: {
36+
rules: [
37+
{
38+
test: /\.(js|vue)$/,
39+
loader: 'eslint-loader',
40+
enforce: "pre",
41+
include: [resolve('src'), resolve('test')],
42+
options: {
43+
formatter: eslintFriendlyFormatter
44+
}
45+
},
46+
{
47+
test: /\.vue$/,
48+
loader: 'vue-loader',
49+
options: vueLoaderConfig
50+
},
51+
{
52+
test: /\.js$/,
53+
loader: 'babel-loader',
54+
include: [resolve('src'), resolve('test')]
55+
},
56+
{
57+
test: /\.json$/,
58+
loader: 'json-loader'
59+
},
60+
{
61+
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
62+
loader: 'url-loader',
63+
query: {
64+
limit: 10000,
65+
name: utils.assetsPath('img/[name].[hash:7].[ext]')
66+
}
67+
},
68+
{
69+
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
70+
loader: 'url-loader',
71+
query: {
72+
limit: 10000,
73+
name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
74+
}
75+
}
76+
]
77+
}
78+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
var utils = require('./utils')
2+
var webpack = require('webpack')
3+
var config = require('../config')
4+
var merge = require('webpack-merge')
5+
var baseWebpackConfig = require('./webpack.base.conf')
6+
var HtmlWebpackPlugin = require('html-webpack-plugin')
7+
var FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin')
8+
9+
// add hot-reload related code to entry chunks
10+
Object.keys(baseWebpackConfig.entry).forEach(function (name) {
11+
baseWebpackConfig.entry[name] = ['./build/dev-client'].concat(baseWebpackConfig.entry[name])
12+
})
13+
14+
module.exports = merge(baseWebpackConfig, {
15+
module: {
16+
rules: utils.styleLoaders({ sourceMap: config.dev.cssSourceMap })
17+
},
18+
// cheap-module-eval-source-map is faster for development
19+
devtool: '#cheap-module-eval-source-map',
20+
plugins: [
21+
new webpack.DefinePlugin({
22+
'process.env': config.dev.env
23+
}),
24+
// https://github.com/glenjamin/webpack-hot-middleware#installation--usage
25+
new webpack.HotModuleReplacementPlugin(),
26+
new webpack.NoEmitOnErrorsPlugin(),
27+
// https://github.com/ampedandwired/html-webpack-plugin
28+
new HtmlWebpackPlugin({
29+
filename: 'index.html',
30+
template: 'index.html',
31+
inject: true
32+
}),
33+
new FriendlyErrorsPlugin()
34+
]
35+
})

0 commit comments

Comments
 (0)