webpacker-jets 3.2.100
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.eslintignore +4 -0
- data/.eslintrc.js +14 -0
- data/.gitignore +6 -0
- data/.rubocop.yml +124 -0
- data/.travis.yml +32 -0
- data/CHANGELOG.md +523 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +154 -0
- data/MIT-LICENSE +20 -0
- data/README.md +445 -0
- data/Rakefile +12 -0
- data/docs/assets.md +106 -0
- data/docs/cloud9.md +310 -0
- data/docs/css.md +116 -0
- data/docs/deployment.md +74 -0
- data/docs/docker.md +49 -0
- data/docs/env.md +65 -0
- data/docs/es6.md +53 -0
- data/docs/folder-structure.md +66 -0
- data/docs/misc.md +23 -0
- data/docs/props.md +223 -0
- data/docs/testing.md +128 -0
- data/docs/troubleshooting.md +119 -0
- data/docs/typescript.md +116 -0
- data/docs/webpack-dev-server.md +92 -0
- data/docs/webpack.md +297 -0
- data/docs/yarn.md +12 -0
- data/exe/webpack +8 -0
- data/exe/webpack-dev-server +8 -0
- data/gemfiles/Gemfile-rails-edge +13 -0
- data/gemfiles/Gemfile-rails.4.2.x +10 -0
- data/gemfiles/Gemfile-rails.5.0.x +10 -0
- data/gemfiles/Gemfile-rails.5.1.x +10 -0
- data/lib/install/angular.rb +27 -0
- data/lib/install/coffee.rb +22 -0
- data/lib/install/config/.babelrc +18 -0
- data/lib/install/config/.postcssrc.yml +3 -0
- data/lib/install/config/webpack/development.js +3 -0
- data/lib/install/config/webpack/environment.js +3 -0
- data/lib/install/config/webpack/production.js +3 -0
- data/lib/install/config/webpack/staging.js +3 -0
- data/lib/install/config/webpack/test.js +3 -0
- data/lib/install/config/webpacker.yml +79 -0
- data/lib/install/elm.rb +38 -0
- data/lib/install/erb.rb +22 -0
- data/lib/install/examples/angular/hello_angular.js +7 -0
- data/lib/install/examples/angular/hello_angular/app/app.component.ts +9 -0
- data/lib/install/examples/angular/hello_angular/app/app.module.ts +16 -0
- data/lib/install/examples/angular/hello_angular/index.ts +8 -0
- data/lib/install/examples/angular/hello_angular/polyfills.ts +73 -0
- data/lib/install/examples/angular/tsconfig.json +19 -0
- data/lib/install/examples/coffee/hello_coffee.coffee +4 -0
- data/lib/install/examples/elm/Main.elm +54 -0
- data/lib/install/examples/elm/hello_elm.js +12 -0
- data/lib/install/examples/erb/hello_erb.js.erb +6 -0
- data/lib/install/examples/react/.babelrc +6 -0
- data/lib/install/examples/react/hello_react.jsx +26 -0
- data/lib/install/examples/vue/app.vue +22 -0
- data/lib/install/examples/vue/hello_vue.js +70 -0
- data/lib/install/javascript/packs/application.js +10 -0
- data/lib/install/loaders/coffee.js +6 -0
- data/lib/install/loaders/elm.js +23 -0
- data/lib/install/loaders/erb.js +11 -0
- data/lib/install/loaders/typescript.js +6 -0
- data/lib/install/loaders/vue.js +13 -0
- data/lib/install/react.rb +28 -0
- data/lib/install/template.rb +37 -0
- data/lib/install/vue.rb +26 -0
- data/lib/tasks/installers.rake +24 -0
- data/lib/tasks/webpacker.rake +22 -0
- data/lib/tasks/webpacker/check_binstubs.rake +12 -0
- data/lib/tasks/webpacker/check_node.rake +24 -0
- data/lib/tasks/webpacker/check_yarn.rake +24 -0
- data/lib/tasks/webpacker/clobber.rake +16 -0
- data/lib/tasks/webpacker/compile.rake +41 -0
- data/lib/tasks/webpacker/install.rake +13 -0
- data/lib/tasks/webpacker/verify_install.rake +16 -0
- data/lib/tasks/webpacker/yarn_install.rake +6 -0
- data/lib/webpacker.rb +32 -0
- data/lib/webpacker/commands.rb +23 -0
- data/lib/webpacker/compiler.rb +88 -0
- data/lib/webpacker/configuration.rb +87 -0
- data/lib/webpacker/dev_server.rb +61 -0
- data/lib/webpacker/dev_server_proxy.rb +26 -0
- data/lib/webpacker/dev_server_runner.rb +51 -0
- data/lib/webpacker/helper.rb +66 -0
- data/lib/webpacker/instance.rb +44 -0
- data/lib/webpacker/manifest.rb +75 -0
- data/lib/webpacker/railtie.rb +82 -0
- data/lib/webpacker/rake_tasks.rb +6 -0
- data/lib/webpacker/runner.rb +22 -0
- data/lib/webpacker/version.rb +9 -0
- data/lib/webpacker/webpack_runner.rb +15 -0
- data/package.json +67 -0
- data/package/__tests__/environment.js +74 -0
- data/package/config.js +34 -0
- data/package/config_types/__tests__/config_list.js +123 -0
- data/package/config_types/__tests__/config_object.js +43 -0
- data/package/config_types/config_list.js +85 -0
- data/package/config_types/config_object.js +55 -0
- data/package/config_types/index.js +7 -0
- data/package/environment.js +116 -0
- data/package/environments/development.js +46 -0
- data/package/environments/production.js +37 -0
- data/package/environments/test.js +3 -0
- data/package/index.js +20 -0
- data/package/rules/babel.js +13 -0
- data/package/rules/css.js +39 -0
- data/package/rules/file.js +13 -0
- data/package/rules/index.js +11 -0
- data/package/rules/sass.js +15 -0
- data/package/utils/__tests__/deep_assign.js +11 -0
- data/package/utils/__tests__/deep_merge.js +10 -0
- data/package/utils/__tests__/objectify.js +9 -0
- data/package/utils/deep_assign.js +22 -0
- data/package/utils/deep_merge.js +23 -0
- data/package/utils/helpers.js +32 -0
- data/package/utils/objectify.js +4 -0
- data/test/command_test.rb +27 -0
- data/test/compiler_test.rb +35 -0
- data/test/configuration_test.rb +69 -0
- data/test/dev_server_test.rb +24 -0
- data/test/helper_test.rb +52 -0
- data/test/manifest_test.rb +28 -0
- data/test/rake_tasks_test.rb +29 -0
- data/test/test_app/Rakefile +3 -0
- data/test/test_app/app/javascript/packs/application.js +10 -0
- data/test/test_app/config/application.rb +11 -0
- data/test/test_app/config/environment.rb +4 -0
- data/test/test_app/config/webpacker.yml +65 -0
- data/test/test_app/public/packs/manifest.json +6 -0
- data/test/test_helper.rb +29 -0
- data/webpacker-jets.gemspec +29 -0
- data/yarn.lock +5768 -0
- metadata +250 -0
@@ -0,0 +1,43 @@
|
|
1
|
+
/* global test expect */
|
2
|
+
|
3
|
+
const ConfigObject = require('../config_object')
|
4
|
+
|
5
|
+
test('new', () => {
|
6
|
+
const object = new ConfigObject()
|
7
|
+
expect(object).toBeInstanceOf(ConfigObject)
|
8
|
+
expect(object).toBeInstanceOf(Object)
|
9
|
+
})
|
10
|
+
|
11
|
+
test('set', () => {
|
12
|
+
const object = new ConfigObject()
|
13
|
+
expect(object.set('key', 'value')).toEqual({ key: 'value' })
|
14
|
+
})
|
15
|
+
|
16
|
+
test('get', () => {
|
17
|
+
const object = new ConfigObject()
|
18
|
+
object.set('key', 'value')
|
19
|
+
object.set('key1', 'value1')
|
20
|
+
expect(object.get('key')).toEqual('value')
|
21
|
+
})
|
22
|
+
|
23
|
+
test('delete', () => {
|
24
|
+
const object = new ConfigObject()
|
25
|
+
object.set('key', { key1: 'value' })
|
26
|
+
expect(object.delete('key.key1')).toEqual({ key: {} })
|
27
|
+
expect(object.delete('key')).toEqual({})
|
28
|
+
})
|
29
|
+
|
30
|
+
test('toObject', () => {
|
31
|
+
const object = new ConfigObject()
|
32
|
+
object.set('key', 'value')
|
33
|
+
object.set('key1', 'value1')
|
34
|
+
expect(object.toObject()).toEqual({ key: 'value', key1: 'value1' })
|
35
|
+
})
|
36
|
+
|
37
|
+
test('merge', () => {
|
38
|
+
const object = new ConfigObject()
|
39
|
+
object.set('foo', {})
|
40
|
+
expect(object.merge({ key: 'foo', value: 'bar' })).toEqual(
|
41
|
+
{ foo: {}, key: 'foo', value: 'bar' }
|
42
|
+
)
|
43
|
+
})
|
@@ -0,0 +1,85 @@
|
|
1
|
+
/**
|
2
|
+
* @class
|
3
|
+
* @extends { Array }
|
4
|
+
*/
|
5
|
+
class ConfigList extends Array {
|
6
|
+
static get [Symbol.species]() { return Array }
|
7
|
+
|
8
|
+
get(key) {
|
9
|
+
const index = this.getIndex(key, true)
|
10
|
+
return this[index].value
|
11
|
+
}
|
12
|
+
|
13
|
+
/**
|
14
|
+
* @deprecated after the 3.0.2 release and will be removed in the next major release
|
15
|
+
*/
|
16
|
+
set(key, value) {
|
17
|
+
/* eslint no-console: 0 */
|
18
|
+
console.warn('set is deprecated! Use append instead')
|
19
|
+
return this.append(key, value)
|
20
|
+
}
|
21
|
+
|
22
|
+
append(key, value) {
|
23
|
+
return this.add({ key, value })
|
24
|
+
}
|
25
|
+
|
26
|
+
prepend(key, value) {
|
27
|
+
return this.add({ key, value }, 'prepend')
|
28
|
+
}
|
29
|
+
|
30
|
+
insert(key, value, pos = {}) {
|
31
|
+
if (!(pos.before || pos.after)) return this.append(key, value)
|
32
|
+
|
33
|
+
const currentIndex = this.getIndex(key)
|
34
|
+
if (currentIndex >= 0) this.splice(currentIndex, 1)
|
35
|
+
|
36
|
+
let newIndex = this.getIndex(pos.before || pos.after)
|
37
|
+
if (pos.after) newIndex += 1
|
38
|
+
|
39
|
+
this.splice(newIndex, 0, { key, value })
|
40
|
+
return this
|
41
|
+
}
|
42
|
+
|
43
|
+
delete(key) {
|
44
|
+
const index = this.getIndex(key, true)
|
45
|
+
this.splice(index, 1)
|
46
|
+
return this
|
47
|
+
}
|
48
|
+
|
49
|
+
getIndex(key, shouldThrow = false) {
|
50
|
+
const index = this.findIndex(entry =>
|
51
|
+
(
|
52
|
+
entry === key ||
|
53
|
+
entry.key === key ||
|
54
|
+
(entry.constructor && entry.constructor.name === key)
|
55
|
+
))
|
56
|
+
|
57
|
+
if (shouldThrow && index < 0) throw new Error(`Item ${key} not found`)
|
58
|
+
return index
|
59
|
+
}
|
60
|
+
|
61
|
+
add({ key, value }, strategy = 'append') {
|
62
|
+
const index = this.getIndex(key)
|
63
|
+
if (index >= 0) this.delete(key)
|
64
|
+
|
65
|
+
switch (strategy) {
|
66
|
+
case 'prepend':
|
67
|
+
this.unshift({ key, value })
|
68
|
+
break
|
69
|
+
default:
|
70
|
+
this.push({ key, value })
|
71
|
+
}
|
72
|
+
|
73
|
+
return this
|
74
|
+
}
|
75
|
+
|
76
|
+
values() {
|
77
|
+
return this.map(item => item.value)
|
78
|
+
}
|
79
|
+
|
80
|
+
keys() {
|
81
|
+
return this.map(item => item.key)
|
82
|
+
}
|
83
|
+
}
|
84
|
+
|
85
|
+
module.exports = ConfigList
|
@@ -0,0 +1,55 @@
|
|
1
|
+
const objectify = require('../utils/objectify')
|
2
|
+
const deepAssign = require('../utils/deep_assign')
|
3
|
+
const deepMerge = require('../utils/deep_merge')
|
4
|
+
const { isStrPath, prettyPrint } = require('../utils/helpers')
|
5
|
+
|
6
|
+
/**
|
7
|
+
* @class
|
8
|
+
* @extends { Object }
|
9
|
+
*/
|
10
|
+
class ConfigObject extends Object {
|
11
|
+
constructor(props = {}) {
|
12
|
+
super()
|
13
|
+
this.merge(props)
|
14
|
+
}
|
15
|
+
|
16
|
+
get(key) {
|
17
|
+
return isStrPath(key) ? objectify(key, this) : this[key]
|
18
|
+
}
|
19
|
+
|
20
|
+
set(key, value) {
|
21
|
+
Object.assign(this, deepAssign(this, key, value))
|
22
|
+
return this
|
23
|
+
}
|
24
|
+
|
25
|
+
delete(key) {
|
26
|
+
let obj = this
|
27
|
+
let propKey = key
|
28
|
+
|
29
|
+
if (isStrPath(key)) {
|
30
|
+
const keys = key.split('.')
|
31
|
+
propKey = keys.pop()
|
32
|
+
const parentObjPath = keys.join('.')
|
33
|
+
obj = objectify(parentObjPath, this)
|
34
|
+
}
|
35
|
+
|
36
|
+
if (!obj) throw new Error(`Prop not found: ${key} in ${prettyPrint(obj)}`)
|
37
|
+
delete obj[propKey]
|
38
|
+
|
39
|
+
return this
|
40
|
+
}
|
41
|
+
|
42
|
+
toObject() {
|
43
|
+
const object = {}
|
44
|
+
/* eslint no-return-assign: 0 */
|
45
|
+
Object.keys(this).forEach(key => (object[key] = this[key]))
|
46
|
+
return object
|
47
|
+
}
|
48
|
+
|
49
|
+
merge(config) {
|
50
|
+
Object.assign(this, deepMerge(this, config))
|
51
|
+
return this
|
52
|
+
}
|
53
|
+
}
|
54
|
+
|
55
|
+
module.exports = ConfigObject
|
@@ -0,0 +1,116 @@
|
|
1
|
+
/* eslint global-require: 0 */
|
2
|
+
/* eslint import/no-dynamic-require: 0 */
|
3
|
+
|
4
|
+
const {
|
5
|
+
basename, dirname, join, relative, resolve
|
6
|
+
} = require('path')
|
7
|
+
const { sync } = require('glob')
|
8
|
+
const extname = require('path-complete-extname')
|
9
|
+
|
10
|
+
const webpack = require('webpack')
|
11
|
+
const ExtractTextPlugin = require('extract-text-webpack-plugin')
|
12
|
+
const ManifestPlugin = require('webpack-manifest-plugin')
|
13
|
+
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin')
|
14
|
+
|
15
|
+
const { ConfigList, ConfigObject } = require('./config_types')
|
16
|
+
const rules = require('./rules')
|
17
|
+
const config = require('./config')
|
18
|
+
|
19
|
+
const getLoaderList = () => {
|
20
|
+
const result = new ConfigList()
|
21
|
+
Object.keys(rules).forEach(key => result.append(key, rules[key]))
|
22
|
+
return result
|
23
|
+
}
|
24
|
+
|
25
|
+
const getPluginList = () => {
|
26
|
+
const result = new ConfigList()
|
27
|
+
result.append('Environment', new webpack.EnvironmentPlugin(JSON.parse(JSON.stringify(process.env))))
|
28
|
+
result.append('CaseSensitivePaths', new CaseSensitivePathsPlugin())
|
29
|
+
result.append('ExtractText', new ExtractTextPlugin('[name]-[contenthash].css'))
|
30
|
+
result.append('Manifest', new ManifestPlugin({ publicPath: config.publicPath, writeToFileEmit: true }))
|
31
|
+
return result
|
32
|
+
}
|
33
|
+
|
34
|
+
const getExtensionsGlob = () => {
|
35
|
+
const { extensions } = config
|
36
|
+
if (!extensions.length) {
|
37
|
+
throw new Error('You must configure at least one extension to compile in webpacker.yml')
|
38
|
+
}
|
39
|
+
return extensions.length === 1 ? `**/${extensions[0]}` : `**/*{${extensions.join(',')}}`
|
40
|
+
}
|
41
|
+
|
42
|
+
const getEntryObject = () => {
|
43
|
+
const result = new ConfigObject()
|
44
|
+
const glob = getExtensionsGlob()
|
45
|
+
const rootPath = join(config.source_path, config.source_entry_path)
|
46
|
+
const paths = sync(join(rootPath, glob))
|
47
|
+
paths.forEach((path) => {
|
48
|
+
const namespace = relative(join(rootPath), dirname(path))
|
49
|
+
const name = join(namespace, basename(path, extname(path)))
|
50
|
+
result.set(name, resolve(path))
|
51
|
+
})
|
52
|
+
return result
|
53
|
+
}
|
54
|
+
|
55
|
+
const getModulePaths = () => {
|
56
|
+
const result = new ConfigList()
|
57
|
+
result.append('source', resolve(config.source_path))
|
58
|
+
if (config.resolved_paths) {
|
59
|
+
config.resolved_paths.forEach(path => result.append(path, resolve(path)))
|
60
|
+
}
|
61
|
+
result.append('node_modules', 'node_modules')
|
62
|
+
return result
|
63
|
+
}
|
64
|
+
|
65
|
+
const getBaseConfig = () =>
|
66
|
+
new ConfigObject({
|
67
|
+
output: {
|
68
|
+
filename: '[name]-[chunkhash].js',
|
69
|
+
chunkFilename: '[name]-[chunkhash].chunk.js',
|
70
|
+
path: config.outputPath,
|
71
|
+
publicPath: config.publicPath
|
72
|
+
},
|
73
|
+
|
74
|
+
resolve: {
|
75
|
+
extensions: config.extensions
|
76
|
+
},
|
77
|
+
|
78
|
+
resolveLoader: {
|
79
|
+
modules: ['node_modules']
|
80
|
+
},
|
81
|
+
|
82
|
+
node: {
|
83
|
+
dgram: 'empty',
|
84
|
+
fs: 'empty',
|
85
|
+
net: 'empty',
|
86
|
+
tls: 'empty',
|
87
|
+
child_process: 'empty'
|
88
|
+
}
|
89
|
+
})
|
90
|
+
|
91
|
+
module.exports = class Environment {
|
92
|
+
constructor() {
|
93
|
+
this.loaders = getLoaderList()
|
94
|
+
this.plugins = getPluginList()
|
95
|
+
this.config = getBaseConfig()
|
96
|
+
this.entry = getEntryObject()
|
97
|
+
this.resolvedModules = getModulePaths()
|
98
|
+
}
|
99
|
+
|
100
|
+
toWebpackConfig() {
|
101
|
+
return this.config.merge({
|
102
|
+
entry: this.entry.toObject(),
|
103
|
+
|
104
|
+
module: {
|
105
|
+
strictExportPresence: true,
|
106
|
+
rules: this.loaders.values()
|
107
|
+
},
|
108
|
+
|
109
|
+
plugins: this.plugins.values(),
|
110
|
+
|
111
|
+
resolve: {
|
112
|
+
modules: this.resolvedModules.values()
|
113
|
+
}
|
114
|
+
})
|
115
|
+
}
|
116
|
+
}
|
@@ -0,0 +1,46 @@
|
|
1
|
+
const webpack = require('webpack')
|
2
|
+
const Environment = require('../environment')
|
3
|
+
const { dev_server: devServer, outputPath: contentBase, publicPath } = require('../config')
|
4
|
+
|
5
|
+
module.exports = class extends Environment {
|
6
|
+
constructor() {
|
7
|
+
super()
|
8
|
+
|
9
|
+
if (devServer.hmr) {
|
10
|
+
this.plugins.append('HotModuleReplacement', new webpack.HotModuleReplacementPlugin())
|
11
|
+
this.plugins.append('NamedModules', new webpack.NamedModulesPlugin())
|
12
|
+
this.config.output.filename = '[name]-[hash].js'
|
13
|
+
}
|
14
|
+
|
15
|
+
this.config.merge({
|
16
|
+
devtool: 'cheap-module-source-map',
|
17
|
+
output: {
|
18
|
+
pathinfo: true
|
19
|
+
},
|
20
|
+
devServer: {
|
21
|
+
clientLogLevel: 'none',
|
22
|
+
compress: devServer.compress,
|
23
|
+
quiet: devServer.quiet,
|
24
|
+
disableHostCheck: devServer.disable_host_check,
|
25
|
+
host: devServer.host,
|
26
|
+
port: devServer.port,
|
27
|
+
https: devServer.https,
|
28
|
+
hot: devServer.hmr,
|
29
|
+
contentBase,
|
30
|
+
inline: devServer.inline,
|
31
|
+
useLocalIp: devServer.use_local_ip,
|
32
|
+
public: devServer.public,
|
33
|
+
publicPath,
|
34
|
+
historyApiFallback: {
|
35
|
+
disableDotRule: true
|
36
|
+
},
|
37
|
+
headers: devServer.headers,
|
38
|
+
overlay: devServer.overlay,
|
39
|
+
stats: {
|
40
|
+
errorDetails: true
|
41
|
+
},
|
42
|
+
watchOptions: devServer.watch_options
|
43
|
+
}
|
44
|
+
})
|
45
|
+
}
|
46
|
+
}
|
@@ -0,0 +1,37 @@
|
|
1
|
+
const webpack = require('webpack')
|
2
|
+
const CompressionPlugin = require('compression-webpack-plugin')
|
3
|
+
const Environment = require('../environment')
|
4
|
+
|
5
|
+
module.exports = class extends Environment {
|
6
|
+
constructor() {
|
7
|
+
super()
|
8
|
+
|
9
|
+
this.plugins.append('ModuleConcatenation', new webpack.optimize.ModuleConcatenationPlugin())
|
10
|
+
|
11
|
+
this.plugins.append('UglifyJs', new webpack.optimize.UglifyJsPlugin({
|
12
|
+
sourceMap: true,
|
13
|
+
mangle: {
|
14
|
+
safari10: true
|
15
|
+
},
|
16
|
+
compress: {
|
17
|
+
warnings: false,
|
18
|
+
comparisons: false
|
19
|
+
},
|
20
|
+
output: {
|
21
|
+
comments: false,
|
22
|
+
ascii_only: true
|
23
|
+
}
|
24
|
+
}))
|
25
|
+
|
26
|
+
this.plugins.append('Compression', new CompressionPlugin({
|
27
|
+
asset: '[path].gz[query]',
|
28
|
+
algorithm: 'gzip',
|
29
|
+
test: /\.(js|css|html|json|ico|svg|eot|otf|ttf)$/
|
30
|
+
}))
|
31
|
+
|
32
|
+
this.config.merge({
|
33
|
+
devtool: 'nosources-source-map',
|
34
|
+
stats: 'normal'
|
35
|
+
})
|
36
|
+
}
|
37
|
+
}
|
data/package/index.js
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
/* eslint global-require: 0 */
|
2
|
+
/* eslint import/no-dynamic-require: 0 */
|
3
|
+
|
4
|
+
const { resolve } = require('path')
|
5
|
+
const { existsSync } = require('fs')
|
6
|
+
const Environment = require('./environment')
|
7
|
+
const config = require('./config')
|
8
|
+
const loaders = require('./rules')
|
9
|
+
|
10
|
+
const createEnvironment = () => {
|
11
|
+
const path = resolve(__dirname, 'environments', `${process.env.NODE_ENV}.js`)
|
12
|
+
const constructor = existsSync(path) ? require(path) : Environment
|
13
|
+
return new constructor()
|
14
|
+
}
|
15
|
+
|
16
|
+
const environment = createEnvironment()
|
17
|
+
|
18
|
+
module.exports = {
|
19
|
+
environment, config, loaders, Environment
|
20
|
+
}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
const { join } = require('path')
|
2
|
+
const { cache_path } = require('../config')
|
3
|
+
|
4
|
+
module.exports = {
|
5
|
+
test: /\.(js|jsx)?(\.erb)?$/,
|
6
|
+
exclude: /node_modules/,
|
7
|
+
use: [{
|
8
|
+
loader: 'babel-loader',
|
9
|
+
options: {
|
10
|
+
cacheDirectory: join(cache_path, 'babel-loader')
|
11
|
+
}
|
12
|
+
}]
|
13
|
+
}
|
@@ -0,0 +1,39 @@
|
|
1
|
+
const ExtractTextPlugin = require('extract-text-webpack-plugin')
|
2
|
+
const path = require('path')
|
3
|
+
const { dev_server: devServer } = require('../config')
|
4
|
+
|
5
|
+
const postcssConfigPath = path.resolve(process.cwd(), '.postcssrc.yml')
|
6
|
+
const isProduction = process.env.NODE_ENV === 'production'
|
7
|
+
const inDevServer = process.argv.find(v => v.includes('webpack-dev-server'))
|
8
|
+
const isHMR = inDevServer && (devServer && devServer.hmr)
|
9
|
+
const extractCSS = !(isHMR) || isProduction
|
10
|
+
|
11
|
+
const styleLoader = {
|
12
|
+
loader: 'style-loader',
|
13
|
+
options: {
|
14
|
+
hmr: isHMR,
|
15
|
+
sourceMap: true
|
16
|
+
}
|
17
|
+
}
|
18
|
+
|
19
|
+
const extractOptions = {
|
20
|
+
fallback: styleLoader,
|
21
|
+
use: [
|
22
|
+
{ loader: 'css-loader', options: { minimize: isProduction, sourceMap: true, importLoaders: 2 } },
|
23
|
+
{ loader: 'postcss-loader', options: { sourceMap: true, config: { path: postcssConfigPath } } }
|
24
|
+
]
|
25
|
+
}
|
26
|
+
|
27
|
+
// For production extract styles to a separate bundle
|
28
|
+
const extractCSSLoader = {
|
29
|
+
test: /\.(css)$/i,
|
30
|
+
use: ExtractTextPlugin.extract(extractOptions)
|
31
|
+
}
|
32
|
+
|
33
|
+
// For hot-reloading use regular loaders
|
34
|
+
const inlineCSSLoader = {
|
35
|
+
test: /\.(css)$/i,
|
36
|
+
use: [styleLoader].concat(extractOptions.use)
|
37
|
+
}
|
38
|
+
|
39
|
+
module.exports = extractCSS ? extractCSSLoader : inlineCSSLoader
|