Skip to content
This repository was archived by the owner on May 14, 2023. It is now read-only.

Commit 79d7555

Browse files
committed
Webpack and development server are configured.
1 parent 904d427 commit 79d7555

File tree

4 files changed

+142
-0
lines changed

4 files changed

+142
-0
lines changed

server/server.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/* eslint-disable import/no-extraneous-dependencies */
2+
3+
const browserSync = require('browser-sync').create();
4+
const webpackDevMiddleware = require('webpack-dev-middleware');
5+
const webpackHotMiddleware = require('webpack-hot-middleware');
6+
const webpack = require('webpack');
7+
const webpackConfig = require('./webpack.config.base');
8+
9+
const DEV_PORT = 3000;
10+
const compiler = webpack(webpackConfig);
11+
12+
browserSync.init({
13+
server: {
14+
baseDir: '../dist',
15+
index: 'index.html',
16+
},
17+
codeSync: true,
18+
files: ['../dist'],
19+
notify: true,
20+
port: DEV_PORT,
21+
middleware: [
22+
webpackDevMiddleware(compiler, {
23+
publicPath: '/',
24+
hot: true,
25+
stats: { colors: true },
26+
}),
27+
webpackHotMiddleware(compiler, {
28+
reload: true,
29+
}),
30+
],
31+
});

server/webpack.config.base.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const path = require('path');
2+
const webpackModules = require('./webpack.modules');
3+
const webpackPlugins = require('./webpack.plugins');
4+
5+
const config = {
6+
entry: ['./src/index.js', 'webpack-hot-middleware/client'],
7+
output: {
8+
filename: '[name].[hash].js',
9+
path: path.resolve(__dirname, '../dist'),
10+
},
11+
target: 'web',
12+
module: webpackModules,
13+
plugins: webpackPlugins,
14+
};
15+
16+
module.exports = config;

server/webpack.modules.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/* eslint-disable import/no-extraneous-dependencies */
2+
3+
const path = require('path');
4+
const ExtractTextPlugin = require('extract-text-webpack-plugin');
5+
6+
module.exports = {
7+
rules: [
8+
{
9+
test: /\.(js|vue)$/,
10+
exclude: [
11+
path.resolve(__dirname, '../node_modules'),
12+
],
13+
use: [
14+
{ loader: 'eslint-loader', options: { failOnError: true } },
15+
],
16+
enforce: 'pre',
17+
},
18+
{
19+
test: /\.vue$/,
20+
exclude: [
21+
path.resolve(__dirname, '../node_modules'),
22+
],
23+
use: 'vue-loader',
24+
},
25+
{
26+
test: /\.js$/,
27+
exclude: [
28+
path.resolve(__dirname, '../node_modules'),
29+
],
30+
use: [
31+
{ loader: 'babel-loader' },
32+
],
33+
},
34+
{
35+
test: /\.scss$/,
36+
exclude: [
37+
path.resolve(__dirname, '../node_modules'),
38+
],
39+
use: ExtractTextPlugin.extract({
40+
fallback: 'style-loader',
41+
use: [
42+
{ loader: 'css-loader' },
43+
{ loader: 'resolve-url-loader' },
44+
{ loader: 'sass-loader?sourceMap' },
45+
{ loader: 'postcss-loader' },
46+
],
47+
}),
48+
},
49+
{
50+
test: /\.(woff|woff2)$/,
51+
use: [
52+
{ loader: 'file-loader', options: { name: 'fonts/[name].[ext]' } },
53+
],
54+
},
55+
{
56+
test: /\.(gif|jpg|png)$/,
57+
use: [
58+
{ loader: 'url-loader', options: { name: 'images/[name].[ext]?[hash]', limit: 5000 } },
59+
],
60+
},
61+
{
62+
test: /\.svg$/,
63+
use: [
64+
{ loader: 'file-loader', options: { name: 'images/[name].[ext]?[hash]' } },
65+
],
66+
},
67+
],
68+
};

server/webpack.plugins.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/* eslint-disable import/no-extraneous-dependencies */
2+
3+
const webpack = require('webpack');
4+
const HtmlWebpackPlugin = require('html-webpack-plugin');
5+
const ExtractTextPlugin = require('extract-text-webpack-plugin');
6+
7+
const COPYRIGHT_TEXT = 'Copyright 2017\nCode by Jeff Mosawy\n\nhttp://www.jmosawy.com\nj@mosawy.net';
8+
9+
module.exports = [
10+
new webpack.optimize.CommonsChunkPlugin({
11+
name: 'vendor',
12+
minChunks(module) {
13+
return module.context && module.context.indexOf('node_modules') !== -1;
14+
},
15+
}),
16+
new webpack.optimize.CommonsChunkPlugin({
17+
name: 'manifest',
18+
}),
19+
new HtmlWebpackPlugin({
20+
filename: 'index.html',
21+
template: 'index.html',
22+
inject: true,
23+
}),
24+
new webpack.HotModuleReplacementPlugin(),
25+
new ExtractTextPlugin('app.css?[contenthash]'),
26+
new webpack.BannerPlugin({ banner: COPYRIGHT_TEXT }),
27+
];

0 commit comments

Comments
 (0)