Skip to content

Commit

Permalink
feat(virtual): images and languages
Browse files Browse the repository at this point in the history
  • Loading branch information
StephanGerbeth committed Oct 23, 2018
1 parent 280b9ea commit 0a4ff6f
Show file tree
Hide file tree
Showing 33 changed files with 554 additions and 269 deletions.
81 changes: 41 additions & 40 deletions .svgorc.yml
Original file line number Diff line number Diff line change
@@ -1,42 +1,43 @@
plugins:
- cleanupAttrs: true,
- removeDoctype: true,
- removeXMLProcInst: true,
- removeComments: true,
- removeMetadata: true,
- removeTitle: true,
- removeDesc: true,
- removeUselessDefs: true,
- removeXMLNS: true,
- removeEditorsNSData: true,
- removeEmptyAttrs: true,
- removeHiddenElems: false,
- removeEmptyText: true,
- removeEmptyContainers: true,
- removeViewBox: true,
- cleanupEnableBackground: true,
- minifyStyles: true,
- convertStyleToAttrs: true,
- convertColors: true,
- convertPathData: true,
- convertTransform: true,
- removeUnknownsAndDefaults: true,
- removeNonInheritableGroupAttrs: true,
- removeUselessStrokeAndFill: true,
- removeUnusedNS: true,
- cleanupIDs: true,
- cleanupNumericValues: true,
- cleanupListOfValues: true,
- moveElemsAttrsToGroup: true,
- moveGroupAttrsToElems: true,
- collapseGroups: true,
- mergePaths: true,
- convertShapeToPath: true,
- sortAttrs: false,
- removeDimensions: false,
- removeAttrs: false,
- removeElementsByAttr: false,
- addClassesToSVGElement: false,
- addAttributesToSVGElement: false,
- removeStyleElement: false,
- cleanupAttrs: true
- removeDoctype: true
- removeXMLProcInst: true
- removeComments: true
- removeMetadata: true
- removeTitle: true
- removeDesc: true
- removeUselessDefs: true
- removeXMLNS: true
- removeEditorsNSData: true
- removeEmptyAttrs: true
- removeHiddenElems: false
- removeEmptyText: true
- removeEmptyContainers: true
- removeViewBox: true
- cleanupEnableBackground: true
- minifyStyles: true
- convertStyleToAttrs: true
- convertColors: true
- convertPathData: true
- convertTransform: true
- removeUnknownsAndDefaults: true
- removeNonInheritableGroupAttrs: true
- removeUselessStrokeAndFill: true
- removeUnusedNS: true
- cleanupIDs: true
- cleanupNumericValues: true
- cleanupListOfValues: true
- moveElemsAttrsToGroup: true
- moveGroupAttrsToElems: true
- collapseGroups: true
- mergePaths: true
- convertShapeToPath: true
# WARNING DANGER DANGER
- sortAttrs: false
- removeDimensions: false
- removeAttrs: false
- removeElementsByAttr: false
- addClassesToSVGElement: false
- addAttributesToSVGElement: false
- removeStyleElement: false
- removeScriptElement: false
2 changes: 1 addition & 1 deletion config.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"**/logs": true,
"**/*.log": true,
"**/.DS_Store": true,
".*": true
".*": false
},
"files.associations": {
".branchlintrc": "json",
Expand Down
75 changes: 44 additions & 31 deletions env/nuxt.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
process.env.DEBUG = 'nuxt:*';
// process.env.DEBUG = '*';
const path = require('path');
const webpackPlugins = require('./webpack/plugins');
const webpackModules = require('./webpack/modules');
// const i18nExtensions = require('vue-i18n-extensions');

module.exports = {
dev: process.env.NODE_ENV === 'development',
Expand All @@ -10,23 +10,57 @@ module.exports = {
build: {
analyze: {
analyzerMode: 'static',
reportFilename: '../reports/webpack-bundle-analyzer.html',
reportFilename: path.resolve('reports/webpack-bundle-analyzer.html'),
openAnalyzer: false
},

// plugins: [],

// vendor: ['vue-i18n'],

extend(config, compiler) {
webpackPlugins(config.plugins, this.options.srcDir, compiler);
extend(config) {
webpackPlugins(config.plugins, this.options, config);
webpackModules(config.module);
return config;
}
},

plugins: ['~/plugins/i18n.js'],
vue: {
transformAssetUrls: {
video: 'src',
source: 'src',
object: 'src',
embed: 'src',
i18n: 'src'
}
},

router: {
base: '/'
},

modules: [
[
'nuxt-i18n',
{
locales: [
{
code: 'en',
iso: 'en-US'
},
{
code: 'de',
iso: 'de-DE'
}
],
defaultLocale: 'de',
strategy: 'prefix_except_default',
vueI18n: {
fallbackLocale: 'de',
messages: {
en: require(path.resolve('src/locales/global/en.json')),
de: require(path.resolve('src/locales/global/de.json'))
}
},
vueI18nLoader: false
}
],
[
'@nuxtjs/pwa',
{
Expand Down Expand Up @@ -61,29 +95,8 @@ module.exports = {
]
],

router: {
middleware: 'i18n'
},

generate: {
routes: ['/en', '/en/about', '/de', '/de/about'],
minify: {
removeOptionalTags: false
}
},

head: {
meta: [],
link: []
}

// render: {
// // confiture `render`
// // see Nuxt.js docs: https://nuxtjs.org/api/configuration-render#bundleRenderer
// bundleRenderer: {
// directives: {
// t: i18nExtensions.directive
// }
// }
// }
};
7 changes: 4 additions & 3 deletions env/webpack/modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ module.exports = function(module) {
let list = []
.concat(
...[
require('./modules/url-loader')(module.rules),
require('./modules/svg-sprite-loader')(module.rules)
// require('./modules/vue-loader')(module.rules)
require('./modules/i18n-loader')(module.rules),
require('./modules/postcss-fix-loader')(module.rules),
require('./modules/svg-sprite-loader')(module.rules),
require('./modules/url-loader')(module.rules)
]
)
.reduce(function(result, item) {
Expand Down
15 changes: 15 additions & 0 deletions env/webpack/modules/i18n-loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = function() {
return {
env: {
development: true,
production: true,
build: true,
static: true
},
module: {
resourceQuery: /\bblockType=i18n\b/,
use: [{ loader: '@kazupon/vue-i18n-loader' }],
type: 'javascript/auto'
}
};
};
14 changes: 14 additions & 0 deletions env/webpack/modules/postcss-fix-loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// issue: https://github.com/nuxt/nuxt.js/issues/4061
// fix: https://qiita.com/karszawa/items/96a9156936fba129cff0

module.exports = function(rules) {
const cssLoader = rules.find(rule => rule.test.test('.css'));
if (cssLoader) {
rules.push({
test: /\.postcss/,
oneOf: cssLoader.oneOf
});
}

return [];
};
11 changes: 5 additions & 6 deletions env/webpack/modules/vue-loader.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
module.exports = function(rules) {
let vueLoader = rules.find(rule => rule.loader === 'vue-loader');
vueLoader.options.loaders.i18n = '@kazupon/vue-i18n-loader';
vueLoader.options.cssModules = {
localIdentName: '[name]__[local]',
camelCase: false
};
rules.push({
resourceQuery: /\bblockType=i18n\b/,
use: [{ loader: '@kazupon/vue-i18n-loader' }],
type: 'javascript/auto'
});
return [];
};
4 changes: 2 additions & 2 deletions env/webpack/plugins.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module.exports = function(plugins) {
module.exports = function(plugins, options) {
let list = []
.concat(
...[
require('./plugins/virtual-file'),
require('./plugins/virtual-file')(options),
require('./plugins/imagemin'),
require('./plugins/svg-sprite'),
require('./plugins/monitor')
Expand Down
94 changes: 56 additions & 38 deletions env/webpack/plugins/virtual-file.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,59 @@
const fs = require('fs');
const VirtualImage = require('webpack-virtual-modules');
const VirtualImage = require('./virtual-file/VirtualImage');
const VirtualLang = require('./virtual-file/VirtualLang');
let locales = [];

module.exports = [
{
env: {
development: true,
production: true,
build: true,
static: true
module.exports = function(options) {
locales = options.modules.reduce((result, item) => {
if (item[0] === 'nuxt-i18n') {
return result.concat(item[1].locales);
}
return result;
}, []);

return [
{
env: {
development: true,
production: true,
build: true,
static: true
},
plugin: new VirtualImage(/(?!\.png24)\.(png|jpe?g|gif)$/)
},
{
env: {
development: true,
production: true,
build: true,
static: true
},
plugin: new VirtualImage(/\.(webp)$/, {
redirectTo: function(url, regex) {
return url.replace(regex, '');
}
})
},
plugin: new VirtualImage(
// {
// 'src/assets/image1.png.webp': fs.readFileSync(
// 'src/assets/image1.png'
// )
// }
/\.(webp)$/,
function(resource, regex) {
return {
path: 'src/' + resource.request,
file: fs.readFileSync('src/' + resource.request.replace(regex, ''))
};
}
)
},
{
env: {
development: true,
production: true,
build: true,
static: true
{
env: {
development: true,
production: true,
build: true,
static: true
},
plugin: new VirtualImage(/\.(png24\.png)$/, {
redirectTo: function(url, regex) {
return url.replace(regex, '.png');
}
})
},
plugin: new VirtualImage(/\.(png24\.png)$/, function(resource, regex) {
return {
path: 'src/' + resource.request,
file: fs.readFileSync('src/' + resource.request.replace(regex, '.png'))
};
})
}
];
{
env: {
development: true,
production: true,
build: true,
static: true
},
plugin: new VirtualLang(/^@.+\.(lang)/, locales)
}
];
};
Loading

0 comments on commit 0a4ff6f

Please sign in to comment.