Skip to content

Commit 31ec207

Browse files
committed
start integration with webpack 2
1 parent acc97d6 commit 31ec207

File tree

9 files changed

+1310
-1107
lines changed

9 files changed

+1310
-1107
lines changed

build/server/index.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,14 @@ const app = express();
1313
const compiler = webpack(webpackConfig);
1414
const rootPath = path.join(__dirname, '..', '..');
1515
const devMiddlewareInstance = devMiddleware(compiler, {
16+
quiet: true,
1617
publicPath: config.publicPath,
17-
index: config.indexPath,
18-
stats: {
19-
colors: true,
20-
chunks: false
21-
}
18+
index: config.indexPath
2219
});
2320

24-
const hotMiddlewareInstance = hotMiddleware(compiler);
21+
const hotMiddlewareInstance = hotMiddleware(compiler, {
22+
log() { }
23+
});
2524

2625
compiler.plugin('compilation', (compilation) => {
2726
compilation.plugin('html-webpack-plugin-after-emit', (data, done) => {
@@ -36,14 +35,16 @@ app.use(hotMiddlewareInstance);
3635
app.use('/', express.static(path.join(rootPath, config.docsPath)));
3736
app.use('/assets', express.static(path.join(rootPath, config.assetsPath)));
3837

39-
export default app.listen(config.server.port, (error) => {
38+
devMiddlewareInstance.waitUntilValid(() => {
4039
let uri = 'http://localhost:' + config.server.port;
4140

41+
console.log(chalk.blue('> Listening at ' + uri + '\n'));
42+
});
43+
44+
export default app.listen(config.server.port, (error) => {
4245
if (error) {
4346
console.log(chalk.red(error));
4447

4548
return;
4649
}
47-
48-
console.log(chalk.blue('Listening at ' + uri + '\n'));
4950
});

build/webpack/base.js

Lines changed: 37 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import webpack from 'webpack';
33
import eslintFormatter from 'eslint-friendly-formatter';
44
import config from '../config';
55

6+
const resolvePath = (dir) => {
7+
return path.resolve(__dirname, '..', '..', dir);
8+
};
9+
610
export default {
711
entry: {
812
docs: './docs/src/index.js'
@@ -13,81 +17,68 @@ export default {
1317
filename: '[name].js'
1418
},
1519
resolve: {
16-
extensions: ['', '.js', '.vue'],
17-
fallback: [config.nodePath],
20+
extensions: ['.js', '.vue', '.json'],
1821
alias: {
19-
assets: path.resolve(__dirname, '../../docs/src/assets')
22+
assets: resolvePath('docs/src/assets')
2023
}
2124
},
22-
resolveLoader: {
23-
fallback: [config.nodePath]
24-
},
2525
module: {
26-
preLoaders: [
26+
rules: [
2727
{
28-
test: /\.vue$/,
29-
loader: 'eslint',
30-
include: config.projectRoot,
31-
exclude: /node_modules/
28+
test: /\.(js|vue)$/,
29+
loader: 'eslint-loader',
30+
enforce: 'pre',
31+
include: [
32+
resolvePath('build'),
33+
resolvePath('src'),
34+
resolvePath('docs')
35+
],
36+
options: {
37+
fix: true,
38+
formatter: eslintFormatter
39+
}
3240
},
33-
{
34-
test: /\.js$/,
35-
loader: 'eslint',
36-
include: config.projectRoot,
37-
exclude: /node_modules/
38-
}
39-
],
40-
loaders: [
4141
{
4242
test: /\.vue$/,
43-
loader: 'vue'
43+
loader: 'vue-loader',
44+
options: {
45+
loaders: {
46+
css: 'vue-style-loader!css-loader',
47+
scss: 'vue-style-loader!css-loader!sass-loader'
48+
}
49+
}
4450
},
4551
{
4652
test: /\.js$/,
47-
loader: 'babel',
48-
include: config.projectRoot,
49-
exclude: /node_modules/
53+
loader: 'babel-loader',
54+
include: [
55+
resolvePath('build'),
56+
resolvePath('src'),
57+
resolvePath('docs')
58+
]
5059
},
5160
{
5261
test: /\.css$/,
53-
loader: 'vue-style-loader!css-loader'
62+
use: ['vue-style-loader', 'css-loader']
5463
},
5564
{
5665
test: /\.scss$/,
57-
loader: 'vue-style-loader!css-loader!sass-loader'
66+
use: ['vue-style-loader', 'css-loader', 'sass-loader']
5867
},
5968
{
6069
test: /\.theme$/,
61-
loaders: ['raw', 'sass-loader']
62-
},
63-
{
64-
test: /\.json$/,
65-
loaders: ['json-loader']
70+
use: ['raw-loader', 'sass-loader']
6671
},
6772
{
68-
test: /\.(png|jpg|gif|svg)(\?.*)?$/,
69-
loader: 'url',
73+
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
74+
loader: 'url-loader',
7075
query: {
7176
limit: 10000,
7277
name: '/assets/[name].[hash:8].[ext]'
7378
}
74-
},
75-
{
76-
test: /\.html$/,
77-
loader: 'vue-html'
7879
}
7980
]
8081
},
81-
eslint: {
82-
fix: true,
83-
formatter: eslintFormatter
84-
},
85-
vue: {
86-
loaders: {
87-
css: 'vue-style-loader!css-loader',
88-
scss: 'vue-style-loader!css-loader!sass-loader'
89-
}
90-
},
9182
plugins: [
9283
new webpack.DefinePlugin({
9384
'process.env': config.env

build/webpack/debug-lib.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import webpack from 'webpack';
21
import merge from 'webpack-merge';
32
import ExtractTextPlugin from 'extract-text-webpack-plugin';
43
import OptimizeJsPlugin from 'optimize-js-plugin';
@@ -12,11 +11,7 @@ const devConfig = merge(prodConfig, {
1211
});
1312

1413
devConfig.plugins = [
15-
new webpack.optimize.OccurenceOrderPlugin(),
16-
new webpack.optimize.DedupePlugin(),
17-
new OptimizeJsPlugin({
18-
sourceMap: false
19-
}),
14+
new OptimizeJsPlugin(),
2015
new ExtractTextPlugin('[name].css')
2116
];
2217

build/webpack/dev.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
import webpack from 'webpack';
22
import merge from 'webpack-merge';
33
import HtmlWebpackPlugin from 'html-webpack-plugin';
4+
import FriendlyErrorsPlugin from 'friendly-errors-webpack-plugin';
45
import baseWebpackConfig from './base';
56
import config from '../config';
67

78
Object.keys(baseWebpackConfig.entry).forEach((name) => {
8-
baseWebpackConfig.entry[name] = ['./build/server/client'].concat(baseWebpackConfig.entry[name]);
9+
baseWebpackConfig.entry[name] = ['./build/server/client', ...[baseWebpackConfig.entry[name]]];
910
});
1011

1112
export default merge(baseWebpackConfig, {
12-
devtool: 'source-map',
13+
devtool: '#eval-source-map',
1314
plugins: [
1415
new webpack.WatchIgnorePlugin([config.nodePath]),
1516
new webpack.HotModuleReplacementPlugin(),
16-
new webpack.NoErrorsPlugin(),
17+
new webpack.NoEmitOnErrorsPlugin(),
1718
new HtmlWebpackPlugin({
1819
filename: 'index.html',
1920
template: 'docs/index.html',
2021
inject: true
21-
})
22+
}),
23+
new FriendlyErrorsPlugin()
2224
]
2325
});

build/webpack/prod-docs.js

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,45 @@ export default merge(baseConfig, {
1818
filename: '[name].[chunkhash:8].js',
1919
chunkFilename: '[name].[chunkhash:8].js'
2020
},
21-
vue: {
22-
loaders: {
23-
css: ExtractTextPlugin.extract('css'),
24-
scss: ExtractTextPlugin.extract('css!sass')
25-
},
26-
postcss: [
27-
autoprefixer({
28-
browsers: ['last 3 versions']
29-
})
21+
module: {
22+
rules: [
23+
{
24+
test: /\.vue$/,
25+
loader: 'vue-loader',
26+
options: {
27+
loaders: {
28+
css: ExtractTextPlugin.extract('css'),
29+
scss: ExtractTextPlugin.extract('css!sass')
30+
},
31+
postcss: [
32+
autoprefixer({
33+
browsers: ['last 3 versions']
34+
})
35+
]
36+
}
37+
}
3038
]
3139
},
3240
plugins: [
33-
new webpack.optimize.DedupePlugin(),
41+
new webpack.LoaderOptionsPlugin({
42+
minimize: true,
43+
debug: false
44+
}),
3445
new webpack.optimize.UglifyJsPlugin({
3546
compress: {
3647
warnings: false
3748
},
38-
comments: false
49+
output: {
50+
comments: false
51+
},
52+
sourceMap: false
3953
}),
4054
new OptimizeJsPlugin({
4155
sourceMap: false
4256
}),
43-
new ExtractTextPlugin('[name].[contenthash:8].css'),
57+
new ExtractTextPlugin({
58+
filename: path.join(docsPath, '[name].[contenthash:8].css')
59+
}),
4460
new CopyWebpackPlugin([
4561
{
4662
context: config.assetsPath,
@@ -96,7 +112,6 @@ export default merge(baseConfig, {
96112
new webpack.optimize.CommonsChunkPlugin({
97113
name: 'manifest',
98114
chunks: ['vendor']
99-
}),
100-
new webpack.optimize.OccurenceOrderPlugin()
115+
})
101116
]
102117
});

build/webpack/prod-lib.js

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,23 @@ export default merge(baseConfig, {
3535
library: 'VueMaterial',
3636
libraryTarget: 'umd'
3737
},
38-
vue: {
39-
loaders: {
40-
css: ExtractTextPlugin.extract('css'),
41-
scss: ExtractTextPlugin.extract('css!sass')
42-
},
43-
postcss: [
44-
autoprefixer({
45-
browsers: ['last 2 versions']
46-
})
38+
module: {
39+
rules: [
40+
{
41+
test: /\.vue$/,
42+
loader: 'vue-loader',
43+
options: {
44+
loaders: {
45+
css: ExtractTextPlugin.extract('css'),
46+
scss: ExtractTextPlugin.extract('css!sass')
47+
},
48+
postcss: [
49+
autoprefixer({
50+
browsers: ['last 2 versions']
51+
})
52+
]
53+
}
54+
}
4755
]
4856
},
4957
externals: {
@@ -56,27 +64,33 @@ export default merge(baseConfig, {
5664
}
5765
},
5866
plugins: [
59-
new webpack.optimize.DedupePlugin(),
67+
new webpack.LoaderOptionsPlugin({
68+
minimize: true,
69+
debug: false
70+
}),
6071
new webpack.optimize.UglifyJsPlugin({
6172
compress: {
6273
warnings: false
6374
},
64-
comments: false
75+
output: {
76+
comments: false
77+
},
78+
sourceMap: false
6579
}),
66-
new webpack.optimize.OccurenceOrderPlugin(),
6780
new OptimizeJsPlugin({
6881
sourceMap: false
6982
}),
70-
new webpack.BannerPlugin(
71-
`/*!
72-
* Vue Material v${version}
73-
* Made with love by Marcos Moura
74-
* Released under the MIT License.
75-
*/`
76-
, {
83+
new webpack.BannerPlugin({
84+
banner: `/*!
85+
* Vue Material v${version}
86+
* Made with love by Marcos Moura
87+
* Released under the MIT License.
88+
*/ `,
7789
raw: true,
7890
entryOnly: true
7991
}),
80-
new ExtractTextPlugin('[name].css')
92+
new ExtractTextPlugin({
93+
filename: path.join(config.rootPath, '[name].css')
94+
})
8195
]
8296
});

0 commit comments

Comments
 (0)