Skip to content

Commit 1c90459

Browse files
authored
Merge pull request boylegu#40 from boylegu/issue/39/build_dev
Issue/39/build dev
2 parents 1ac0d44 + 200eac3 commit 1c90459

File tree

9 files changed

+1801
-30
lines changed

9 files changed

+1801
-30
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ target/springboot_vue-0.0.1-SNAPSHOT.jar.original
2424

2525
### NetBeans ###
2626
nbproject/private/
27-
build/
2827
nbbuild/
2928
dist/
3029
nbdist/

frontend/build/config.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* Created by gubaoer on 17/5/10.
3+
*/
4+
5+
6+
var path = require('path');
7+
module.exports = {
8+
dev: {
9+
outputPath: path.resolve(__dirname, '../dist'),
10+
outputPublicPath: '/',
11+
port: 8080
12+
},
13+
prod: {
14+
outputPath: path.resolve(__dirname, '../dist'),
15+
outputPublicPath: '/'
16+
}
17+
}

frontend/build/dev.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* Created by gubaoer on 17/5/11.
3+
*/
4+
5+
var webpack = require('webpack');
6+
var webpackDevServer = require('webpack-dev-server');
7+
var devConfig = require("./webpack.dev.config");
8+
var config = require("./config");
9+
var compiler = webpack(devConfig);
10+
var server = new webpackDevServer(compiler, {
11+
hot: true,
12+
noInfo: true,
13+
publicPath: config.dev.outputPublicPath,
14+
stats: { colors: true }
15+
});
16+
server.listen(config.dev.port, "0.0.0.0");
17+
var url = `http://localhost:${config.dev.port}/`;
18+
var opn = require('opn');
19+
// auto start brower
20+
server.middleware.waitUntilValid(function() {
21+
console.log(`> Listening at ${url}`);
22+
opn(`${url}`);
23+
})

frontend/build/prod.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* Created by gubaoer on 17/5/11.
3+
*/
4+
5+
var webpack = require("webpack");
6+
var prodWebpackConfig = require('./webpack.prod.config');
7+
webpack(prodWebpackConfig, function (err, stats) {
8+
process.stdout.write(stats.toString());
9+
});

