2016-05-05 24 views
9

io continuo il mio server & codice del client nello stesso repository, anche se io uso Webpack a costruire solo il client:Perché Webpack non include una cartella che ho specificato?

enter image description here

Il mio progetto si basa bene se cancello la cartella src/server. Ma quando è lì ricevo tutti questi errori duplicato definizione Webpack tipografico come:

[1m[31mERROR in /home/rje/projects/ekaya/typings/main/ambient/react-dom/index.d.ts 
(70,5): error TS2300: Duplicate identifier 'export='. 

che sono causati da Webpack cercando di costruire uno dei file nella cartella del server che contiene:

/// <reference path="../../../../typings/main.d.ts" /> 

Come posso ottenere che Webpack ignori completamente la cartella del server?

ho provato nei miei webpack.config.js:

var rootPath = __dirname; 
var srcPath = path.join(rootPath, 'src/client'); 
var distPath = path.join(rootPath, 'dist/client'); 
var serverPath = path.join(rootPath, 'src/serve 
... 
loaders: 
     [ 
      {test: /\.js$/, loader: 'babel-loader?cacheDirectory', include: [srcPath], exclude: [serverPath]}, 
      {test: /\.jsx$/, loader: 'babel-loader?cacheDirectory', include: [srcPath], exclude: [serverPath] }, 
      {test: /\.ts$/, loader: 'ts-loader?cacheDirectory', include: [srcPath], exclude: [serverPath] }, 
      {test: /\.tsx$/, loader: 'ts-loader?cacheDirectory', include: [srcPath], exclude: [serverPath] }, 

Ecco il webpack configurazione completa se aiuta:

//https://webpack.github.io/docs/configuration.html 

var webpack = require('webpack'); 
var HtmlWebpackPlugin = require('html-webpack-plugin'); 
var CopyWebpackPlugin = require('copy-webpack-plugin'); 
var path = require('path'); 
var rootPath = __dirname; // e.g. ~/projects/ekaya 
var srcPath = path.join(rootPath, 'src/client'); 
var distPath = path.join(rootPath, 'dist/client'); 
var serverPath = path.join(rootPath, 'src/server'); 

module.exports = 
{ 
    bail: true, 
    cache: false, 
    context: rootPath, 
    debug: true, 
    devtool: 'source-map', //inline-source-map, https://webpack.github.io/docs/configuration.html#devtool 
    target: 'web', //node, web 
    devServer: 
    { 
     contentBase: distPath, 
     historyApiFallback: true, 
     outputPath: path.join(distPath, 'devServer') 
    }, 
    entry: 
    { 
     app: path.join(srcPath, 'app/home.jsx'), 
     lib: ['react', 'react-router', 'react-dom', 'jquery', 'lodash', 'history'] 
    }, 
    output: 
    { 
     path: distPath, 
     publicPath: '', 
     filename: '[name].js', 
     pathInfo: true 
    }, 
    resolve: 
    { 
     root: srcPath, 
     extensions: ['', '.js', '.jsx', '.ts', '.tsx'], 
     modulesDirectories: ['node_modules', srcPath, 'typings'] 
    }, 
    module: 
    { 
     loaders: 
     [ 
      {test: /\.js$/, loader: 'babel-loader?cacheDirectory', include: [srcPath], exclude: [serverPath]}, 
      {test: /\.jsx$/, loader: 'babel-loader?cacheDirectory', include: [srcPath], exclude: [serverPath] }, 
      {test: /\.ts$/, loader: 'ts-loader?cacheDirectory', include: [srcPath], exclude: [serverPath] }, 
      {test: /\.tsx$/, loader: 'ts-loader?cacheDirectory', include: [srcPath], exclude: [serverPath] }, 
      {test: /\.scss$/, loaders: ['style', 'css', 'sass']}, 
      {test: /\.png$/, loader: 'file-loader'}, 
      {test: /\.jpg$/, loader: 'file-loader'}, 
      {test: /\.jpeg$/, loader: 'file-loader'}, 
      {test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, loader: 'file-loader?mimetype=image/svg+xml'}, 
      {test: /\.woff(\?v=\d+\.\d+\.\d+)?$/, loader: "file-loader?mimetype=application/font-woff"}, 
      {test: /\.woff2(\?v=\d+\.\d+\.\d+)?$/, loader: "file-loader?mimetype=application/font-woff"}, 
      {test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/, loader: "file-loader?mimetype=application/octet-stream"}, 
      {test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, loader: "file-loader"} 
     ] 
    }, 
    plugins: 
    [ 
     new CopyWebpackPlugin 
     ([ 
      { from: path.join(srcPath, 'images'), to: 'images' } 
     ]), 
     new webpack.optimize.CommonsChunkPlugin('lib', 'lib.js'), 
     new HtmlWebpackPlugin 
     ({ 
      inject: true, 
      template: path.join(srcPath, 'index.html') 
     }), 
     new webpack.NoErrorsPlugin() 
    ] 
}; 
+0

hai mai risolto questo? – superjos

+0

No, penso che alla fine ho dovuto spostare tutto in cartelle separate, cioè mettere la configurazione webpback nella cartella client – Richard

+0

Grazie. Durante il tentativo di superare un problema di build, ho notato che l'inclusione/esclusione sembra essere più influenzata dall'espressione che dalla stringa del percorso assoluto. Potrebbe essere qualcosa che stavo facendo male, ma potrebbe valere la pena provare che in una prossima occasione – superjos

risposta

6

Hai provato escludendo la cartella nel vostro tsconfig.json?

{ 
    "compilerOptions": { 
    "target": "es5", 
    "module": "commonjs", 
    ... 
    }, 
    "exclude": [ 
    "src/server", 
    "node_modules" 
    ] 
} 
+0

ha avuto 40 errori, ora ho 2000, quindi chiaramente non funziona, qualcuno ha una soluzione per questo? – ninja

+0

Saaame qui. Exclude ha tutte le definizioni per l'esclusione, ma webpack/ts-loader sta ancora cercando di compilare le cose all'interno di node_modules. –