-
Notifications
You must be signed in to change notification settings - Fork 44
/
webpack.lint.config.js
150 lines (141 loc) · 3.6 KB
/
webpack.lint.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
// Initialization
const webpack = require('webpack');
// Lint and test
const BrowserSyncPlugin = require('browser-sync-webpack-plugin');
const StyleLintPlugin = require('stylelint-webpack-plugin');
// File ops
const HtmlWebpackPlugin = require('html-webpack-plugin');
// Folder ops
const CopyWebpackPlugin = require('copy-webpack-plugin');
const path = require('path');
// PostCSS support
const postcssImport = require('postcss-easy-import');
const precss = require('precss');
const autoprefixer = require('autoprefixer');
// Constants
const APP = path.join(__dirname, 'app');
const BUILD = path.join(__dirname, 'build');
const STYLE = path.join(__dirname, 'app/style.css');
const PUBLIC = path.join(__dirname, 'app/public');
const TEMPLATE = path.join(__dirname, 'app/templates/index_default.html');
const HOST = process.env.HOST || 'localhost';
const PORT = process.env.PORT || 8080;
const PROXY = `http://${HOST}:${PORT}`;
const LINT = path.join(__dirname, '.eslintrc.js');
const STYLELINT = ['./app/styles/**/*.css', './app/styles.css'];
module.exports = {
// Paths and extensions
entry: {
app: APP,
style: STYLE
},
output: {
path: BUILD,
filename: '[name].js',
publicPath: '/'
},
resolve: {
extensions: ['', '.js', '.jsx', '.css']
},
eslint: {
configFile: LINT,
emitError: true
},
// Loaders for processing different file types
module: {
preLoaders: [
{
test: /\.jsx?$/,
loaders: ['eslint'],
include: APP
}
],
loaders: [
{
test: /\.jsx?$/,
loaders: ['babel?cacheDirectory'],
include: APP
},
{
test: /\.css$/,
loaders: ['style', 'css', 'postcss'],
include: APP
},
// Process JSON data fixtures
{
test: /\.json$/,
loader: 'json',
include: APP
}
]
},
// Configure PostCSS plugins
postcss: function processPostcss(webpack) { // eslint-disable-line no-shadow
return [
postcssImport({
addDependencyTo: webpack
}),
precss,
autoprefixer({ browsers: ['last 2 versions'] })
];
},
// Source maps used for debugging information
devtool: 'eval-source-map',
// webpack-dev-server configuration
devServer: {
historyApiFallback: true,
hot: true,
inline: true,
progress: true,
stats: 'errors-only',
host: HOST,
port: PORT,
// CopyWebpackPlugin: This is required for webpack-dev-server.
// The path should be an absolute path to your build destination.
outputPath: BUILD
},
// Webpack plugins
plugins: [
// Required to inject NODE_ENV within React app.
// Reduntant package.json script entry does not do that, but required for .babelrc
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify('test') // eslint-disable-line quote-props
}
}),
new StyleLintPlugin({
files: STYLELINT,
syntax: 'scss'
}),
new BrowserSyncPlugin(
// BrowserSync options
{
host: HOST,
port: PORT,
proxy: PROXY
},
// plugin options
{
// prevent BrowserSync from reloading the page
// and let Webpack Dev Server take care of this
reload: false
}
),
new webpack.HotModuleReplacementPlugin(),
new CopyWebpackPlugin([
{ from: PUBLIC, to: BUILD }
],
{
ignore: [
// Doesn't copy Mac storage system files
'.DS_Store'
]
}
),
new HtmlWebpackPlugin({
template: TEMPLATE,
// JS placed at the bottom of the body element
inject: 'body'
})
]
};