I want to use css-loader with :local()
function in my dev-setup.
No error: import './sidebar.css';
it compiles without problem, but then I dont know how to access the local classnames inside my .tsx
file.
Error: import classNames from './sidebar.css';
Here I get: error TS2307: Cannot find module './sidebar.css'
Explaining my setup:
.tsx
files are compiled to commonjs modules via gulp-typescript (ES5)- commonjs modules are compiled & minified to JS via webpack
sidebar.tsx (gets imported in app.tsx
if that matters)
import classNames from './sidebar.css';
sidebar.css
.sl-sidebar {
background-color: yellow;
}
gulpfile.js
Gulp task compiling .tsx
files to commonJS modules (runs before webpack-task of course):
gulp.task('gui-tsx', function () {
return gulp.src(config.guiTsxPath + '**/*.tsx')
.pipe(ts({
jsx: 'react',
outDir: config.guiCompiledPath,
module: 'commonjs',
target: 'ES5'
}))
.pipe(gulp.dest(config.guiCompiledPath));
});
My gulp-webpack task:
gulp.task('gui-webpack', function () {
webpack({
bail: false,
debug: true,
entry: './' + config.guiCompiledPath + 'app.js',
output: {
filename: "gui.js",
path: './' + config.pubPath + 'js'
},
devtool: "#inline-source-map",
plugins: [
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
},
output: {
comments: false,
semicolons: true
},
sourceMap: true
})
],
module: {
loaders: [ {
test: /\.css$/,
loader: 'style-loader!css-loader?modules'
}]
}
}, function (err, stats) {
if (stats.compilation.errors.length > 0) {
console.log(stats.compilation.errors[0].message);
}
});
});
What am I doing wrong?
Edit: I just found this: https://github.com/Microsoft/TypeScript/issues/2709 but I dont quite understand it. Does it mean I have to declare my CSS as a module?