【问题标题】:Webpack build not including resources/json filesWebpack 构建不包括资源/json 文件
【发布时间】:2017-10-31 14:25:57
【问题描述】:

我的 Webpack 构建未将我的资源文件夹包含到 dist 构建中,这导致我的翻译文件永远不会被拾取,因此没有进行任何翻译...

文件结构:

dist
   //I need my json files from src/resources here
src
  app // holds all components
  resources 
      locale-en-us.json
      locale-fr-fr-json
      locale-ru-ru.json
      locale-zh-cn-json
webpack
    webpack.common.js
    webpack.server.js

weback.server.js:

const { root } = require('./helpers');

const { AotPlugin } = require('@ngtools/webpack');

module.exports = {
    entry: root('./src/main.server.ts'),
    output: {
         filename: 'server.js'
     },
    target: 'node'
};

webpack.common.js

 const { root } = require('./helpers');

 const ExtractTextPlugin = require("extract-text-webpack-plugin");

 /**
   * This is a common webpack config which is the base for all builds
 */
  module.exports = {
      devtool: 'cheap-module-source-map',
      resolve: {
        extensions: ['.ts', '.js']
       },
      output: {
       path: root('dist')
       },
      module: {
        rules: [
         { test: /\.ts$/, loader: '@ngtools/webpack' },      
         { test: /\.html$/, loader: 'raw-loader' },
         { test: /\.less$/, loader: ExtractTextPlugin.extract({ fallback: 'style-loader', use: 'css-loader?sourceMap!less-loader?sourceMap' }) },
         { test: /\.scss$/, loader: ExtractTextPlugin.extract({ fallback: 'style-loader', use: 'css-loader?sourceMap!sass-loader?sourceMap' }) },
         { test: /\.css$/, loader: ExtractTextPlugin.extract({ fallback: 'style-loader', use: 'css-loader?sourceMap' }) },
         { test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: 'url-loader?limit=8192&minetype=application/font-woff&name=fonts/[name].[hash].[ext]' },
         { test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: 'file-loader?name=fonts/[name].[hash].[ext]' },
         { test: /\.(jpg|jpeg|png|gif)(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: 'url-loader?limit=4096&name=images/[name].[hash].[ext]' }
        ]
     },
     plugins: [
        new ExtractTextPlugin('[name].css')
     ]
 };

我正在使用 Webpack v2.5.1。有人知道我在这里缺少什么吗?据我了解,我不应该在 Webpack 2.0+ 版中包含任何 json 加载器

我需要从某处的资源文件夹中导入我的文件吗?

【问题讨论】:

    标签: angular npm webpack localization webpack-2


    【解决方案1】:

    Webpack 仅考虑您的代码明确导入/需要的文件。

    如果您只想将一些文件移动到您的构建目录中,请查看this answer,了解如何设置copy-webpack-plugin

    【讨论】:

    • 感谢您的帮助!
    猜你喜欢
    • 2019-04-12
    • 2016-12-08
    • 2023-04-01
    • 2019-05-14
    • 2018-06-27
    • 1970-01-01
    • 1970-01-01
    • 2013-05-07
    • 1970-01-01
    相关资源
    最近更新 更多