I've setup webpack following Anglular(2).io guide, but didn't work, so I've found something online to add but still doesn't work and I'm still getting these errors (hundred of it) (after I run 'npm start'):
[default] /Users/username/Desktop/Angular2-app/node_modules/@types/core-js/index.d.ts:21:13
Duplicate identifier 'PropertyKey'
[default] /Users/username/Desktop/Angular2-app/node_modules/@types/core-js/index.d.ts:1513:4
Duplicate identifier 'export='.
The structure of my project is this below:
-/dist (empty)
-/nodule_modules
-/src
--/app
---/assets
---/components
---/services
---/shared
---/app.component.css
---/app.component.ts
---/app.module.ts
---/app.routing.ts
--/config
--/typings
--index.html
--main.ts
--polyfills.ts
--vendor
-favicon.ico
-packages.json
-tsconfig.json
-tslint.json
-typings.json
-webapck.config.js
tsconfig.json:
{
"compilerOptions": {
"target": "ES5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true,
"baseUrl": "./src"
},
"types": [
"hammerjs",
"jasmine",
"node",
"protractor",
"selenium-webdriver",
"source-map",
"uglify-js",
"webpack"
],
"exclude": [
"node_modules",
"dist"
],
"compileOnSave": false,
"buildOnSave": false
}
webpack.config.json:
module.exports = require('./src/config/webpack.dev.js');
helpers.js:
var path = require('path');
var _root = path.resolve(__dirname, '..');
function root(args) {
args = Array.prototype.slice.call(arguments, 0);
return path.join.apply(path, [_root].concat(args));
}
exports.root = root;
webpack.common.js:
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var helpers = require('./helpers');
module.exports = {
entry: {
'polyfills': './src/polyfills.ts',
'vendor': './src/vendor.ts',
'app': './src/main.ts'
},
resolve: {
extensions: ['', '.ts', '.js', '.json', '.css', '.scss', '.html']
},
module: {
loaders: [
{
test: /\.ts$/,
loaders: ['awesome-typescript-loader', 'angular2-template-loader'],
exclude: [/\.(spec|e2e)\.ts$/, /node_modules\/(?!(ng2-.+))/]
},
{
test: /\.html$/,
loader: 'html'
},
{
test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico)$/,
loader: 'file?name=assets/[name].[hash].[ext]'
},
{
test: /\.css$/,
exclude: helpers.root('src', 'app'),
loader: ExtractTextPlugin.extract('style', 'css?sourceMap')
},
{
test: /\.css$/,
include: helpers.root('src', 'app'),
loader: 'raw'
}
]
},
plugins: [
new webpack.optimize.CommonsChunkPlugin({
name: ['app', 'vendor', 'polyfills']
}),
new HtmlWebpackPlugin({
template: 'src/index.html'
})
]
};
webpack.dev.js:
var webpackMerge = require('webpack-merge');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var commonConfig = require('./webpack.common.js');
var helpers = require('./helpers');
module.exports = webpackMerge(commonConfig, {
devtool: 'cheap-module-eval-source-map',
output: {
path: helpers.root('dist'),
publicPath: 'http://localhost:4200/',
filename: '[name].js',
chunkFilename: '[id].chunk.js'
},
plugins: [
new ExtractTextPlugin('[name].css')
],
devServer: {
historyApiFallback: true,
stats: 'minimal'
}
});
polyfills:
import 'core-js/es6';
import 'core-js/es7/reflect';
require('zone.js/dist/zone');
if (process.env.ENV === 'production') {
// Production
} else {
// Development
Error['stackTraceLimit'] = Infinity;
require('zone.js/dist/long-stack-trace-zone');
}
main.ts:
// main entry point
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import {enableProdMode} from "@angular/core";
import { AppModule } from './app/app.module';
if ( process.env.ENV === 'production' ){
enableProdMode()
}
platformBrowserDynamic().bootstrapModule(AppModule);