forked from phase2/particle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.particle.js
150 lines (145 loc) · 3.81 KB
/
webpack.particle.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
/**
* Particle base config.
*
* The shared loaders, plugins, and processing that all our "apps" should use.
* This file is not used directly. See particle.js for usage.
*/
// Library Imports
const { ProgressPlugin, ProvidePlugin } = require('webpack');
// Plugins
const VueLoaderPlugin = require('vue-loader/lib/plugin');
const TerserPlugin = require('terser-webpack-plugin');
// Constants: environment
// NODE_ENV is set within all NPM scripts before running Webpack, eg:
//
// "NODE_ENV='development' webpack-dev-server --config ./apps/pl/webpack.config.js --hot",
//
// NODE_ENV is either:
// - development
// - production
// Defaults to 'production'
const { NODE_ENV = 'production' } = process.env;
// Enable to track down deprecation during development
// process.traceDeprecation = true;
module.exports = {
// entry: {}, // See entryPrepend() and particle() below for entry details
mode: NODE_ENV, // development|production
output: {
filename: '[name].js',
},
devtool: NODE_ENV === 'development' ? 'eval' : 'source-map',
module: {
rules: [
{
test: /\.vue$/,
loader: 'vue-loader',
options: {
loaders: {
js: 'babel-loader',
},
},
},
{
test: /\.css$/,
use: [
{
loader: 'css-loader',
options: {
sourceMap: true,
},
},
{
loader: 'resolve-url-loader',
options: {
sourceMap: true,
root: '',
},
},
{
// PostCSS config at ./postcss.config.js
loader: 'postcss-loader',
options: {
sourceMap: true,
ident: 'postcss',
},
},
],
},
{
test: /\.(js|vue)$/,
enforce: 'pre',
exclude: /node_modules/,
loader: 'eslint-loader',
options: {
emitWarning: true, // development only
// emitWarning: false, // production only
},
},
{
test: /\.js$/,
// @babel runtime and core must NOT be transformed by babel
exclude: /@babel(?:\/|\\{1,2})runtime|core-js/,
use: {
loader: 'babel-loader',
},
},
{
test: /\.(png|jpg|gif|svg)$/,
loader: 'file-loader',
options: {
name: 'images/[name].[ext]?[hash]',
},
},
{
test: /\.(woff|woff2|eot|ttf|otf)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
use: [
{
loader: 'file-loader',
options: {
name: 'fonts/[name].[ext]?[hash]',
},
},
],
},
// Non-standard assets on the dependency chain
{
test: /\.twig$/,
loader: 'file-loader',
options: {
emitFile: false,
},
},
],
},
optimization: {
minimizer: [
new TerserPlugin({
sourceMap: NODE_ENV === 'production',
}),
],
},
plugins: [
// Provides "global" vars mapped to an actual dependency. Allows e.g. jQuery
// plugins to assume that `window.jquery` is available
new ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery',
}),
// Handle .vue files
new VueLoaderPlugin(),
// Only add ProgressPlugin for non-production env.
...(NODE_ENV === 'production'
? []
: [new ProgressPlugin({ profile: false })]),
],
resolve: {
alias: {
// Since we operate in a world where random Vue templates might have to
// be output via twig, we need the Vue build that includes the whole
// template compiling engine. If we are on a build that will NEVER read
// HTML from the DOM and use it as a template, then remove this line.
vue$: 'vue/dist/vue.esm.js',
},
},
};