久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    • <bdo id='lG01e'></bdo><ul id='lG01e'></ul>

      <i id='lG01e'><tr id='lG01e'><dt id='lG01e'><q id='lG01e'><span id='lG01e'><b id='lG01e'><form id='lG01e'><ins id='lG01e'></ins><ul id='lG01e'></ul><sub id='lG01e'></sub></form><legend id='lG01e'></legend><bdo id='lG01e'><pre id='lG01e'><center id='lG01e'></center></pre></bdo></b><th id='lG01e'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='lG01e'><tfoot id='lG01e'></tfoot><dl id='lG01e'><fieldset id='lG01e'></fieldset></dl></div>

      <small id='lG01e'></small><noframes id='lG01e'>

    1. <tfoot id='lG01e'></tfoot>

    2. <legend id='lG01e'><style id='lG01e'><dir id='lG01e'><q id='lG01e'></q></dir></style></legend>
      1. 在 React JS 中需要帶有變量的文件

        Require file with a variable in React JS(在 React JS 中需要帶有變量的文件)
            <tbody id='EwM05'></tbody>

          <small id='EwM05'></small><noframes id='EwM05'>

          <legend id='EwM05'><style id='EwM05'><dir id='EwM05'><q id='EwM05'></q></dir></style></legend>

            1. <tfoot id='EwM05'></tfoot>
                <bdo id='EwM05'></bdo><ul id='EwM05'></ul>

              • <i id='EwM05'><tr id='EwM05'><dt id='EwM05'><q id='EwM05'><span id='EwM05'><b id='EwM05'><form id='EwM05'><ins id='EwM05'></ins><ul id='EwM05'></ul><sub id='EwM05'></sub></form><legend id='EwM05'></legend><bdo id='EwM05'><pre id='EwM05'><center id='EwM05'></center></pre></bdo></b><th id='EwM05'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='EwM05'><tfoot id='EwM05'></tfoot><dl id='EwM05'><fieldset id='EwM05'></fieldset></dl></div>

                1. 本文介紹了在 React JS 中需要帶有變量的文件的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

                  我正在嘗試在路徑中要求一個帶有變量的文件.類似的東西

                  I'm trying to require a file with a variable in the path. Something like

                  const langCode = this.props.langCode; // en
                  let languageFile = require('../common/languages/' + langCode);
                  

                  langCode 可以是 fr、en、de、nl.因此,我想要得到的是例如

                  Where langCode can be fr, en, de, nl. Thus what I'm trying to get is for example

                  require('../common/languages/en'); 
                  

                  當我在最后鍵入它時沒有變量,因此 require('../common/languages/en'); 效果很好.但是當我嘗試使用 require('../common/languages/' + langCode); 時,它不起作用,langCode 的值無關緊要也是zh.

                  When I type it without variable at the end, thus require('../common/languages/en'); it works good. But when I try with require('../common/languages/' + langCode); it won't work, doesn't matter that the value of the langCode is also en.

                  我得到下一個錯誤:

                  bundle.js:1 未捕獲的錯誤:找不到模塊 '../common/languages/en'

                  更新

                      'use strict';
                  
                  var gulp = require('gulp');
                  var connect = require('gulp-connect');
                  var open = require('gulp-open');
                  var browserify = require('browserify');
                  var source = require('vinyl-source-stream');
                  var concat = require('gulp-concat');
                  var babelify = require('babelify');
                  var sass = require('gulp-sass');
                  var merge = require('merge-stream'); // Merge all styles (css, sass and less) in one big bundle
                  var lint = require("gulp-eslint");
                  
                  var config = {
                      port: 8001,
                      devBaseUrl: 'http://localhost',
                      paths: {
                          html: "./src/*.html",
                          externals: "./src/assets/externals/*.js",
                          js: "./src/**/*.js",
                          images: './src/assets/images/**/*',
                          fonts: './src/assets/css/fonts/*',
                          css: [
                              "./src/assets/css/*.css",
                              "./node_modules/toastr/package/toastr.css"
                          ],
                          sass: './src/assets/css/*.scss',
                          dist: "./dist",
                          mainJS: "./src/main.js"
                      }
                  };
                  
                  
                  gulp.task('connect', ['watch'], function () {
                      connect.server({
                          root: ['dist'],
                          port: config.port,
                          base: config.devBaseUrl,
                          livereload: true,
                          fallback: './dist/index.html'
                      })
                  });
                  
                  gulp.task('open', ['connect'], function () {
                      gulp.src('dist/index.html')
                          .pipe(open({uri: config.devBaseUrl + ":" + config.port + "/"}));
                  });
                  
                  
                  gulp.task('html', function () {
                      gulp.src(config.paths.html)
                          .pipe(gulp.dest(config.paths.dist))
                          .pipe(connect.reload());
                  });
                  
                  
                  gulp.task('externals', function () {
                      gulp.src(config.paths.externals)
                          .on('error', console.error.bind(console))
                          .pipe(concat('external.js'))
                          .pipe(gulp.dest(config.paths.dist + '/externals'))
                          .pipe(connect.reload());
                  });
                  
                  
                  gulp.task('js', function () {
                      browserify(config.paths.mainJS)
                          .transform('babelify', {presets: ['es2015', 'react']})
                          .bundle()
                          .on('error', console.error.bind(console))
                          .pipe(source('bundle.js'))
                          .pipe(gulp.dest(config.paths.dist + '/scripts'))
                          .pipe(connect.reload());
                  });
                  
                  
                  gulp.task('images', function () {
                      gulp.src(config.paths.images)
                          .pipe(gulp.dest(config.paths.dist + '/images'));
                  });
                  
                  
                  gulp.task('styles', function () {
                      var cssStyles = gulp.src(config.paths.css)
                          .pipe(concat('styles.css'));
                  
                      var sassStyles = gulp.src(config.paths.sass)
                          .pipe(sass())
                          .pipe(concat('styles.scss'));
                  
                      var mergedStream = merge(cssStyles, sassStyles)
                          .pipe(concat('bundle.css'))
                          .pipe(gulp.dest(config.paths.dist + '/css'))
                          .pipe(connect.reload());
                  
                      return mergedStream;
                  });
                  
                  gulp.task('fonts', function () {
                      gulp.src(config.paths.fonts)
                          .pipe(gulp.dest(config.paths.dist + '/css/fonts'));
                  });
                  
                  gulp.task('lint', function () {
                      return gulp.src(config.paths.js)
                          .pipe(lint())
                          .pipe(lint.format());
                  });
                  
                  
                  gulp.task('watch', function () {
                      gulp.watch(config.paths.html, ['html']);
                      gulp.watch(config.paths.js, ['js', 'lint']);
                      gulp.watch(config.paths.externals, ['externals', 'lint']);
                      gulp.watch([config.paths.css, config.paths.sass], ['styles']);
                      gulp.watch(config.paths.images, ['images']);
                  });
                  
                  gulp.task('default', ['html', 'js', 'styles', 'externals', 'images', 'fonts', 'lint', 'open', 'watch']);
                  

                  推薦答案

                  大部分 JS bundler 無法處理動態(tài) require 機制.嘗試加載所有語言并在運行時切換它們

                  Most of JS bundlers cannot handle dynamic require mechanism. Try to load all languages and switch them in runtime

                  let languages = {
                      en:  require('../common/languages/en'),
                      ru: require('../common/languages/ru'),
                      de: require('../common/languages/de')
                  }
                  const langCode = this.props.langCode; // en
                  let languageFile = languages[langCode];
                  

                  這篇關于在 React JS 中需要帶有變量的文件的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  Browserify, Babel 6, Gulp - Unexpected token on spread operator(Browserify,Babel 6,Gulp - 傳播運算符上的意外令牌)
                  Is it possible to pass a flag to Gulp to have it run tasks in different ways?(是否可以將標志傳遞給 Gulp 以使其以不同的方式運行任務?)
                  Why do we need to install gulp globally and locally?(為什么我們需要在全局和本地安裝 gulp?)
                  How to run Gulp tasks sequentially one after the other(如何一個接一個地依次運行 Gulp 任務)
                  Stylesheet not loaded because of MIME-type(由于 MIME 類型而未加載樣式表)
                  Visual Studio 2015 crashes when opening Javascript files(打開 Javascript 文件時 Visual Studio 2015 崩潰)
                  • <legend id='7g3gt'><style id='7g3gt'><dir id='7g3gt'><q id='7g3gt'></q></dir></style></legend>
                          <bdo id='7g3gt'></bdo><ul id='7g3gt'></ul>

                          <small id='7g3gt'></small><noframes id='7g3gt'>

                          <i id='7g3gt'><tr id='7g3gt'><dt id='7g3gt'><q id='7g3gt'><span id='7g3gt'><b id='7g3gt'><form id='7g3gt'><ins id='7g3gt'></ins><ul id='7g3gt'></ul><sub id='7g3gt'></sub></form><legend id='7g3gt'></legend><bdo id='7g3gt'><pre id='7g3gt'><center id='7g3gt'></center></pre></bdo></b><th id='7g3gt'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='7g3gt'><tfoot id='7g3gt'></tfoot><dl id='7g3gt'><fieldset id='7g3gt'></fieldset></dl></div>

                            <tfoot id='7g3gt'></tfoot>
                              <tbody id='7g3gt'></tbody>
                            主站蜘蛛池模板: 日韩黄色小视频 | 中国一级毛片免费 | 天天干在线播放 | 亚洲成人一区 | 亚洲精品观看 | 免费在线观看黄色av | 日韩国产一区 | 久久久久久久久久性 | 欧美精三区欧美精三区 | 91在线精品视频 | 免费av毛片 | 久久精品国产亚洲夜色av网站 | 2021狠狠干| 激情五月婷婷综合 | 91麻豆蜜桃一区二区三区 | 日韩精品成人免费观看视频 | 日韩二三区 | 日日骚视频| 欧美精品影院 | 午夜丰满少妇一级毛片 | 亚洲欧美日韩中文字幕一区二区三区 | 日韩免费视频一区二区 | 情侣酒店偷拍一区二区在线播放 | 日韩精品一区二区三区在线 | 欧美日韩在线一区二区 | 五月综合色啪 | 69xxx免费| 成人免费一区二区三区视频网站 | 国产免费一区二区 | 特级一级黄色片 | 99久久久久国产精品免费 | 精品国产一区二区三区性色av | 国产电影一区二区 | 亚洲成人av| 久久99精品久久久久久琪琪 | 91av大全 | 亚洲欧美日韩中文字幕一区二区三区 | 欧美视频精品 | 中文字幕视频在线 | 欧美一区在线视频 | 国产免费一区二区 |