Created
October 3, 2019 14:42
-
-
Save tanhauhau/bb9e1ec66ba53d06832ad4ac48c90aa5 to your computer and use it in GitHub Desktop.
Declarative webpack config
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const FILE_TYPES = { | |
JS: /\.js$/, | |
CSS: /\.css$/, | |
SCSS: /\.scss$/, | |
TS: /\.tsx?$/, | |
}; | |
const FOLDERS = { | |
APP: path.join(__dirname, './src'), | |
NODE_MODULES: path.join(__dirname, './node_modules'), | |
}; | |
matchFileType(FILE_TYPES.JS, 'js files', () => { | |
matchFolder(FOLDERS.APP, 'js files in app', () => { | |
production(() => { | |
declareLoader('loader for js files in app', () => { | |
return { | |
loader: 'babel-loader', | |
options: {}, | |
}; | |
}); | |
declarePlugin('plugin for js files in app', () => { | |
return [ | |
new HappyPackPlugin({}), | |
]; | |
}); | |
}); | |
development(() => { | |
declareLoader('loader for js files in app', () => { | |
return { | |
loader: 'babel-loader', | |
options: {}, | |
} | |
}); | |
}); | |
}); | |
matchFolder(FOLDERS.NODE_MODULES, 'js files in node_modules', () => { | |
allEnv(() => { | |
declareLoader('loader for js files in node_modules', () => { | |
return { | |
loader: 'babel-loader', | |
options: {}, | |
} | |
}); | |
}); | |
}); | |
}); | |
matchFileType(FILE_TYPES.CSS, 'css files', () => { | |
allFolder(() => { | |
allEnv(() => { | |
declareLoader('loader for js files in node_modules', () => { | |
return { | |
loader: 'css-loader', | |
options: {}, | |
} | |
}); | |
}); | |
}); | |
}); | |
// can use label to set which loader/plugin should come before another | |
definePriority('loader for js files in app', 'js files in app'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment