Search code examples
angularnpmwebpacklocalizationwebpack-2

Webpack build not including resources/json files


My Webpack build is not including my resources folder into the dist build, which is causing my translation files to never get picked up and therefore no translation is taking place...

File structure:

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')
     ]
 };

I'm using Webpack v2.5.1. Anybody know what I'm missing here? It's my understanding I should not have to include any json loader in Webpack version 2.0+

Do I need to import my files from the resources folder somewhere?


Solution

  • Webpack only considers the files explicitly imported/required by your code.

    If you just want to move some files into your build directory, have a look to this answer on how to set up copy-webpack-plugin.