mirror of
https://github.com/elyby/accounts-frontend.git
synced 2024-12-29 00:10:54 +05:30
Fix multiple fontgen-loader invocations in production mode
This commit is contained in:
parent
003a224688
commit
9b00815f96
@ -47,6 +47,8 @@ try {
|
|||||||
console.error('\n\n===\nPlease create dev.json config under ./config based on template.dev.json\n===\n\n');
|
console.error('\n\n===\nPlease create dev.json config under ./config based on template.dev.json\n===\n\n');
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
|
const fileCache = {};
|
||||||
|
|
||||||
|
|
||||||
const cssLoaderQuery = {
|
const cssLoaderQuery = {
|
||||||
modules: true,
|
modules: true,
|
||||||
@ -207,7 +209,6 @@ var webpackConfig = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
postcss() {
|
postcss() {
|
||||||
// TODO: иконочные шрифты эмитятся > 1 раза
|
|
||||||
return [
|
return [
|
||||||
cssImport({
|
cssImport({
|
||||||
path: rootPath,
|
path: rootPath,
|
||||||
@ -221,11 +222,18 @@ var webpackConfig = {
|
|||||||
load: ((defaultLoad) =>
|
load: ((defaultLoad) =>
|
||||||
(filename, importOptions) => {
|
(filename, importOptions) => {
|
||||||
if (/\.font.(js|json)$/.test(filename)) {
|
if (/\.font.(js|json)$/.test(filename)) {
|
||||||
return new Promise((resolve, reject) =>
|
if (!fileCache[filename] || !isProduction) {
|
||||||
this.loadModule(filename, (err, source) =>
|
// do not execute loader on the same file twice
|
||||||
err ? reject(err) : resolve(this.exec(source))
|
// this is an overcome for a bug with ExtractTextPlugin, for isProduction === true
|
||||||
)
|
// when @imported files may be processed mutiple times
|
||||||
);
|
fileCache[filename] = new Promise((resolve, reject) =>
|
||||||
|
this.loadModule(filename, (err, source) =>
|
||||||
|
err ? reject(err) : resolve(this.exec(source))
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return fileCache[filename];
|
||||||
}
|
}
|
||||||
|
|
||||||
return defaultLoad(filename, importOptions);
|
return defaultLoad(filename, importOptions);
|
||||||
@ -248,10 +256,12 @@ if (isDockerized) {
|
|||||||
if (isProduction) {
|
if (isProduction) {
|
||||||
webpackConfig.module.loaders.forEach((loader) => {
|
webpackConfig.module.loaders.forEach((loader) => {
|
||||||
if (loader.extractInProduction) {
|
if (loader.extractInProduction) {
|
||||||
|
// remove style-loader from chain and pass through ExtractTextPlugin
|
||||||
const parts = loader.loader.split('!');
|
const parts = loader.loader.split('!');
|
||||||
|
|
||||||
loader.loader = ExtractTextPlugin.extract(
|
loader.loader = ExtractTextPlugin.extract(
|
||||||
parts[0],
|
parts[0], // style-loader
|
||||||
parts.slice(1)
|
parts.slice(1) // css-loader and rest
|
||||||
.join('!')
|
.join('!')
|
||||||
.replace(/[&?]sourcemap/, '')
|
.replace(/[&?]sourcemap/, '')
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user