diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2017-05-17 00:00:56 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2017-05-17 00:00:56 +0900 |
| commit | fb70e3b1769e9d008b75585e7c3fdfa061491f4d (patch) | |
| tree | 0c80a14191c174d850a8021c79ff02b357d63fba /webpack/module/rules | |
| parent | Merge pull request #462 from syuilo/greenkeeper/mocha-3.4.1 (diff) | |
| download | sharkey-fb70e3b1769e9d008b75585e7c3fdfa061491f4d.tar.gz sharkey-fb70e3b1769e9d008b75585e7c3fdfa061491f4d.tar.bz2 sharkey-fb70e3b1769e9d008b75585e7c3fdfa061491f4d.zip | |
Refactoring
Diffstat (limited to 'webpack/module/rules')
| -rw-r--r-- | webpack/module/rules/i18n.ts | 34 | ||||
| -rw-r--r-- | webpack/module/rules/index.ts | 11 | ||||
| -rw-r--r-- | webpack/module/rules/stylus.ts | 13 | ||||
| -rw-r--r-- | webpack/module/rules/tag.ts | 20 | ||||
| -rw-r--r-- | webpack/module/rules/theme-color.ts | 25 |
5 files changed, 103 insertions, 0 deletions
diff --git a/webpack/module/rules/i18n.ts b/webpack/module/rules/i18n.ts new file mode 100644 index 0000000000..0539e97db4 --- /dev/null +++ b/webpack/module/rules/i18n.ts @@ -0,0 +1,34 @@ +/** + * Replace i18n texts + */ + +const StringReplacePlugin = require('string-replace-webpack-plugin'); + +export default (lang, locale) => ({ + enforce: 'pre', + test: /\.(tag|js)$/, + exclude: /node_modules/, + loader: StringReplacePlugin.replace({ + replacements: [ + { + pattern: /%i18n:(.+?)%/g, replacement: (_, key) => { + let text = locale; + const error = key.split('.').some(k => { + if (text.hasOwnProperty(k)) { + text = text[k]; + return false; + } else { + return true; + } + }); + if (error) { + console.warn(`key '${key}' not found in '${lang}'`); + return key; + } else { + return text.replace(/'/g, '\\\'').replace(/"/g, '\\"'); + } + } + } + ] + }) +}); diff --git a/webpack/module/rules/index.ts b/webpack/module/rules/index.ts new file mode 100644 index 0000000000..2308f4e535 --- /dev/null +++ b/webpack/module/rules/index.ts @@ -0,0 +1,11 @@ +import i18n from './i18n'; +import themeColor from './theme-color'; +import tag from './tag'; +import stylus from './stylus'; + +export default (lang, locale) => [ + i18n(lang, locale), + themeColor(), + tag(), + stylus() +]; diff --git a/webpack/module/rules/stylus.ts b/webpack/module/rules/stylus.ts new file mode 100644 index 0000000000..dd1e4c3218 --- /dev/null +++ b/webpack/module/rules/stylus.ts @@ -0,0 +1,13 @@ +/** + * Stylus support + */ + +export default () => ({ + test: /\.styl$/, + exclude: /node_modules/, + use: [ + { loader: 'style-loader' }, + { loader: 'css-loader' }, + { loader: 'stylus-loader' } + ] +}); diff --git a/webpack/module/rules/tag.ts b/webpack/module/rules/tag.ts new file mode 100644 index 0000000000..706af35b40 --- /dev/null +++ b/webpack/module/rules/tag.ts @@ -0,0 +1,20 @@ +/** + * Riot tags + */ + +export default () => ({ + test: /\.tag$/, + exclude: /node_modules/, + loader: 'riot-tag-loader', + query: { + hot: false, + style: 'stylus', + expr: false, + compact: true, + parserOptions: { + style: { + compress: true + } + } + } +}); diff --git a/webpack/module/rules/theme-color.ts b/webpack/module/rules/theme-color.ts new file mode 100644 index 0000000000..7ee545191c --- /dev/null +++ b/webpack/module/rules/theme-color.ts @@ -0,0 +1,25 @@ +/** + * Theme color provider + */ + +const StringReplacePlugin = require('string-replace-webpack-plugin'); + +const constants = require('../../../src/const.json'); + +export default () => ({ + enforce: 'pre', + test: /\.tag$/, + exclude: /node_modules/, + loader: StringReplacePlugin.replace({ + replacements: [ + { + pattern: /\$theme\-color\-foreground/g, + replacement: () => constants.themeColorForeground + }, + { + pattern: /\$theme\-color/g, + replacement: () => constants.themeColor + }, + ] + }) +}); |