我的应用程序的生产和开发环境有单独的文件,我的开发环境工作正常,我没有得到如何在webpack中使用我的静态资产并在应用程序中使用它们,它们可以直接在我的html中访问和css文件如下所示
authentication.component.html
root folder
->admin
=>uploads//(images need to saved)
-> API
=>V1
->user.php(//here is my file upload code)
authentication.component.css
<img src="/assets/images/myimage.png" />
这是我项目的目录结构
和我的webpack配置文件
通用
@font-face {
font-family: "untitled-font-5";
src:url("/assets/fonts/untitled-font-5.eot");
src:url("/assets/fonts/untitled-font-5.eot?#iefix") format("embedded-opentype"),
url("/assets/fonts/untitled-font-5.woff") format("woff"),
url("/assets/fonts/untitled-font-5.ttf") format("truetype"),
url("/assets/fonts/untitled-font-5.svg#untitled-font-5") format("svg");
font-weight: normal;
font-style: normal;
}
dev的
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var helpers = require('./helpers');
module.exports = {
entry: {
'vendor': './src/vendor.ts',
'app': './src/app/main.ts'
},
resolve: {
extensions: ['', '.ts', '.js']
},
module: {
loaders: [
{
test: /\.ts$/,
loaders: ['awesome-typescript-loader', 'angular2-template-loader']
},
{
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']
}),
new HtmlWebpackPlugin({
template: 'src/index.html'
}),
new webpack.ProvidePlugin({
jQuery: 'jquery',
$: 'jquery',
jquery: 'jquery',
"window.jQuery": "jquery"
})
]
};
刺
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:3000/',
filename: '[name].js',
chunkFilename: '[id].chunk.js'
},
plugins: [
new ExtractTextPlugin('[name].css')
],
devServer: {
historyApiFallback: true,
stats: 'minimal'
}
});