【发布时间】:2016-12-18 15:26:33
【问题描述】:
尝试使用我的 angular/ionic 项目设置 webpack CSS 模块。是否可以将我的 CSS 模块类定义正确附加到外部模板而不是内联模板?
当我将模板硬编码到路由中时,它可以正常工作:
var styles = require('./css.css')
module.exports = function(ngModule) {
ngModule.config(function ($stateProvider, $urlRouterProvider) {
$stateProvider
.state('tab.two', {
url: '/two',
views: {
'module-two': {
template:`<ion-view view-title="Module Two"> <ion-content class="padding moduleTwo"> <h2 class="${styles.title}">Welcome to Module Two</h2> </ion-content> </ion-view>`,
controller: 'TwoCtrl'
}
}
})
})
}
有没有办法只需要我的模板进入
var styles = require('./css.css')
module.exports = function(ngModule) {
ngModule.config(function ($stateProvider, $urlRouterProvider) {
$stateProvider
.state('tab.two', {
url: '/two',
views: {
'module-two': {
template:require('./myTemplate.html'),
controller: 'TwoCtrl'
}
}
})
})
}
我想我可能需要对 webpack.config 进行不同的设置,但我不确定。
var webpack = require('webpack');
var path = require('path');
module.exports = {
entry: './index.js',
output: {
filename: 'bundle.js',
},
module: {
loaders: [
{test: /\.js$/, loader: "ng-annotate!babel", exclude: /node_modules/},
{test: /\.html$/, loader: "raw", exclude: /node_modules/},
{test: /\.json$/, loader: "json", exclude: /node_modules/},
{
test: /\.css$/,
loader: "style!css-loader?modules&localIdentName=[name]__[local]___[hash:base64:5]",
exclude: [
path.resolve(__dirname, 'node_modules')
]
}]
}
};
【问题讨论】: