mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
75de0fa5fa
support windows path remove unused hammerjs hack remove unused 'style/css' resolver
58 lines
1.3 KiB
JavaScript
58 lines
1.3 KiB
JavaScript
const path = require('path')
|
|
const fs = require('fs')
|
|
const requireHacker = require('require-hacker')
|
|
|
|
function setupRequireHacker () {
|
|
const webjs = '.web.js'
|
|
const webModules = ['antd-mobile', 'rmc-picker'].map(m => path.join('node_modules', m))
|
|
|
|
requireHacker.hook('js', filename => {
|
|
if (filename.endsWith(webjs) || webModules.every(p => !filename.includes(p))) return
|
|
|
|
const webFilename = filename.replace(/\.js$/, webjs)
|
|
if (!fs.existsSync(webFilename)) return
|
|
|
|
return fs.readFileSync(webFilename, { encoding: 'utf8' })
|
|
})
|
|
|
|
requireHacker.hook('svg', filename => {
|
|
return requireHacker.to_javascript_module_source(`#${path.parse(filename).name}`)
|
|
})
|
|
}
|
|
|
|
setupRequireHacker()
|
|
|
|
function moduleDir (m) {
|
|
return path.dirname(require.resolve(`${m}/package.json`))
|
|
}
|
|
|
|
module.exports = {
|
|
webpack: (config, { dev }) => {
|
|
config.resolve.extensions = ['.web.js', '.js', '.json']
|
|
|
|
config.module.rules.push(
|
|
{
|
|
test: /\.(svg)$/i,
|
|
loader: 'emit-file-loader',
|
|
options: {
|
|
name: 'dist/[path][name].[ext]'
|
|
},
|
|
include: [
|
|
moduleDir('antd-mobile'),
|
|
__dirname
|
|
]
|
|
},
|
|
{
|
|
test: /\.(svg)$/i,
|
|
loader: 'svg-sprite-loader',
|
|
include: [
|
|
moduleDir('antd-mobile'),
|
|
__dirname
|
|
]
|
|
}
|
|
)
|
|
|
|
return config
|
|
}
|
|
}
|