forked from xmmedia/starter_symfony_4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.base.config.js
121 lines (104 loc) · 4.03 KB
/
webpack.base.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
'use strict';
const path = require('path');
const glob = require('glob-all');
const PurgecssPlugin = require('purgecss-webpack-plugin');
const Dotenv = require('dotenv-webpack');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
function resolve (dir) {
return path.join(__dirname, '.', dir);
}
// Base configuration of Encore/Webpack
module.exports = function (Encore) {
if (!Encore.isRuntimeEnvironmentConfigured()) {
Encore.configureRuntimeEnvironment(process.env.NODE_ENV || 'dev');
}
Encore
// directory where all compiled assets will be stored
.setOutputPath('public/build/')
// what's the public path to this directory (relative to your project's document root dir)
.setPublicPath('/build')
// always create hashed filenames (e.g. public.a1b2c3.css)
.enableVersioning(true)
// empty the outputPath dir before each build
.cleanupOutputBeforeBuild()
// don't output the runtime chunk as we only include 1 JS file per page
.disableSingleRuntimeChunk()
// will output as build/admin.js and similar
.addEntry('admin', './public/js/src/admin.js')
.addEntry('public', './public/js/src/public.js')
// allow sass/scss files to be processed
.enableSassLoader(function(sassOptions) {}, {
// see: http://symfony.com/doc/current/frontend/encore/bootstrap.html#importing-bootstrap-sass
resolveUrlLoader: false,
})
.enablePostCssLoader()
// allow .vue files to be processed
.enableVueLoader((options) => {
options.transpileOptions = {
transforms: {
dangerousTaggedTemplateString: true
},
};
})
.enableSourceMaps(true)
.configureBabel(() => {}, {
includeNodeModules: [
'vue-apollo', // Object.entries()
],
})
.addLoader({
test: /\.svg$/,
use: [
{
loader: 'svgo-loader',
options: {
plugins: [
// config targeted at icon files, but should work for others
{ removeUselessDefs: false },
{ cleanupIDs: false },
],
},
},
],
})
.addAliases({
'@': resolve('public/js/src'),
'vue$': 'vue/dist/vue.esm.js',
})
.addPlugin(new Dotenv())
.addPlugin(new BundleAnalyzerPlugin({
analyzerMode: 'static',
openAnalyzer: false,
}))
;
if (Encore.isProduction()) {
// Custom PurgeCSS extractor for Tailwind that allows special characters in class names
class TailwindExtractor {
static extract(content) {
return content.match(/[A-Za-z0-9-_:\/]+/g) || [];
}
}
Encore
.addPlugin(new PurgecssPlugin({
// Specify the locations of any files you want to scan for class names.
paths: glob.sync([
path.join(__dirname, 'templates/**/*.html.twig'),
path.join(__dirname, 'public/js/src/**/*.vue'),
path.join(__dirname, 'public/js/src/**/*.js'),
path.join(__dirname, 'node_modules/vue-js-modal/dist/index.js'),
]),
extractors: [
{
extractor: TailwindExtractor,
// Specify the file extensions to include when scanning for class names
extensions: ['html', 'js', 'php', 'vue', 'twig'],
},
],
whitelistPatterns: [
// vue transition classes: https://vuejs.org/v2/guide/transitions.html#Transition-Classes
/-enter/,
/-leave/,
],
}));
}
};