Create CSS typings before build. Fixes #251. (#350)

* Create CSS typings before build

* Let's try this.

* Adding comment

* Remove hack from travis
This commit is contained in:
Jake Archibald
2018-11-28 16:09:08 +00:00
committed by GitHub
parent 32f2b4e573
commit 428b7d976d
6 changed files with 386 additions and 52 deletions

View File

@@ -15,6 +15,7 @@ const WorkerPlugin = require('worker-plugin');
const AutoSWPlugin = require('./config/auto-sw-plugin');
const CrittersPlugin = require('critters-webpack-plugin');
const AssetTemplatePlugin = require('./config/asset-template-plugin');
const addCssTypes = require('./config/add-css-types');
function readJson (filename) {
return JSON.parse(fs.readFileSync(filename));
@@ -22,7 +23,7 @@ function readJson (filename) {
const VERSION = readJson('./package.json').version;
module.exports = function (_, env) {
module.exports = async function (_, env) {
const isProd = env.mode === 'production';
const nodeModules = path.join(__dirname, 'node_modules');
const componentStyleDirs = [
@@ -32,6 +33,8 @@ module.exports = function (_, env) {
path.join(__dirname, 'src/lib'),
];
await addCssTypes(componentStyleDirs, { watch: !isProd });
return {
mode: isProd ? 'production' : 'development',
entry: {
@@ -109,9 +112,7 @@ module.exports = function (_, env) {
// In production, CSS is extracted to files on disk. In development, it's inlined into JS:
isProd ? MiniCssExtractPlugin.loader : 'style-loader',
{
// This is a fork of css-loader that auto-generates .d.ts files for CSS module imports.
// The result is a definition file with the exported String classname mappings.
loader: 'typings-for-css-modules-loader',
loader: 'css-loader',
options: {
modules: true,
localIdentName: isProd ? '[hash:base64:5]' : '[local]__[hash:base64:5]',