frontend/build/utils.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* Created by gubaoer on 17/5/10.
3+
*/
4+
5+
var ExtractTextPlugin = require('extract-text-webpack-plugin');
6+
var isProd = process.env.NODE_ENV === "production";
7+
8+
var cssLang = [{
9+
name: 'css',
10+
reg: /\.css$/,
11+
loader: 'css-loader'
12+
}];
13+
14+
function genLoaders(lang) {
15+
var loaders = ['css-loader', 'postcss-loader'];
16+
if (lang.name !== 'css') {
17+
loaders.push(lang.loader);
18+
}
19+
if (isProd) {
20+
21+
loaders = ExtractTextPlugin.extract({
22+
use: loaders
23+
});
24+
} else {
25+
26+
loaders.unshift('vue-style-loader');
27+
}
28+
return loaders;
29+
}
30+
31+
exports.styleLoaders = function() {
32+
var output = [];
33+
cssLang.forEach(lang => {
34+
output.push({
35+
test: lang.reg,
36+
use: genLoaders(lang)
37+
})
38+
});
39+
return output;
40+
};
41+
// options of vue-loader
42+
exports.vueLoaderOptions = function() {
43+
var options = {
44+
loaders: {}
45+
};
46+
cssLang.forEach(lang => {
47+
options.loaders[lang.name] = genLoaders(lang);
48+
});
49+
return options;
50+
};
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/**
2+
* Created by gubaoer on 17/5/10.
3+
*/
4+
var webpack = require('webpack');
5+
var path = require('path');
6+
var utils = require('./utils');
7+
8+
function resolve(relPath) {
9+
return path.resolve(__dirname, relPath);
10+
}
11+
12+
module.exports = {
13+
entry: {app: resolve('../src/main.js')},
14+
output: {
15+
filename: 'js/[name].js'
16+
},
17+
module: {
18+
rules: [{
19+
test: /\.js$/,
20+
use: "babel-loader",
21+
include: [resolve('../src')]
22+
},
23+
{
24+
test: /\.vue$/,
25+
use: {
26+
loader: "vue-loader",
27+
options: utils.vueLoaderOptions()
28+
}
29+
},
30+
{
31+
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
32+
use: {
33+
loader: "url-loader",
34+
options: {
35+
limit: 10000,
36+
name: 'images/[name].[hash:7].[ext]'
37+
}
38+
}
39+
},
40+
{
41+
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
42+
use: [{
43+
loader: "url-loader",
44+
options: {
45+
limit: 10000,
46+
name: 'fonts/[name].[hash:7].[ext]'
47+
}
48+
}]
49+
}
50+
]
51+
}
52+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* Created by gubaoer on 17/5/10.
3+
*/
4+
5+
var webpack = require('webpack');
6+
var merge = require('webpack-merge');
7+
var HtmlWebpackPlugin = require('html-webpack-plugin');
8+
var baseWebpackConfig = require('./webpack.base.config.js');
9+
var utils = require('./utils');
10+
var config = require('./config');
11+
12+
Object.keys(baseWebpackConfig.entry).forEach(function (name) {
13+
baseWebpackConfig.entry[name] = [
14+
`webpack-dev-server/client?http://localhost:${config.dev.port}/`,
15+
"webpack/hot/dev-server"
16+
].concat(baseWebpackConfig.entry[name])
17+
});
18+
19+
module.exports = merge(baseWebpackConfig, {
20+
output: {
21+
path: config.dev.outputPath,
22+
publicPath: config.dev.outputPublicPath
23+
},
24+
module: {
25+
rules: utils.styleLoaders()
26+
},
27+
plugins: [
28+
new webpack.HotModuleReplacementPlugin(),
29+
new HtmlWebpackPlugin({
30+
filename: 'index.html',
31+
template: 'index.html',
32+
inject: true
33+
})
34+
]
35+
})
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* Created by gubaoer on 17/5/10.
3+
*/
4+
5+
process.env.NODE_ENV = 'production';
6+
var webpack = require('webpack');
7+
var merge = require('webpack-merge');
8+
var HtmlWebpackPlugin = require('html-webpack-plugin');
9+
var ExtractTextPlugin = require('extract-text-webpack-plugin');
10+
var path = require('path');
11+
var baseWebpackConfig = require('./webpack.base.config.js');
12+
var utils = require('./utils');
13+
var config = require('./config');
14+
15+
module.exports = merge(baseWebpackConfig, {
16+
output: {
17+
path: config.prod.outputPath,
18+
publicPath: config.prod.outputPublicPath,
19+
filename: 'js/[name].js?[chunkhash]'
20+
},
21+
module: {
22+
rules: utils.styleLoaders()
23+
},
24+
plugins: [
25+
new webpack.DefinePlugin({
26+
'process.env.NODE_ENV': '"production"'
27+
}),
28+
new webpack.optimize.UglifyJsPlugin(),
29+
new ExtractTextPlugin({
30+
filename: "css/style.css?[contenthash:8]"
31+
}),
32+
new webpack.optimize.CommonsChunkPlugin({
33+
name: 'vendor',
34+
minChunks: function (module, count) {
35+
return module.resource && /\.js$/.test(module.resource) && module.resource.indexOf(path.join(__dirname, '../node_modules')) === 0
36+
}
37+
}),
38+
new webpack.optimize.CommonsChunkPlugin({
39+
name: 'manifest',
40+
chunks: ['vendor']
41+
}),
42+
new HtmlWebpackPlugin({
43+
filename: 'index.html',
44+
template: 'index.tpl.html',
45+
inject: true
46+
})
47+
]
48+
})

0 commit comments

Comments
 (0)