-
Notifications
You must be signed in to change notification settings - Fork 4
/
webpack.config.js
141 lines (139 loc) · 4.48 KB
/
webpack.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
/* eslint-disable import/no-extraneous-dependencies */
const path = require('path');
const webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const ProgressBarPlugin = require('progress-bar-webpack-plugin');
const dev = process.env.NODE_ENV !== 'production';
module.exports = {
entry: {
index: './src/javascripts/index.js',
admin: './src/javascripts/admin.js',
},
externals: {
vue: 'Vue',
},
plugins: [
// This plugin tears out the common parts of index.js and admin.js
// into a shared `shared.js` file to be included in both the back-office
// and the client-side deployments. This will include things like
// babel-polyfill, Vuejs, lodash functions used in both places, and
// the NodeSupport CustomEvent lib used to build most of the front end
new ProgressBarPlugin(),
new webpack.optimize.CommonsChunkPlugin({
name: 'shared',
chunks: ['index', 'admin'],
}),
// This plugin will wholesale replace 'process.env.NODE_ENV' with the
// value on the right so we need to make sure to wrap it in quotes
// so it doesn't try to evaluate `production` or `development`
// as a symbol in scope and takes it as a string instead. This is to
// tell Vuejs to avoid including in various development dependencies
// when building for production, thereby optimizing the build a little bit more
// https://vuejs.org/v2/guide/deployment.html
// https://webpack.js.org/plugins/define-plugin/
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: `"${process.env.NODE_ENV}"`,
},
}),
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
new ExtractTextPlugin('[name].css'),
],
devtool: dev ? 'eval-source-map' : 'source-map',
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'public', 'build'),
},
module: {
loaders: [
{
test: /\.vue$/,
use: {
loader: 'vue-loader',
options: {
postcss: [
require('stylelint')(),
require('postcss-reporter')({ clearReportedMessages: true }),
require('postcss-cssnext')({ browsers: ['last 2 versions'] }),
require('postcss-color-function')(),
require('postcss-nested')(),
].concat(
dev
? []
: [
require('cssnano')({
autoprefixer: false,
preset: [
'default',
{
discardComments: {
removeAll: true,
},
},
],
}),
],
),
},
},
},
{
test: /\.js$/,
use: {
loader: 'babel-loader',
},
exclude: /node_modules/,
},
{
test: /\.css$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
{
loader: 'css-loader',
options: {
importLoaders: false,
sourceMap: true,
},
},
{
loader: 'postcss-loader',
options: {
ident: 'postcss',
sourceMap: true,
plugins(loader) {
return [
require('stylelint'),
require('postcss-reporter'),
require('postcss-import')({ root: loader.resourcePath }),
require('postcss-cssnext')({
browsers: ['last 2 versions'],
}),
require('postcss-color-function')(),
require('postcss-nested')(),
].concat(
dev
? []
: [
require('cssnano')({
autoprefixer: false,
preset: [
'default',
{
discardComments: {
removeAll: true,
},
},
],
}),
],
);
},
},
},
],
}),
},
],
},
};