각도 + typescript + webpack 응용 프로그램을 빌드하려고합니다. 나는 this을 출처로 사용하고 나의 요구 사항에 따라 수정했다.Webpack : 예기치 않은 토큰 : webpack.config.ts
이 내 webpack.config.ts입니다 :
const {
optimize: {
CommonsChunkPlugin,
DedupePlugin
}
} = require('webpack');
const { ConcatSource } = require('webpack-sources');
const { TsConfigPathsPlugin } = require('awesome-typescript-loader');
const AssetsPlugin = require('assets-webpack-plugin');
const path = require('path');
const fs = require('fs');
function root(__path = '.') {
return path.join(__dirname, __path);
}
// type definition for WebpackConfig is defined in webpack.d.ts
function webpackConfig(options: EnvOptions = {}): WebpackConfig {
const CONSTANTS = {
ENV: JSON.stringify(options.ENV),
PORT: 3000,
HOST: 'localhost',
HTTPS: false
};
const isProd = options.ENV.indexOf('prod') !== -1;
return {
cache: true,
devtool: 'source-map',
entry: {
main: './src/index'
},
output: {
path: root('dist'),
filename: '[name].bundle.js',
sourceMapFilename: '[name].map',
},
module: {
loaders: [
{
test: /\.ts$/,
loader: 'awesome-typescript-loader',
exclude: [/\.(spec|e2e|d)\.ts$/],
include: [root('../src')]
},
{ test: /\.json$/, loader: 'json-loader', include: [root('../src')] }
]
},
plugins: [
new AssetsPlugin({
path: root('dist'),
filename: 'webpack-assets.json',
prettyPrint: true
}),
new TsConfigPathsPlugin(/* { tsconfig, compiler } */)
],
resolve: {
extensions: ['.ts', '.js', '.json']
},
node: {
global: true,
process: true,
Buffer: false,
crypto: 'empty',
module: false,
clearImmediate: false,
setImmediate: false,
clearTimeout: true,
setTimeout: true
}
};
}
// Export
module.exports = webpackConfig;
내가 $> webpack --config webpack.config.ts
나는 다음과 같은 오류를 얻고을 실행
$ webpack --config ./configs/webpack.config.ts
PathToProject\WebStorageManager\configs\webpack.config.ts:19
function webpackConfig(options: EnvOptions = {}): WebpackConfig {
^
SyntaxError: Unexpected token :
at Object.exports.runInThisContext (vm.js:76:16)
일부 웹팩 구성을 놓치셨습니까?
그렇다면 어떻게하면 [webpack.config.ts] 파일로 [this] (https://github.com/AngularClass/angular2-seed) 프로젝트를 만들 수 있습니까? – Thaadikkaaran
한 가지 방법은 tsc를 실행하는 것입니다. 수동으로 결과 .js 파일을로드하십시오. ts-node를 사용하여 잠재적 인 또 다른 방법을 포함하도록 답변을 업데이트했습니다. 이 옵션은 당신이 찾고있는 것 같습니다. – dtabuenc
그게 효과가! 업데이트 된 답변에 대해 이야기하는 의사가 있습니까? – Thaadikkaaran