2017-01-16 7 views
0

typescript 관련 .tsx 파일을 컴파일하는 데 webpack을 사용하고 jsxES2015/stage-0 구문을 사용합니다.webpack을 통해 tsconfig.json에서 sourceMap 옵션을 동적으로 만드는 방법은 무엇입니까?

var PATHS = { 
    "build": path.join(__dirname, 'build'), 
    "myModule1": path.join(__dirname, 'js', 'module1'), 
    "myModule2": path.join(__dirname, 'js', 'module2') 
} 

var scriptIncludes = [PATHS.myModule1, 
         PATHS.myModule2] 

module.exports = { 
    entry: { 
     "my-module1": path.join(PATHS.myModule1, 'index.jsx'), 
     "my-module2": path.join(PATHS.myModule2, 'index.tsx') 
    }, 
    output: { 
     filename: '[name].js', 
     sourceMapFilename: '[name].js.map', 
     path: PATHS.build 
    }, 

    // Enable sourcemaps for debugging webpack's output. 
    devtool: "source-map", 

    resolve: { 
     // resolvable extensions. 
     // Files with the following extensions are fair game for webpack to process. 
     extensions: ['', ".webpack.js", ".web.js", ".ts", ".tsx", ".js", ".jsx"], 
     alias: { 
      'ie': 'component-ie' 
     } 
    }, 
    plugins: [], //plugins, 
    module: { 
     loaders: [ 
     { 
      test: /\.js*/, 
      include: scriptIncludes, 
      loader: "babel-loader", query: { presets: ['react', 'es2015', 'stage-0'] } 
     }, 
     { 
      // The loader that handles ts and tsx files. These are compiled 
      // with the awesome-typescript-loader and the output is then passed through to the 
      // babel-loader. The babel-loader uses the es2015, react and stage-0 presets 
      // in order that jsx and es6 are processed. 
      // Note that order of loader processing is from right to left. 
      test: /\.ts(x?)$/, 
      include: scriptIncludes, 
      loader: 'babel-loader?presets[]=es2015&presets[]=react&presets[]=stage-0!awesome-typescript-loader' 
     }], 
     preLoaders: [ 
      // All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'. 
      { test: /\.js$/, loader: "source-map-loader" } 
     ] 
    }, 

    // When importing a module whose path matches one of the following, just 
    // assume a corresponding global variable exists and use that instead. 
    // This is important because it allows us to avoid bundling all of our 
    // dependencies, which allows browsers to cache those libraries between builds. 
    externals: { 
     "react": "React", 
     "react-dom": "ReactDOM" 
    }, 
}; 

tsconfig.json 파일은 다음과 같다 :

{ 
    "compilerOptions": { 
    "outDir": "./build/", 
    "module": "commonjs", 
    "target": "es5", 
    "noImplicitAny": false, 
    "sourceMap": true, 
    "jsx": "react" 
    }, 
    "exclude": [ 
    "node_modules" 
    ] 
} 

을 지금 :

  1. 내가 진정한 tsconfig.jsonsourceMap 옵션을 설정하면, 다음과 같이

    webpack.config.js 파일입니다 오직 소스 맵이 생성됩니다. 나는 동적으로 만들려는 명령 행 인자를 기반으로하고, 매번 하드 코드를 사용하지 않고 tsconfig.json 파일을 사용한다. 어떻게하면됩니까?

  2. 또한 웹 팩 구성에서 preLoaders 옵션을 언급하면 ​​어떤 차이가 있습니까?

답변

2

당신은 로더 쿼리 문자열 내부 컴파일러 옵션을 전달할 수

예를 들어

멋진-타이프 라이터 로더? sourceMap = 명령 행 지원에 대한

+0

거짓 당신이 뭔가를 할 수 > awesome-typescript-loader? sourceMap = process.env.TS_SOURCEMAPS > [내보내기 | 설정] TS_SOURCEMAPS = true && webpack을 사용하여 빌드하십시오. –