forked from shopsys/project-base
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
126 lines (116 loc) · 4.44 KB
/
Copy pathwebpack.config.js
File metadata and controls
126 lines (116 loc) · 4.44 KB
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
const Encore = require('@symfony/webpack-encore');
const EventHooksPlugin = require('event-hooks-webpack-plugin');
const processTrans = require('./assets/js/commands/translations/process');
const CopyPlugin = require('copy-webpack-plugin');
const yaml = require('js-yaml');
const fs = require('fs');
const path = require('path');
const StylelintPlugin = require('stylelint-webpack-plugin');
const sources = require('./assets/js/bin/helpers/sources');
const LiveReloadPlugin = require('webpack-livereload-plugin');
if (!Encore.isRuntimeEnvironmentConfigured()) {
Encore.configureRuntimeEnvironment(process.env.NODE_ENV || 'dev');
}
Encore
.setOutputPath('web/build/')
.setPublicPath('/build')
.setManifestKeyPrefix('web')
.cleanupOutputBeforeBuild()
.autoProvidejQuery()
.addEntry('frontend', './assets/js/frontend.js')
// hp entry?
// order entry?
// product entry?
// cart entry?
.addEntry('styleguide', './assets/js/styleguide/styleguide.js')
.addEntry('admin', './assets/js/admin/admin.js')
.splitEntryChunks()
.enableSingleRuntimeChunk()
.enableSourceMaps(!Encore.isProduction())
.enableVersioning(Encore.isProduction())
.configureBabel(null, {
includeNodeModules: ['@shopsys'],
})
.enableBuildNotifications()
.configureWatchOptions(function (watchOptions) {
watchOptions.ignored = '**/*.json';
})
.addPlugin(new EventHooksPlugin({
beforeRun: () => {
const dirWithJsFiles = [
sources.getFrameworkNodeModulesDir() + '/js/**/*.js',
'./assets/js/**/*.js'
];
const dirWithTranslations = [
sources.getFrameworkVendorDir() + '/src/Resources/translations/*.po',
'./translations/*.po',
];
const outputDirForExportedTranslations = './assets/js/';
try {
processTrans(dirWithJsFiles, dirWithTranslations, outputDirForExportedTranslations);
} catch (e) {
console.log('Parsing files for translations has failed.');
}
}
}))
.addPlugin(new CopyPlugin({
patterns: [
{
from: 'web/bundles/fpjsformvalidator',
to: '../../assets/js/bundles/fpjsformvalidator',
force: true
},
{
from: sources.getFrameworkNodeModulesDir() + '/public/admin',
to: '../../web/public/admin',
force: true
},
{
from: 'assets/public',
to: '../../web/public',
globOptions: {
ignore: ['assets/public/admin/svg/**/*']
},
force: true
}
]
}))
.addPlugin(new LiveReloadPlugin())
;
const domainFile = './config/domains.yaml';
const domains = yaml.safeLoad(fs.readFileSync(domainFile, 'utf8'));
const domainStylesDirectories = new Set(domains.domains.map(domain => {
if (!domain.styles_directory) {
return 'common';
}
return domain.styles_directory;
}));
domainStylesDirectories.forEach(stylesDirectory => {
Encore
.addEntry('frontend-style-' + stylesDirectory, './assets/styles/frontend/' + stylesDirectory + '/main.less')
.addEntry('frontend-print-style-' + stylesDirectory, './assets/styles/frontend/' + stylesDirectory + '/print/main.less')
.addEntry('frontend-wysiwyg-' + stylesDirectory, './assets/styles/frontend/' + stylesDirectory + '/wysiwyg.less');
});
Encore
.addEntry('admin-style', './assets/styles/admin/main.less')
.addEntry('admin-wysiwyg', './assets/styles/admin/wysiwyg.less')
.addEntry('styleguide-style', './assets/styles/styleguide/main.less')
.addPlugin(
new StylelintPlugin({
configFile: '.stylelintrc',
files: 'assets/styles/**/*.less'
})
)
.enableLessLoader()
.enablePostCssLoader()
;
const config = Encore.getWebpackConfig();
config.resolve.alias = {
'jquery-ui': 'jquery-ui/ui/widgets',
'framework': '@shopsys/framework/js',
'jquery': path.resolve(path.join(__dirname, 'node_modules', 'jquery')),
'jquery-ui-styles': path.resolve(path.join(__dirname, 'node_modules', 'jquery-ui')),
'bazinga-translator': path.resolve(path.join(__dirname, 'node_modules', 'bazinga-translator')),
'jquery-ui-nested-sortable': path.resolve(path.join(__dirname, 'node_modules', 'nestedSortable'))
};
module.exports = config;