mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-02 19:57:25 +02:00
feat: simple webpack config
This commit is contained in:
parent
e85d3230a9
commit
e64a06c748
3 changed files with 70 additions and 0 deletions
48
lib/webpack/config/base.js
Normal file
48
lib/webpack/config/base.js
Normal file
|
@ -0,0 +1,48 @@
|
|||
const Config = require('webpack-chain');
|
||||
const path = require('path');
|
||||
|
||||
module.exports = function createBaseConfig(props) {
|
||||
const {outDir, themePath, siteDir, baseUrl} = props;
|
||||
|
||||
const config = new Config();
|
||||
const isProd = process.env.NODE_ENV === 'production';
|
||||
|
||||
config
|
||||
.mode(isProd ? 'production' : 'development')
|
||||
.output.path(outDir)
|
||||
.filename(
|
||||
isProd ? 'static/js/[name].[chunkhash].js' : 'static/js/[name].js'
|
||||
)
|
||||
.publicPath(isProd ? baseUrl : '/');
|
||||
|
||||
config.resolve
|
||||
.set('symlinks', true)
|
||||
.alias.set('@theme', themePath)
|
||||
.set('@site', siteDir)
|
||||
.set('@generated', path.resolve(__dirname, '../core/generated'))
|
||||
.set('@core', path.resolve(__dirname, '../core'))
|
||||
.end();
|
||||
|
||||
const libDir = path.join(__dirname, '..');
|
||||
config.module
|
||||
.rule('js')
|
||||
.test(/\.js$/)
|
||||
.exclude.add(filepath => {
|
||||
// Always transpile lib directory
|
||||
if (filepath.startsWith(libDir)) {
|
||||
return false;
|
||||
}
|
||||
// Don't transpile node_modules
|
||||
return /node_modules/.test(filepath);
|
||||
})
|
||||
.end()
|
||||
.use('babel')
|
||||
.loader('babel-loader')
|
||||
.options({
|
||||
// do not pick local project babel config
|
||||
babelrc: false,
|
||||
presets: ['env', 'react']
|
||||
});
|
||||
|
||||
return config;
|
||||
};
|
10
lib/webpack/config/dev.js
Normal file
10
lib/webpack/config/dev.js
Normal file
|
@ -0,0 +1,10 @@
|
|||
const path = require('path');
|
||||
const createBaseConfig = require('./base');
|
||||
|
||||
module.exports = function createDevConfig(props) {
|
||||
const config = createBaseConfig(props);
|
||||
|
||||
config.entry('main').add(path.resolve(__dirname, '../core/devEntry.js'));
|
||||
|
||||
return config;
|
||||
};
|
12
lib/webpack/config/prod.js
Normal file
12
lib/webpack/config/prod.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
const path = require('path');
|
||||
const createBaseConfig = require('./base');
|
||||
|
||||
module.exports = function createProdConfig(props) {
|
||||
const config = createBaseConfig(props);
|
||||
|
||||
config.entry('main').add(path.resolve(__dirname, '../core/prodEntry.js'));
|
||||
|
||||
// TODO
|
||||
|
||||
return config;
|
||||
};
|
Loading…
Add table
Reference in a new issue