Skip to content

Commit 78f87b6

Browse files
committed
Webpack config in dev and prod include copywebpack for static translations.json
Change in i18n to serve the translations from a different path
1 parent afe74e9 commit 78f87b6

File tree

5 files changed

+20
-5
lines changed

5 files changed

+20
-5
lines changed

client/i18n.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const fallbackLng = ['en-US'];
77
const availableLanguages = ['en-US', 'es-419'];
88

99
const options = {
10-
loadPath: '/translations/{{lng}}/translations.json',
10+
loadPath: 'locales/{{lng}}/translations.json',
1111
requestOptions: { // used for fetch, can also be a function (payload) => ({ method: 'GET' })
1212
mode: 'no-cors'
1313
},

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@
154154
"connect-mongo": "^1.3.2",
155155
"console-feed": "^2.8.11",
156156
"cookie-parser": "^1.4.3",
157+
"copy-webpack-plugin": "^6.0.3",
157158
"cors": "^2.8.5",
158159
"cross-env": "^5.2.1",
159160
"csslint": "^1.0.5",

server/server.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ app.use(corsMiddleware);
7575
app.options('*', corsMiddleware);
7676

7777
// Body parser, cookie parser, sessions, serve public assets
78-
78+
app.use('/translations', Express.static('translations/locales/'));
7979
app.use(Express.static(path.resolve(__dirname, '../dist/static'), {
8080
maxAge: process.env.STATIC_MAX_AGE || (process.env.NODE_ENV === 'production' ? '1d' : '0')
8181
}));
82-
app.use('/translations', Express.static('translations/locales/'));
82+
8383
app.use(bodyParser.urlencoded({ limit: '50mb', extended: true }));
8484
app.use(bodyParser.json({ limit: '50mb' }));
8585
app.use(cookieParser());

webpack/config.dev.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const webpack = require('webpack');
22
const path = require('path');
3+
const CopyWebpackPlugin = require('copy-webpack-plugin')
34

45
if (process.env.NODE_ENV === 'development') {
56
require('dotenv').config();
@@ -40,7 +41,13 @@ module.exports = {
4041
'process.env': {
4142
NODE_ENV: JSON.stringify('development')
4243
}
43-
})
44+
}),
45+
new CopyWebpackPlugin({
46+
patterns: [
47+
{from: path.resolve(__dirname, '../translations/locales') , to: path.resolve(__dirname, 'locales')}
48+
]
49+
}
50+
)
4451
],
4552
module: {
4653
rules: [

webpack/config.prod.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const cssnext = require('postcss-cssnext');
88
const postcssFocus = require('postcss-focus');
99
const postcssReporter = require('postcss-reporter');
1010
const cssnano = require('cssnano');
11+
const CopyWebpackPlugin = require('copy-webpack-plugin')
1112
if (process.env.NODE_ENV === "development") {
1213
require('dotenv').config();
1314
}
@@ -144,7 +145,13 @@ module.exports = [{
144145
}),
145146
new MiniCssExtractPlugin({
146147
filename: 'app.[hash].css',
147-
})
148+
}),
149+
new CopyWebpackPlugin({
150+
patterns: [
151+
{from: path.resolve(__dirname, '../translations/locales') , to: path.resolve(__dirname, '../dist/static/locales')}
152+
]
153+
}
154+
)
148155
]
149156
},
150157
{

0 commit comments

Comments
 (0)